Vim logo vim online Vim Book Ad

DirDo.vim : Performs Vim commands over files recursively under multiple directories.

 script karma  Rating 35/11, Downloaded by 300

created by
William Lee
 
script type
utility
 
description
This plugin is like :argdo but it works recursively under a directory (or
multiple directories).  The limitation for :argdo is that it does not glob
the files inside the subdirectories.  DirDo works in a similar manner but
you're allowed to specify multiple directories (good for refactoring code
and modifying files in a deep hierarchy).  DirDo also globs the files in
the subdirectories so you can make sure an operation is performed
consistantly.
 
install details
Put this file in your ~/.vim/plugin directory.

The syntax of the commands:

First we need to set what directory we would like to perform this
command on

    :DirDoDir [/my/directory1] [/my/directory2] [/my/directory3]

    or

    :DDD [/my/directory1] [/my/directory2] [/my/directory3]

If no argument is given, then it'll display the directories that you're
going to work on and let you edit them by separating them with commas
(',')

You can also use the following command to add a directory to the DirDoDir variable:

       :DirDoAdd /my/dir

       or

       :DDA /my/dir

If you do not give an argument to DDA, it'll add the current working
directory to the DirDoDir variable.

Then we set the file glob pattern:

    :DirDoPattern [file glob pattern1] [file glob pattern2] ...

    or

    :DDP [file glob pattern1] [file glob pattern2] ...

If no argument is given, then it'll display the patterns and let you
edit them (separate each pattern with spaces).

Then, you can do:

    :DirDo [commands]

    or

    :DDO [commands]

to executes the commands on each file that matches the glob pattern
recursively under the directories that you have specified.  The format of
[commands] is just like what you do on :argdo. See :help argdo for
details.

If no argument is given, then it'll reuse the last command.

Examples:

Replace all the instaces of "Foo" to "Bar" in all the Java or C files under
the directory /my/directory and its subdirectories, confirming each match:

    :DDD /my/directory (or just :DDD<CR> and type it in)
    :DDP *.java *.c (or just :DDP<CR> and type it in)
    :DDO %s/Foo/Bar/gce | update

(See :h argdo for the commands after DDO.)

Same scenario but replacing "Bar" with "Baz" without confirmation for each
match (note the directory and patterns are saved):

    :DDO %s/Bar/Baz/ge | update


There is an option to run DirDo with less verbosity, to toggle the
setting, run:

    :DirDoVerbose

    or

    :DDV

You can also set the following variables in your .vimrc to set the default
directory and pattern.  This is good for pointing to the directories for
code refactoring:

let g:DirDoPattern = "..."

let g:DirDoDir = "..."

For example, if you want by default have the command apply on all your C,
C++, and Java source, you can set the DirDoPattern to:

let g:DirDoPattern = "*.c *.cpp *.java"

If you want to apply your changes to /dir1, /dir2, and /dir3, you can do:

let g:DirDoDir = "/dir1,/dir2,/dir3"
 

rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
DirDo.vim 1.1 20-Aug-2002 6.0 William Lee Added the option :DirDoAdd (:DDA) to add the current directory (getcwd()) to the list of directories that you want to apply DirDo on.  This is useful if you want to construct your list of DirDo directories quickly.
DirDo.vim 1.0 07-Aug-2002 6.0 William Lee Initial upload

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to [email protected] after searching the archive. Help Bram help Uganda.
SourceForge Logo