In usual editing, to open a file with vim, we run the command:
It is also possible to browse a directory using vim:
When we are inside vim, to save a file, we use the
:read to read an existing file into current buffer; or using
:tabnew /path/to/file to open a file in a new tabbed window.
When it comes to remote editing, (quite surprising me) vim simply reuses the same command set to access files or directories from a remote machine.
For example, to open a file in my web hosting server:
To browse my web directory in the server (the trailing slash in the URL is essential to indicate it is a directory):
Let say, I have opened the file
index.html and made some changes. When I run the
:write command, vim immediately sends an FTP request to my server to update the file.
FTP is not the only allowed protocol, vim is also capable to access remote machines through HTTP, WebDAV, SSH (scp, sftp) etc. For more details, run help command
:help netrw in vim.
Config vim to use Passive FTP
If you have connected successfully to your FTP server, able to send FTP requests, but always fail on receiving data from the server, you may need to turn on the passive mode in FTP to fix the problem.
To configure vim to use passive FTP, we need to force vim to use
pftp by appending the line below in vim config file
let g:netrw_ftp_cmd = 'pftp'
:0r to load template. I keep a few HTML document templates, and used do this whenever I want to create a new document:
cp html401.tpl tutorial2.html vim tutorial2.html
But if you are already inside vim, it’s easier to open a blank page with
:tabnew, and load the template directly using
:0r html401.tpl .
Insert ISO6801 date format. In the Web world, we often need to insert ISO6801 formatted timestamp when writing standard documents such as Atom. To insert a timestamp like
2007-06-18T23:14:02+0800 in vim, try
:r !date -Iseconds .