summaryrefslogtreecommitdiff
path: root/plugins/vim-interaction
diff options
context:
space:
mode:
authorRobby Russell <robby@planetargon.com>2014-03-22 15:44:11 -0700
committerRobby Russell <robby@planetargon.com>2014-03-22 15:44:11 -0700
commit75504364edce000c054495f1b394bea8ed51ea45 (patch)
tree27f63d41b1e9665741b4393bbc8cc7d23c0a0608 /plugins/vim-interaction
parentae1f33178285beb1560f4e6838a23335cfce29ef (diff)
parent94dd6515365e0d2655485c5afc27e75a921fa6ec (diff)
downloadzsh-75504364edce000c054495f1b394bea8ed51ea45.tar.gz
zsh-75504364edce000c054495f1b394bea8ed51ea45.tar.bz2
zsh-75504364edce000c054495f1b394bea8ed51ea45.zip
Merge pull request #1022 from derekwyatt/master
A plugin that makes it easier to interact with the (single) running instance of gvim
Diffstat (limited to 'plugins/vim-interaction')
-rw-r--r--plugins/vim-interaction/README.md82
-rw-r--r--plugins/vim-interaction/vim-interaction.plugin.zsh72
2 files changed, 154 insertions, 0 deletions
diff --git a/plugins/vim-interaction/README.md b/plugins/vim-interaction/README.md
new file mode 100644
index 000000000..681648018
--- /dev/null
+++ b/plugins/vim-interaction/README.md
@@ -0,0 +1,82 @@
+# Vim Interaction #
+
+The plugin presents a function called `callvim` whose usage is:
+
+ 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
+
+## Rationale ##
+
+The idea for this script is to give you some decent interaction with a running
+GVim session. Normally you'll be running around your filesystem doing any
+number of amazing things and you'll need to load some files into GVim for
+editing, inspecting, destruction, or other bits of mayhem. This script lets you
+do that.
+
+## Aliases ##
+
+There are a few aliases presented as well:
+
+* `v` A shorthand for `callvim`
+* `vvsp` Edits the passed in file but first makes a vertical split
+* `vhsp` Edits the passed in file but first makes a horizontal split
+
+## Post Callout ##
+
+At the end of the `callvim` function we invoke the `postCallVim` function if it
+exists. If you're using MacVim, for example, you could define a function that
+brings window focus to it after the file is loaded:
+
+ function postCallVim
+ {
+ osascript -e 'tell application "MacVim" to activate'
+ }
+
+This'll be different depending on your OS / Window Manager.
+
+## Examples ##
+
+This will load `/tmp/myfile.scala` into the running GVim session:
+
+ > v /tmp/myfile.scala
+
+This will load it after first doing a vertical split:
+
+ > vvsp /tmp/myfile.scala
+ or
+ > v -b':vsp' /tmp/myfile.scala
+
+This will load it after doing a horizontal split, then moving to the bottom of
+the file:
+
+ > vhsp -aG /tmp/myfile.scala
+ or
+ > v -b':sp' -aG /tmp/myfile.scala
+
+This will load the file and then copy the first line to the end (Why you would
+ever want to do this... I dunno):
+
+ > v -a':1t$' /tmp/myfile.scala
+
+And this will load all of the `*.txt` files into the args list:
+
+ > v *.txt
+
+If you want to load files into areas that are already split, use one of the
+aliases for that:
+
+ # Do a ':wincmd h' first
+ > vh /tmp/myfile.scala
+
+ # Do a ':wincmd j' first
+ > vj /tmp/myfile.scala
+
+ # Do a ':wincmd k' first
+ > vk /tmp/myfile.scala
+
+ # Do a ':wincmd l' first
+ > vl /tmp/myfile.scala
diff --git a/plugins/vim-interaction/vim-interaction.plugin.zsh b/plugins/vim-interaction/vim-interaction.plugin.zsh
new file mode 100644
index 000000000..5142f1f9b
--- /dev/null
+++ b/plugins/vim-interaction/vim-interaction.plugin.zsh
@@ -0,0 +1,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'"