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?
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
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
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,
[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,
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
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