String Substitution in VIM

November 9th, 2006 liewsheng Posted in vim | Hits: 28912 | 8 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:


What if you want to substitute a word which in line 2 until line 20:


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:


following command will capitalize only the first charater of every words:


For more info about command can be use, you can visit this page: VIM Trick

8 Responses to “String Substitution in VIM”

  1. 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.

  2. Thank you :)

  3. to aizatto

    Thank you!

  4. Ciekawe naklejki na cian to dobra ozdoba do kazdego domu! naklejki na cian naklejki cienne dekoruj

  5. Nice post there. Will check more soon! You’ve have a good day!

  6. You can definitely see your skills in the article you write.

    The world hopes for more passionate writers like you who aren’t afraid to mention how they believe.
    At all times go after your heart.

  7. I’m pretty pleased to find this great site. I need to to thank you for ones time
    for this particularly wonderful read!! I definitely appreciated every little bit of it and I have you book marked to see new information on your web site.

  8. It’s actually a great and helpful piece of info.
    I’m glad that you shared this helpful information with us.
    Please stay us up to date like this. Thanks for sharing.

Leave a Reply