Saturday, May 22, 2010

Re: Visually select lines to number

On 22/05/10 20:00, Bee wrote:
> Visually select lines to number, the following works:
>
> :let @r=1<bar> '<,'>s#^#\=printf("%02d. ", @r + setreg('r', @r+1))#
>
> 01. select the lines
>
> 02. type :
> problem is '<,'> is inserted at the beginning of the line and
> must be deleted before using the above command.
>
> I would like a vmap that does not insert the '<,'>
>
> Is this possible?
>

When you hit the colon in Visual mode, Vim inserts '<,'> which means
"from first to last line of the latest Visual selection". To delete
those lines, you can include a CTRL-U immediately after the colon (see
:help c_CTRL-U ), it remove everything on the command-line between the
colon and the cursor. So the mapping would be for instance

:xnoremap <F4> :<C-U>let @r = 1 <Bar> '<,'>s/^/<Bslash>=printf('%02d.
', @r + setreg('r', @r + 1))/

In Vim 7 (to be picky, in Vim 7.0g beta or later) you can use <special>
before the {lhs} to make sure that <> codes will be translated even if
the mapping is run in 'compatible' mode (see :help :map-<special> ).


Berst regards,
Tony.
--
The notion that the church, the press, and the universities should
serve the state is essentially a Communist notion ... In a free society
these institutions must be wholly free -- which is to say that their
function is to serve as checks upon the state.
-- Alan Barth

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments: