Tuesday, January 17, 2012

Re: specifying multiple ranges in vim

On 01/17/12 08:17, rail shafigulin wrote:
> does anybody know if it is possible to specify multiple ranges in vim for a
> command execution
> for example:
> :1,4s/old/new/g - this command will replace old to new in lines 1 to 4
> inclusive
>
> however what if i want to execute this command in multiple places say
> something like
>
> :1,4;10,14;20,24s/old/new/g - i want to do a replacement on lines 1 through
> 4, 10 through 14, and 20 through 24
>
> does anybody know if it is possible in vim?

You can combine the "\|" ("or") atom with the "\%l" atom to
produce :global searches like

:g/\%<5l\|\%>9l\%<15l\|\%>19l\%<25l/s/old/new/g

It's a bit ugly, but it does what you ask.

:help :g
:help /\%l
:help /\|

Hope this helps,

-tim


--
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: