Skip to content

Instantly share code, notes, and snippets.

@doloopwhile
Created September 4, 2014 02:51
Show Gist options
  • Save doloopwhile/b74600367198c765bc37 to your computer and use it in GitHub Desktop.
Save doloopwhile/b74600367198c765bc37 to your computer and use it in GitHub Desktop.
A script to open file in gvim (suport "/path/to/file:42" format)
#!/bin/bash
#
# open-gvim.sh
#
# - Open a file with gvim
# - If there is running gvim open file in there.
# - Open "path with line number" (like "/path/to/file:42" printed in grep and etc.)
if [ "$#" -eq 0 ]; then
if vim --serverlist | grep -q GVIM; then
vim -g --servername GVIM --remote-expr 'foreground()' 2>/dev/null
else
vim -g --servername GVIM 2>/dev/null &!
fi
else
for f in "$@"; do
vim -g --servername GVIM --remote-tab-silent \
$(echo "$f" | sed -e "s|\(.*\):\([[:digit:]]\+\)|+\2 \1|") \
2>/dev/null &!
done
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment