summaryrefslogtreecommitdiff
path: root/plugins/vim-interaction/vim-interaction.plugin.zsh
diff options
context:
space:
mode:
authorBob Williams <bobwilliams.ii@gmail.com>2014-03-22 21:24:52 -0400
committerBob Williams <bobwilliams.ii@gmail.com>2014-03-22 21:24:52 -0400
commitd70e73294494e68c94879c7bf22f708a3049a9d4 (patch)
tree696f9a6cb49cab00924942eb5147b99b5fb1798d /plugins/vim-interaction/vim-interaction.plugin.zsh
parent5a586670d73dbbda97d124e33398aabf21597659 (diff)
parent178b5224e830845e45070ef803fcdb5a3f468dca (diff)
downloadzsh-d70e73294494e68c94879c7bf22f708a3049a9d4.tar.gz
zsh-d70e73294494e68c94879c7bf22f708a3049a9d4.tar.bz2
zsh-d70e73294494e68c94879c7bf22f708a3049a9d4.zip
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'plugins/vim-interaction/vim-interaction.plugin.zsh')
-rw-r--r--plugins/vim-interaction/vim-interaction.plugin.zsh72
1 files changed, 72 insertions, 0 deletions
diff --git a/plugins/vim-interaction/vim-interaction.plugin.zsh b/plugins/vim-interaction/vim-interaction.plugin.zsh
new file mode 100644
index 000000000..5142f1f9b
--- /dev/null
+++ b/plugins/vim-interaction/vim-interaction.plugin.zsh
@@ -0,0 +1,72 @@
+#
+# See README.md
+#
+# Derek Wyatt (derek@{myfirstnamemylastname}.org
+#
+
+function resolveFile
+{
+ if [ -f "$1" ]; then
+ echo $(readlink -f "$1")
+ elif [[ "${1#/}" == "$1" ]]; then
+ echo "$(pwd)/$1"
+ else
+ echo $1
+ fi
+}
+
+function callvim
+{
+ if [[ $# == 0 ]]; then
+ cat <<EOH
+usage: callvim [-b cmd] [-a cmd] [file ... fileN]
+
+ -b cmd Run this command in GVIM before editing the first file
+ -a cmd Run this command in GVIM after editing the first file
+ file The file to edit
+ ... fileN The other files to add to the argslist
+EOH
+ return 0
+ fi
+
+ local cmd=""
+ local before="<esc>"
+ local after=""
+ while getopts ":b:a:" option
+ do
+ case $option in
+ a) after="$OPTARG"
+ ;;
+ b) before="$OPTARG"
+ ;;
+ esac
+ done
+ shift $((OPTIND-1))
+ if [[ ${after#:} != $after && ${after%<cr>} == $after ]]; then
+ after="$after<cr>"
+ fi
+ if [[ ${before#:} != $before && ${before%<cr>} == $before ]]; then
+ before="$before<cr>"
+ fi
+ local files=""
+ for f in $@
+ do
+ files="$files $(resolveFile $f)"
+ done
+ if [[ -n $files ]]; then
+ files=':args! '"$files<cr>"
+ fi
+ cmd="$before$files$after"
+ gvim --remote-send "$cmd"
+ if typeset -f postCallVim > /dev/null; then
+ postCallVim
+ fi
+}
+
+alias v=callvim
+alias vvsp="callvim -b':vsp'"
+alias vhsp="callvim -b':sp'"
+alias vk="callvim -b':wincmd k'"
+alias vj="callvim -b':wincmd j'"
+alias vl="callvim -b':wincmd l'"
+alias vh="callvim -b':wincmd h'"