Blame view

plugins/vim-interaction/vim-interaction.plugin.zsh 1.44 KB
093a6c34b   mj   Squashed 'repos/r...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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'"