vim-interaction.plugin.zsh 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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] [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. file The file to edit
  14. ... fileN The other files to add to the argslist
  15. EOH
  16. return 0
  17. fi
  18. local cmd=""
  19. local before="<esc>"
  20. local after=""
  21. while getopts ":b:a:" option
  22. do
  23. case $option in
  24. a) after="$OPTARG"
  25. ;;
  26. b) before="$OPTARG"
  27. ;;
  28. esac
  29. done
  30. shift $((OPTIND-1))
  31. if [[ ${after#:} != $after && ${after%<cr>} == $after ]]; then
  32. after="$after<cr>"
  33. fi
  34. if [[ ${before#:} != $before && ${before%<cr>} == $before ]]; then
  35. before="$before<cr>"
  36. fi
  37. local files
  38. if [[ $# -gt 0 ]]; then
  39. # absolute path of files resolving symlinks (:A) and quoting special chars (:q)
  40. files=':args! '"${@:A:q}<cr>"
  41. fi
  42. cmd="$before$files$after"
  43. gvim --remote-send "$cmd"
  44. if typeset -f postCallVim > /dev/null; then
  45. postCallVim
  46. fi
  47. }
  48. alias v=callvim
  49. alias vvsp="callvim -b':vsp'"
  50. alias vhsp="callvim -b':sp'"
  51. alias vk="callvim -b':wincmd k'"
  52. alias vj="callvim -b':wincmd j'"
  53. alias vl="callvim -b':wincmd l'"
  54. alias vh="callvim -b':wincmd h'"