search and replace (not what was searched for)

2011-11-07 Thread Totte Karlsson
Hi, I often wants to search for lines that have a certain characteristic, and change it. However, I may not want to change what I am searching for. For example. Say I have lines looking like this [1 [2 [3 and want to add the missing ] at the end of the line. What is the command for that?

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

2011-11-07 Thread Taylor Hedberg
You're looking for the `:global` (a.k.a. `:g`) command. For your example: :g/^\[\d/s/$/] This says, Tag lines matching the pattern /^\[\d/ (open bracket at the beginning of the line, followed by a decimal digit), and on each tagged line, replace the end of the line with a close bracket. In

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

2011-11-07 Thread Tim Chase
On 11/07/11 13:07, Totte Karlsson wrote: Say I have lines looking like this [1 [2 [3 and want to add the missing ] at the end of the line. What is the command for that? Should one use search and replace or something else? It depends on whether you need to manually tweak each line or if

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

2011-11-07 Thread Totte Karlsson
On 11/7/2011 11:18 AM, Taylor Hedberg wrote: You're looking for the `:global` (a.k.a. `:g`) command. For your example: :g/^\[\d/s/$/] This says, Tag lines matching the pattern /^\[\d/ (open bracket at the beginning of the line, followed by a decimal digit), and on each tagged line,

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

2011-11-07 Thread Totte Karlsson
[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,

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

2011-11-07 Thread Tim Chase
On 11/07/11 13:40, Totte Karlsson wrote: :%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

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

2011-11-07 Thread Chris Jones
On Mon, Nov 07, 2011 at 02:07:55PM EST, Totte Karlsson wrote: Hi, I often wants to search for lines that have a certain characteristic, and change it. However, I may not want to change what I am searching for. For example. Say I have lines looking like this [1 [2 [3 and want to add