Ad blocker interference detected!
Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers
Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.
created 2005 · complexity basic · author Matthias Ihrke · version 5.7
I often have a local working copy of a remote directory tree (e.g. a website) and sometimes I want to transfer some minor changes to a file very fast (e.g. when updating a webpage).
You can do this by simply typing
:Upload while editing a file using the following line in vimrc:
:command Upload :!upload.py %;
The file upload.py must be in your PATH:
#!/usr/bin/env python import os, sys # cmd parsing if len(sys.argv)>1 and os.path.isfile(sys.argv): file=sys.argv else: print "Usage: upload.py <file>"; sys.exit() # can be overridden by environment variables mode='scp' server='your_server.org' user='username_on_server' remote_root='/your/root/on/server' local_root='/your/local/root' # override defaults with environment variables if os.getenv('UPLOAD_MODE'): mode = os.getenv('UPLOAD_MODE') if os.getenv('UPLOAD_SERVER'): server = os.getenv('UPLOAD_SERVER') if os.getenv('UPLOAD_USER'): user = os.getenv('UPLOAD_USER') if os.getenv('UPLOAD_REMOTE_ROOT'): remote_root = os.getenv('UPLOAD_REMOTE_ROOT') if os.getenv('UPLOAD_LOCAL_ROOT'): local_root = os.getenv('UPLOAD_LOCAL_ROOT') # add other modes here if mode=='scp': if not os.getcwd().startswith(local_root): print 'file not in %s'%local_root; sys.exit() else: ext_path=os.path.join(os.getcwd().replace(local_root, remote_root), file) cmd = 'scp %s %s@%s:%s'%(file, user, server, ext_path) failure = os.system(cmd) if failure: print "Running %s failed..."%cmd
You will have to specify your server, your directory on the server, the user on the server and the local directory root which is corresponding to the remote directory.
You can specify the location either in the script, or as environment variables as
If the file you are editing is in the specified local directory or one of its subdirectories, the script will automatically upload it to the correct location.
Of course this is only of use if you have one major directory on one major server. If you have data on multiple servers, this script won't help, since you always have to specify the server and the corresponding directories.
Use netrw (distributed with Vim) for this type of operation. See :help netrw.
Using netrw, Vim keeps a local copy of the document in your temp folder.
You can use a procedure like the following to use short names to access hosts.
Add following lines to
Host short Hostname very.long.hostname User username Port 12345 # if you really need it Host another Hostname another.very.long.hostname User different_username
Now try this:
~ is your home folder (usually you keep files here).