Last active
October 24, 2016 01:30
-
-
Save eri451/177d7ea182900fc30e49f30e06717e7f to your computer and use it in GitHub Desktop.
Vimlink - using the clientserver feature
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
#compdef vimlink | |
_vimlink() { | |
local -a vimse | |
vimse=($(/usr/bin/vim --serverlist)) | |
if (( CURRENT == 2 )); then | |
_arguments '*:vimserver:($vimse)' | |
fi | |
return 0 | |
} | |
_vimlink |
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
function vimlinked() | |
{ | |
if [[ -z ${VIMLINKED} ]] | |
then | |
echo "" | |
else | |
echo "${PR_MAGENTA} ⚓ ${VIMLINKED}" | |
fi | |
} | |
local vilnk='$(vimlinked)' | |
local inner="${vilnk} ${cwd}${colon}${user_host}" | |
RPROMPT="${PR_RESET}${bracket_open}${inner}${bracket_close}${PR_RESET}" |
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
if [[ $# -ge 1 ]] | |
then | |
if [[ $# -gt 1 ]] | |
then | |
print "only one argument allowed" > /dev/fd/2 | |
return 23 | |
else | |
servername=$(echo ${1} | tr "[:lower:]" "[:upper:]") | |
fi | |
else | |
print "please specify a servername" > /dev/fd/2 | |
return 13 | |
fi | |
_redefines() | |
{ | |
# force vim to cd with you | |
cd() | |
{ | |
builtin cd $* | |
/usr/bin/vim --servername ${VIMLINKED} --remote-send ":cd ${PWD}<CR>" | |
} | |
# open files in linked vim | |
vim() | |
{ | |
if [[ ${1} =~ "^-.*" ]] | |
then | |
/usr/bin/vim $* | |
else | |
/usr/bin/vim --servername ${VIMLINKED} --remote $* | |
fi | |
} | |
} | |
print "trying to link to ${servername}" | |
vim --serverlist | grep ${servername} > /dev/null | |
if [[ $? -eq 0 ]] | |
then | |
if [[ $VIMLINKED != ${servername} ]] | |
then | |
print "now linked to ${servername}" | |
export VIMLINKED=${servername} | |
_redefines | |
cd . | |
else | |
print "this shell is already linked to ${VIMLINKED}" | |
fi | |
else | |
print "there is no server ${servername}" | |
fi | |
return 0 | |
# vim: ft=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
cd() { builtin cd $*} | |
vim() { /usr/bin/vim $* } | |
unset VIMLINKED | |
# vim: ft=zsh |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment