Web Authoring with Vim
June 18th, 2007 toydi Posted in Network, Text Manipulation, vim | Hits: 21264 |
In usual editing, to open a file with vim, we run the command:
vim /path/to/file
It is also possible to browse a directory using vim:
vim /path/to/directory/
When we are inside vim, to save a file, we use the :write command, :read to read an existing file into current buffer; or using :tabnew /path/to/file to open a file in a new tabbed window.
Remote editing
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:
vim ftp://ftp.teohuiming.name/public_html/blog/index.html
To browse my web directory in the server (the trailing slash in the URL is essential to indicate it is a directory):
vim ftp://ftp.teohuiming.name/public_html/
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 ~/.vimrc:
let g:netrw_ftp_cmd = 'pftp'
Extra tips
Use :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 .
Live Chat!







Leave a Reply