Monday, November 7, 2011

Re: search and replace (not what was searched for)

>> [1
>> [2
>> [3
>>
>> and want to add the missing ] at the end of the line.
>>
> It depends on whether you need to manually tweak each line or if the change can
> be automated. In your case, you can do things like
>
> :%s/\[\d\+]\@!\zs/]/g
>
> "where there's an open-bracket, one or more digits and no closing brace, start
> replacing at the end of the match and replace with a close-bracket" This one is
> pretty tight and should skip cases where there's already a close-bracket
>
That is pretty complex, gotta read upon how that is working.

> 2) :g/\[\d/s/$/]

>
> "on lines containing an open-bracket followed by digits, put a ']' at the end of
> the line"
Got this from Taylor. Great.

>
> 3) if they're contiguous, visually select the lines in block-mode, press "$"
> followed by "A" (append some text after each line), "]" (the text you want to
> append) and <esc> (to exit insert-mode)
>
> 4) you can search for the text, placing the cursor at the end and use "n" and
> "." to append the text:
>
> /\[\d\+/e
> a]<esc>
> n.n.n.n.n.n. (as needed)

Thanks!
totte

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