DirDo.vim : Performs Vim commands over files recursively under multiple directories.
| script karma
Downloaded by 2781
Comments, bugs, improvements
script versions (upload new version)
|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
- The :argdo command in Vim 6.0
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
:DirDoDir [/my/directory1] [/my/directory2] [/my/directory3]
: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
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] ...
: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:
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
If no argument is given, then it'll reuse the last command.
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
(Since 1.2) There is a command called DirDoFast where you can set the
directory, pattern, and command at once. Note that your arguments need to
be escaped if there is an space to it, otherwise Vim will break up the
arguments incorrectly. The syntax is:
:DirDoFast [directories] [patterns] command
:DDF [directories] [patterns] command
Multiple directories need to be separated by comma. Patterns need to be
separated by spaces. Since space is used by Vim to separate the command
arguments, ALL spaces in the directory, pattern, or command need to be
escaped. For example, the last command using DDF would look like:
:DDF /my/directory *.java\ *.c %s/Foo/Bar/gce\ |\ update
If you only give 2 arguments to :DDF, you assume the directory is set to
If you only give 1 argument to :DDF, you assume the directory is set to
"." and the pattern is set to "*".
(Since 1.3) There is a command called DirReplace that simplifies the
multi-directory string replace procedure. Essentially, it is the same
as executing DirDoFast with a directory, pattern, and command (as
s/[regex_pattern]/[replacement/gce | update).
You will be asked for the directories, glob patterns, regex string, and
There is an option to run DirDo with less verbosity, to toggle the
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
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"
Click on the package to download.
ip used for rating: 126.96.36.199
||Added the DirReplace command. Fixed a bug on the directory listing that prevents DirDo from functioning properly.
||Added the DirDoFast command so you can set directory, pattern, and command at once. Fixed bug where the unix hidden file will not show up in the file list. Fixed bug where ~ in the path does not work.
||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.