diff options
author | Derek Wyatt <dwyatt@rim.com> | 2012-03-20 08:16:44 -0400 |
---|---|---|
committer | Derek Wyatt <dwyatt@rim.com> | 2012-03-20 08:16:44 -0400 |
commit | e652756fdb0495e58f3f4f3be3a82aa9f166731d (patch) | |
tree | 01f19f65ae1af6634d881fde84a7c4eeaba76a02 /plugins/vim-interaction/vim-interaction.plugin.zsh | |
parent | 1120f973054836eeb53750f57d69fbec41a340dc (diff) | |
download | zsh-e652756fdb0495e58f3f4f3be3a82aa9f166731d.tar.gz zsh-e652756fdb0495e58f3f4f3be3a82aa9f166731d.tar.bz2 zsh-e652756fdb0495e58f3f4f3be3a82aa9f166731d.zip |
A plugin that makes it easier to interact with the (single) running instance of gvim
Diffstat (limited to 'plugins/vim-interaction/vim-interaction.plugin.zsh')
-rw-r--r-- | plugins/vim-interaction/vim-interaction.plugin.zsh | 67 |
1 files changed, 67 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..3f346dfc3 --- /dev/null +++ b/plugins/vim-interaction/vim-interaction.plugin.zsh @@ -0,0 +1,67 @@ +# +# See README.md +# +# Derek Wyatt (derek@{myfirstnamemylastname}.org +# + +function resolveFile +{ + if [ -f "$1" ]; then + echo $(readlink -f "$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="" + 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" +} + +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'" |