Web Authoring with Vim

June 18th, 2007 toydi Posted in Network, Text Manipulation, vim | Hits: 40649 | 3 Comments »

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 .

[中文翻译]

3 Responses to “Web Authoring with Vim”

  1. I actually wanted to post a brief message in order to appreciate you for all the remarkable ideas you are showing on this site. My extended internet lookup has at the end of the day been recognized with sensible knowledge to write about with my friends and classmates. I would assert that most of us visitors actually are unquestionably endowed to be in a magnificent network with very many brilliant individuals with great basics. I feel pretty fortunate to have come across the webpage and look forward to really more fun minutes reading here. Thank you once more for all the details.

  2. I think this is among the most significant information for me. And i am glad I am reading your article. But should remark on some general things, The website style is great, the articles is really nice. Good job, cheers.

  3. I found the same file but not including the trojan at keygenpen.

Leave a Reply