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 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: Formatting C++ files

2011-10-29 Thread Totte Karlsson
On 10/29/2011 1:06 AM, Taylor Hedberg wrote: I assume that not every function in the headers is called AFunction with void return type, so this is a little more liberal than precisely what you stated. It will apply to any line that has some whitespace, followed by one or more words (the return

Formatting C++ files

2011-10-28 Thread Totte Karlsson
Hi, I am going trough many C++ headers and need to do some formatting. The first I need to do is related to C++ headers: a lot of them look has lines like this some white spacevoidsome white spaceAFunction(); where the some whitespace is just some whitespace. that I need to convert to a more