vim-interaction.plugin.zsh 1.44 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
#
# See README.md
#
# Derek Wyatt (derek@{myfirstnamemylastname}.org
# 

function callvim
{
  if [[ $# == 0 ]]; then
    cat <<EOH
11
usage: callvim [-b cmd] [-a cmd] [-n name] [file ... fileN]
12
13
14

  -b cmd     Run this command in GVIM before editing the first file
  -a cmd     Run this command in GVIM after editing the first file
15
  -n name    Name of the GVIM server to connect to
16
17
18
19
20
21
22
  file       The file to edit
  ... fileN  The other files to add to the argslist
EOH
    return 0
  fi

  local cmd=""
23
  local before="<esc>"
24
  local after=""
25
26
  local name="GVIM"
  while getopts ":b:a:n:" option
27
28
29
30
31
32
  do
    case $option in
      a) after="$OPTARG"
         ;;
      b) before="$OPTARG"
         ;;
33
34
      n) name="$OPTARG"
         ;;
35
36
37
38
39
40
41
42
43
    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
44
45
46
47
  local files
  if [[ $# -gt 0 ]]; then
    # absolute path of files resolving symlinks (:A) and quoting special chars (:q)
    files=':args! '"${@:A:q}<cr>"
48
49
  fi
  cmd="$before$files$after"
50
  gvim --servername "$name" --remote-send "$cmd"
51
52
53
  if typeset -f postCallVim > /dev/null; then
    postCallVim
  fi
54
55
56
57
58
59
60
61
62
}

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'"