Linux Advocacy : Editing multiple files quickly

January 4th, 2009 by Rohan

Standard Disclaimer

  • You can accomplish this in Windows too by installing cygwin or the various tools mentioned in this article.
  • This rant is more about the Linux way of doing things, rather than fighting over which OS is better.
  • I’m not implying that I’m smarter or better than you. Thats for you to decide.
  • There might be better ways in which you can do whatever is outlined in this article. I’m just writing whatever method first came to mind

Editing Multiple Files Quickly

I have a lot of yum repositories defined in my configuration. Often, while installing new software I need to selectively enable or disable some repositories. All the repository definitions are located in *.conf files under a single directory /etc/yum.repos.d

LIst of files

I was looking to install cinelerra - a Linux video editing tool, and for this I had to enable only two yum repositories - kwizart and livna.

The Vim editor can open multiple files. Just specify them as command line arguments.

# vi *.repo

You can use the :n command to go to the next file. :previous for the previous file.

Once I was inside the Vim editor, I immediately ran a search for enabled by typing /enabled, so this word would be higlighted across all files. I can then use the n command to move the cursor to this word.

Enabled

It was that easy!

  1. Type n to move the cursor to the word enabled.
  2. Either enable or disable the repository.
  3. Type :wn to save and go to next file.
  4. Go back to step 1

I ran a simple command at the end to verify which repositories were enabled.

# grep -nr enabled=1 *.repo
kwizart.repo:5:enabled=1
livna.repo:12:enabled=1

Only the kwizart and livna repositories were enabled. Mission accomplished!

Now lets see you do this in WIndows.

[Post to Twitter] Tweet This Post  [Post to Facebook] Facebook 

Leave a Reply




Tweet This Post links powered by Tweet This v1.4.1, a WordPress plugin for Twitter.