Skip to content

Instantly share code, notes, and snippets.

@motyar
Last active August 29, 2015 13:57
Show Gist options
  • Save motyar/9885182 to your computer and use it in GitHub Desktop.
Save motyar/9885182 to your computer and use it in GitHub Desktop.
Auto start and stop ssh tunnel, for super fast remote editing with Vim
"{{{ Start and stop ssh tunnel, Fast remote editing idea via http://www.erikzaadi.com/2013/03/07/fast-remote-editing-with-vim/
function! StartSshTunnel(machine)
let shellcmd = "ssh ".a:machine." -f -N -o ControlMaster=auto -o ControlPath=/tmp/%r@%h:%p"
let tunnel=system(shellcmd)
endfunction
function! StopSshTunnel()
let kill = system("lsof -i -n | grep ssh | awk '{print $2}' | xargs kill -9")
endfunction
au FileType netrw au VimEnter * call StartSshTunnel(g:netrw_machine)
au FileType netrw au VimLeave * call StopSshTunnel()
"}}}
" More vim Hacks in my .vimrc https://github.com/motyar/dotfiles/blob/master/.vimrc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment