Personal tools
You are here: Home kaeru's blog Archive 2007 August 28 loading multiple files that match a string with vim
Document Actions

loading multiple files that match a string with vim

by kaeru last modified 2007-08-28 23:25
Filed Under:

loading multiple files that match a string with vim using command line unix tools

Using the ever useful grep, with -l option, it outputs only the matching filenames:

grep -rl --exclude '*.svn*' CMFCore *

vim loads multiples file in one line separated by spaces. So I need to join the multiple lines into one, separated by space. Here we have the paste command. For each line, put a space as the separator:

paste  -s -d " "

Finally I wanted vim to load this in GUI mode with tabs, so we put it together:

gvim -p $(grep -rl --exclude '*.svn*' CMFCore *  | paste  -s -d " " -)
  • the part inside the $( ) is the output of the command.
  • using pipes | the output of grep (the list of files) is read by paste
  • the - in paste is telling it to input the stdout output of grep

I then quickly have my editor setup for work,

http://kaeru.inigo-tech.com/blog/blog-images/gvim-tabs.png/image_preview

Powered by Plone CMS, the Open Source Content Management System

This site conforms to the following standards: