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
That is pretty complex, gotta read upon how that is working.
%s/ on every line matching
\[ a literal "["
\d\+ one or more digits
]\@! assert that a "]" doesn't match here to prevent
it from adding a "]" if one is already present
\zs start the replacement here
(with nothing following this, it ends up being
an insertion after the match, instead of replacing)
/ replace with
] the literal "]" you want to add
/g and do it for all matches on the line
If you KNOW that none of them are closed, you can omit the assertion:
:%s/\[\d\+\zs/]/g
or you can avoid the "\zs" by including the match in the replacement:
:%s/\[\d\+]\@!/&]/g
:%s/\[\d\+/&]/g
-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