String Substitution in VIM
November 9th, 2006 liewsheng Posted in vim | Hits: 15066 | 5 Comments »
VIM is a powerful text editor, it have a lot of feature like tag, syntax highlighting…and many more. Here I only show some useful vim command.
To start the VIM editor:
vim <filename>
<filename> is a option. If no <filename> specific, VIM will open a empty buffer for you. After you have edit, If you want to save the text, you can do this:
:save <filename>
Now go to the main topics – string substitution ;p Let say you want to search a word – “help” and substitute by “pleh”, this you can simply enter:
:s/help/pleh/
What if you want to substitute a word which in line 2 until line 20:
:1,20s/help/pleh/
Next you may want to swap order of two different word, for example “help” and “me” to become “me help” :
:s/\(help\) \(me\)/\2 \1/
actually the \(help\) \(me\) can be replace by \(\S*\) \(\S*\), where \S* is mean any character but not a space character (which have intro in Some Trick For VIM). \( and \) pair will store in buffer. The first \( and \) pair will represent by \1, the second \( and \) is \2 and so on…
You can easy to capitalize characters in line by enter:
:s/[a-z]/\u&/
following command will capitalize only the first charater of every words:
:s/\S*/\u&/
For more info about command can be use, you can visit this page: VIM Trick







November 16th, 2006 at 12:16 am
thats inefficient to capitalize all strings on a line…
In command mode enter:
Shift+V U (as in capital U)
Shift+V selects the line
U uppercases it.
Reverse is to use lowercase u which downcases it.
July 13th, 2009 at 4:48 pm
Thank you :)
October 30th, 2009 at 12:53 am
to aizatto
Thank you!
May 19th, 2011 at 1:41 am
Ciekawe naklejki na cian to dobra ozdoba do kazdego domu! naklejki na cian naklejki cienne dekoruj
September 9th, 2011 at 9:17 pm
Nice post there. Will check more soon! You’ve have a good day!