vim-interaction.plugin.zsh 1.4 KB

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