What's the quickest way to enclose the current line the cursor is on
in, say, <li></li> tags?


Depends on what you mean by "quickest"...are you looking for a one-shot, or are you looking for something you can map, or are you looking to perform the action on a number of lines?

For a simple one-shot, you can just do

        I<li>^[A</li>^[

(where ^[ is escape). If you want the opening tag at the column-beginning-of-line rather than before the first, start with "gI" instead of just "I".

If you plan to do a one-shot, but across a whole bunch of lines, you can use

        :%s!.*!<li>&</li>

Or, if you just want to do it for lines matching a particular pattern, you can use

        :g/pattern/s!.*!<li>&</li>

If you want the opening tag after leading whitespace, you can change those to

        s!^\s*\zs.*!<li>&</li>

Lastly, if it's something you want to do regularly, you can map any of the above behaviors with something like

        :nnoremap <f4> :s!^\s*\zs.*!<lt>li>&<lt>/li><cr>

Hope this gives you some ideas with which to work.

-tim



Reply via email to