Skip to content

Instantly share code, notes, and snippets.

@lepht
Last active December 27, 2015 19:29
Show Gist options
  • Save lepht/7377120 to your computer and use it in GitHub Desktop.
Save lepht/7377120 to your computer and use it in GitHub Desktop.
vim-scp Uses scp to copy a local version of the remote file over scp, edit it with vim, and with each save connect via scp and save it to the remote location. Original source: [Fast remote editing with Vim - Erik Zaadi](http://www.erikzaadi.com/2013/03/07/fast-remote-editing-with-vim/)
#!/bin/sh
# The vim binary you would like to use
# eg `mvim -f` will run macvim
VIM_BIN="mvim -f"
echo "vim-scp FTW"
if [ $# -ne 2 ]; then
echo "usage : `basename $0` user@host /path"
exit 1
fi
COMMAND="ssh $1 -f -N -o ControlMaster=auto -o ControlPath=/tmp/%r@%h:%p"
echo "opening ssh tunnel.."
$COMMAND || exit $?
echo "ssh tunnel active, opening vim.."
$VIM_BIN scp://$1/$2
echo "closing ssh tunnel.."
ps -ef | grep "$COMMAND" | grep -v grep | awk '{print $2}' | xargs kill -9
echo "Great Success!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment