1
0
Fork 0
mirror of https://github.com/ohmyzsh/ohmyzsh.git synced 2024-12-19 10:51:57 +00:00
ohmyzsh/plugins/vim-interaction/vim-interaction.plugin.zsh
Jóhann Friðriksson aa6e932b06
fix(vim-interaction): look up the newest GVim instance (#9095)
Instead of relying on a hardcoded instance-name existing for the default-value, let's
look up the latest instance. This also resolves my problem where MacVim
had a servername of "VIM" instead of "GVIM".

Co-authored-by: Johann Fridriksson <jofridri@silabs.com>
2021-09-09 19:31:01 +02:00

63 lines
1.5 KiB
Bash

#
# See README.md
#
# Derek Wyatt (derek@{myfirstnamemylastname}.org
#
function callvim
{
if [[ $# == 0 ]]; then
cat <<EOH
usage: callvim [-b cmd] [-a cmd] [-n name] [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
-n name Name of the GVIM server to connect to
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=""
# Look up the newest instance
local name="$(gvim --serverlist | tail -n 1)"
while getopts ":b:a:n:" option
do
case $option in
a) after="$OPTARG"
;;
b) before="$OPTARG"
;;
n) name="$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
if [[ $# -gt 0 ]]; then
# absolute path of files resolving symlinks (:A) and quoting special chars (:q)
files=':args! '"${@:A:q}<cr>"
fi
cmd="$before$files$after"
gvim --servername "$name" --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'"