Vim Tips Wiki
Advertisement

Proposed tip Please edit this page to improve it, or add your comments below (do not use the discussion page).

Please use new tips to discuss whether this page should be a permanent tip, or whether it should be merged to an existing tip.
created January 5, 2010 · complexity basic · author Chris Bedford · version 7.0

This tip shows a simple mapping to construct an HTML link.

Suppose you have some lines like this:

This identifies a website:
http://www.example.com
The Example Site

With the mapping below, you can move the cursor to anywhere in the second line (the target URL), then press F7 to convert the text to:

This identifies a website:
<a href="http://www.example.com">The Example Site</a>

The key mapping for your vimrc is:

" Convert two lines (URL then TITLE) to one line: <a href=URL>TITLE</a>
map <F7> <Esc>I<a href="<Esc>A"><Esc>gJA</a><Esc>

See also

Comments

Advertisement