vim-interaction.plugin.zsh 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. # Look up the newest instance
  23. local name="$(gvim --serverlist | tail -n 1)"
  24. while getopts ":b:a:n:" option
  25. do
  26. case $option in
  27. a) after="$OPTARG"
  28. ;;
  29. b) before="$OPTARG"
  30. ;;
  31. n) name="$OPTARG"
  32. ;;
  33. esac
  34. done
  35. shift $((OPTIND-1))
  36. if [[ ${after#:} != $after && ${after%<cr>} == $after ]]; then
  37. after="$after<cr>"
  38. fi
  39. if [[ ${before#:} != $before && ${before%<cr>} == $before ]]; then
  40. before="$before<cr>"
  41. fi
  42. local files
  43. if [[ $# -gt 0 ]]; then
  44. # absolute path of files resolving symlinks (:A) and quoting special chars (:q)
  45. files=':args! '"${@:A:q}<cr>"
  46. fi
  47. cmd="$before$files$after"
  48. gvim --servername "$name" --remote-send "$cmd"
  49. if typeset -f postCallVim > /dev/null; then
  50. postCallVim
  51. fi
  52. }
  53. alias v=callvim
  54. alias vvsp="callvim -b':vsp'"
  55. alias vhsp="callvim -b':sp'"
  56. alias vk="callvim -b':wincmd k'"
  57. alias vj="callvim -b':wincmd j'"
  58. alias vl="callvim -b':wincmd l'"
  59. alias vh="callvim -b':wincmd h'"