think tank forum

technology » vi(m) and regular expressions

asemisldkfj's avatar
17 years ago
link
asemisldkfj
the law is no protection
just saved me about a million years of my life.

instead of adding line breaks to the end of hundreds (literally) of lines of code, I did :g/^I^I^I^I^I-/normal $a<br /> and it took all of one second.

thank you, vi!
asemisldkfj's avatar
17 years ago
link
asemisldkfj
the law is no protection
(I was adding line breaks to the end of a bunch of lines that were five tabs in and started with dashes, if that isn't obvious.)
asemisldkfj's avatar
17 years ago
link
asemisldkfj
the law is no protection
on this same note, I despise HTML.
nestor's avatar
16 years ago
link
nestor
nestor
http://houghi.org/shots/vim001.gif
asemisldkfj's avatar
16 years ago
link
asemisldkfj
the law is no protection
hahaha I'm glad you posted that in this thread.
DaGr8Gatzby's avatar
16 years ago
link
DaGr8Gatzby
Drunk by Myself
oh man that's classic!
nestor's avatar
16 years ago
link
nestor
nestor
asemi > i know, it really was the perfect thread to post in :)
bluet's avatar
16 years ago
link
bluet
is :g the same as :%s?
asemisldkfj's avatar
16 years ago
link
asemisldkfj
the law is no protection
good question. what's the percent sign in :%s for?
bluet's avatar
16 years ago
link
bluet
it does s for all lines
asemisldkfj's avatar
16 years ago
link
asemisldkfj
the law is no protection
well g stands for global, so maybe it's the same?
Carpetsmoker's avatar
16 years ago
link
Carpetsmoker
Martin
No, the format is like this:
<range>s/search/replace/flags

The g flag means that it will replace all occurences of <search> on the same line, for example with the line:
aa

:s/a/A/

Will output Aa

and :s/a/A/g

will output AA

and :3,5s/a/A/

Will replace a with A only on lines 3 through 5

btw.
You put put a range before most commands, this is not unique to :subtitute, see :help range
bluet's avatar
16 years ago
link
bluet
carpetsmoker: of course, but the g command was new to me. guess i'm still used to ed