Christopher Bull bio photo

Christopher Bull

Aspiring Oceanographer at Northumbria University. Big data python enthusiast. Outdoor adventurer.

Email Twitter Github

I often find myself wanting to edit a file on a remote machine but ssh is too slow to be running a text editor on the remote machine.. Solution? Vim can use rsync to download a copy of the file and then when you save it, it saves it back to the remote location!

Here’s a bash function I wrote to make it all easy….

function vim_servername() 
    if [[ ( $# -eq 0 ) || ( $1 == "--help" ) || ( $1 == "-h" ) ]] ; then
        echo "Usage:   vim_servername [path_to]." 
        echo "Purpose: Allows remote editing of files on servers..." 
        echo "       " 
        echo "Mandatory arguments: " 
        echo "path or file: vim will either edit or open path passed" 
        echo "       " 
        echo "Example." 
        echo "This:" 
        echo "vim_servername /server/path/or/file/"
        echo "       " 
        echo "Becomes:" 
        echo "vim scp://"

        return 1

    vim scp://${1} 


So, just put these in your .bashrc with your relevant server details and you should be good to go! Best to be using ssh keys, that way you’re not typing in your password everytime you save..

In category: hpc