vim-interaction.plugin.zsh 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #
  2. # See README.md
  3. #
  4. # Derek Wyatt (derek@{myfirstnamemylastname}.org
  5. #
  6. function resolveFile
  7. {
  8. if [ -f "$1" ]; then
  9. echo $(readlink -f "$1")
  10. elif [[ "${1#/}" == "$1" ]]; then
  11. echo "$PWD/$1"
  12. else
  13. echo $1
  14. fi
  15. }
  16. function callvim
  17. {
  18. if [[ $# == 0 ]]; then
  19. cat <<EOH
  20. usage: callvim [-b cmd] [-a cmd] [file ... fileN]
  21. -b cmd Run this command in GVIM before editing the first file
  22. -a cmd Run this command in GVIM after editing the first file
  23. file The file to edit
  24. ... fileN The other files to add to the argslist
  25. EOH
  26. return 0
  27. fi
  28. local cmd=""
  29. local before="<esc>"
  30. local after=""
  31. while getopts ":b:a:" option
  32. do
  33. case $option in
  34. a) after="$OPTARG"
  35. ;;
  36. b) before="$OPTARG"
  37. ;;
  38. esac
  39. done
  40. shift $((OPTIND-1))
  41. if [[ ${after#:} != $after && ${after%<cr>} == $after ]]; then
  42. after="$after<cr>"
  43. fi
  44. if [[ ${before#:} != $before && ${before%<cr>} == $before ]]; then
  45. before="$before<cr>"
  46. fi
  47. local files=""
  48. for f in $@
  49. do
  50. files="$files $(resolveFile $f)"
  51. done
  52. if [[ -n $files ]]; then
  53. files=':args! '"$files<cr>"
  54. fi
  55. cmd="$before$files$after"
  56. gvim --remote-send "$cmd"
  57. if typeset -f postCallVim > /dev/null; then
  58. postCallVim
  59. fi
  60. }
  61. alias v=callvim
  62. alias vvsp="callvim -b':vsp'"
  63. alias vhsp="callvim -b':sp'"
  64. alias vk="callvim -b':wincmd k'"
  65. alias vj="callvim -b':wincmd j'"
  66. alias vl="callvim -b':wincmd l'"
  67. alias vh="callvim -b':wincmd h'"