There’s probably a better way to do this, but this is what I’m trying to do. I have several html files for which I need to update meta tags prior to updating the content. I’m trying to automate this by using a keyboard mapping similar to what follows:
nnoremap <leader>mt /<meta name="developer"<cr>f";;lct"$username
This seems to work with the exception of the $username portion. How can I make the mapping evaluate the variable?
I do have a few tags to update per page, but don’t know how else to do this. If someone has a better method, I’d be more than happy to hear it. The content that I’m searching through is similar to the following:
<meta name="owner" content="someowner">
<meta name="developer" content="somedev">
<meta name="date" content="2012-07-26">
<meta name="expires" content="2013-07-26">
The date would be the date that I opened the file to edit, while the expires would be one year from the date
NOTE: This is gvim on Windows if that changes things.
$usernamedoes refer to the environment variableusername, but to use this in a mapping, you have to stick to the (somewhat unintuitive, but perfectly consistent) interpretation rules of Vim.The
ct"mean change until double-quote, so what follows is in insert mode. To insert an environment variable (or any other Vim expression), use<C-R>=:This will evaluate the environment variable on each mapping invocation. (And stay in insert mode; append
<Esc>to go back to normal mode!) Alternatively, you could also bake the value into the mapping itself: