14.06.2014 Views

vim 101 hacks

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Buyer: xiujuan lu (luxiujuan@gmail.com)<br />

Transaction ID: 85W16630AD8515549<br />

Vim <strong>101</strong> Hacks<br />

www.thegeekstuff.com<br />

Hack 42. Add Automatic Headers to Files Using<br />

Let us review how to use the powerful autocmd feature of Vim to create<br />

a header section inside a file (for example, header in a C programming code)<br />

with file name, creation date, last modified date/time automatically<br />

populated when you open a file in vi.<br />

Vim autocmd syntax:<br />

autocmd {event} {pattern} {cmd}<br />

Events: There are more than 40 autocmd events. The following are few<br />

sample autocmd events.<br />

Event<br />

BufNewFile<br />

FileReadPre<br />

Description<br />

Starting to edit a file that doesn't exist<br />

Before reading a file with a ":read" command<br />

BufWritePre<br />

Starting to write the whole buffer to a file<br />

FileWritePre<br />

Starting to write part of a buffer to a file<br />

BufDelete<br />

Before deleting a buffer from the buffer list<br />

BufWipeout<br />

Before completely deleting a buffer<br />

BufNew<br />

Just after creating a new buffer<br />

BufEnter<br />

After entering a buffer<br />

BufLeave<br />

Before leaving to another buffer<br />

76

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!