Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Derek Wyatt
committed
Mar 19, 2012
1 parent
a8b8d93
commit e3bf1e7
Showing
2 changed files
with
117 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# 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 | ||
|
||
## 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 would you | ||
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 |
63 changes: 63 additions & 0 deletions
63
zsh_custom/plugins/vim-interaction/vim-interaction.plugin.zsh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# | ||
# See README.md | ||
# | ||
# Derek Wyatt (derek@{myfirstnamemylastname}.org | ||
# | ||
|
||
function resolveFile | ||
{ | ||
if [ -f "$1" ]; then | ||
echo $(readlink -f "$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 | ||
fi | ||
|
||
local cmd="" | ||
local before="" | ||
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$cmd$after$files" | ||
echo gvim --remote-send "$cmd" | ||
gvim --remote-send "$cmd" | ||
} | ||
|
||
alias v=callvim | ||
alias vvsp="callvim -b':vsp'" | ||
alias vhsp="callvim -b':sp'" |