Creation of new page metadata in Vim
If I’m going to be creating tons of new entries with my standard title/created/updated metadata, I need to speed up their creation. Actually, this has been on my wishlist for a long time.
I can instantly create new pages in the wiki by hitting the Enter key (VViki provides this). But to create the metadata (only needed on portions of the wiki intended for Web publishing), I’ve been using an external script. This is fine for creating the occasional new web page on my site, but not going to cut it for quick card entries!
The solution: a Vim shortcut mapping. If there are any children in the room, you might want to cover their eyes.
nnoremap <leader>wn gg0i:title: <esc>:put=strftime('%Y-%m-%d')<cr> \ I:created: <esc>A<cr>:updated:<cr><cr><esc>ggA
The key to understanding this nonsense is…well, the whole thing is crazy because Vimscript is crazy.
But the key part is
:put=strftime() where I’m using the put command (normally
used to paste buffers) to insert the date. Put in this form always operates on
whole lines, so I don’t need to insert a
<cr> after the
Also, after inserting the data, I use
I to go back and insert the
This metadata, by the way, is understood by my script which uses Ruby ERB templates and the AsciiDoctor library to export the page as HTML.