Vim Tip of the Week : Oct 5th, 2007

By | 2007/10/05

This vim tip of the week was submitted by Andrew.  Many thanks.  Do you have a vi/vim tip that you’d like to share with the world?  Visit my contact page and send me your idea!

This vim tip relates to updating multiple windows or tabs within vim with a single command.  If you ever edit multiple files at once, or use the tabbing or windowing feature of vim this can save you some typing.  To do this we’d use the command:

:windo {cmd}

As Andrew outlines in his submission:

This is a fantastic command that has saved me much typing since I discovered it. Put simply, it executes {cmd} once for each open Vim window. If you've just opened a large number of files each in their own window and need to do the same thing in each, this is what you want.

Here is an example of using :window {cmd} to do a find and replace across multiple files:

 :windo %s/search/replace/g

There are also the :windo related commands such as:

:bufdo {cmd} - run {cmd} in each buffer

:tabdo {cmd} - run {cmd} in each tab

:argdo {cmd} - run {cmd} in each file in an argument list

I want to thank Andrew again for his submission.  If you have a vim tip that you’d like to share feel free to submit it via my contact page.

3 thoughts on “Vim Tip of the Week : Oct 5th, 2007

  1. Elaine

    I hit the SU icon and Stumbleupon was telling me Page Not Found. Never seen that before.

    Reply

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.