4 # Derek Wyatt (derek@{myfirstnamemylastname}.org
10 usage: callvim [-b cmd] [-a cmd] [-n name] [file ... fileN]
12 -b cmd Run this command in GVIM before editing the first file
13 -a cmd Run this command in GVIM after editing the first file
14 -n name Name of the GVIM server to connect to
16 ... fileN The other files to add to the argslist
21 # Look up the newest instance or start one
22 local name="$(gvim --serverlist | tail -n 1)"
24 # run gvim or exit if it fails
27 # wait for gvim instance to fully load
28 while name=$(gvim --serverlist) && [[ -z "$name" ]]; do
33 local before="<esc>" files after cmd
35 while getopts ":b:a:n:" option
48 # If before or after commands begin with : and don't end with <cr>, append it
49 [[ ${after} = :* && ${after} != *\<cr\> ]] && after+="<cr>"
50 [[ ${before} = :* && ${before} != *\<cr\> ]] && before+="<cr>"
51 # Open files passed (:A means abs path resolving symlinks, :q means quoting special chars)
52 [[ $# -gt 0 ]] && files=':args! '"${@:A:q}<cr>"
53 # Pass the built vim command to gvim
54 cmd="$before$files$after"
56 # Run the gvim command
57 gvim --servername "$name" --remote-send "$cmd" || return $?
59 # Run postCallVim if defined (maybe to bring focus to gvim, see README)
60 (( ! $+functions[postCallVim] )) || postCallVim
64 alias vvsp="callvim -b':vsp'"
65 alias vhsp="callvim -b':sp'"
66 alias vk="callvim -b':wincmd k'"
67 alias vj="callvim -b':wincmd j'"
68 alias vl="callvim -b':wincmd l'"
69 alias vh="callvim -b':wincmd h'"