On the Linux platform, there are many good shell command combinations to do multiple file lookups/replacements, such as these commands: Find,sed,grep,awk,perl. But other platforms such as windows are less convenient, and Vim's built-in multiple file lookup commands are useful, although slightly slower than external commands.
VIM Multi-file lookup
This vim built-in command is Vimgrep, and there are two basic ways to use it:
: vim[grep][!]/{pattern}/[g][j] {file} ...
: vim[grep][!] {Pattern} {file} ...
The file section supports wildcards, * represents the current directory, * * represents the current directory and its subdirectories (recursion), for example, */*.C represents the C source program file in the current directory, and **/*.C represents all source program files under the current directory and its recursive subdirectories. The file section can be specified more than once.
The following command looks at the matching results:
: Cn[ext] Next result
: cp[revious] Previous result
: Cw[indow] Quickfix window, result file list
For more detailed use see: Help Vimgrep and the refs below.
Vim multi-file replacement
In fact, as long as the following two commands are available (assuming that you want to replace the hate in all files in the current directory with. Txt/.cpp):
: args *.txt *.cpp:argdo%s/hate/love/gc | Update
: args *.txt *.cpp
: Argdo%S/HATE/LOVE/GC | Update
will be done. Explained as follows,
: args *.txt *.cpp
: args *.txt *.cpp
This write scans the. txt and. cpp files in the current directory and adds them to the parameter list. But this writing will only seedlings the current directory, and if you want to recursively scan all the subordinate directories, use the
: Args **/*.txt
: Args **/*.txt
If you only want to scan the next level of the directory (that is, not scanning the current directory), use the
: Args */*.txt
: Args */*.txt
and
: Argdo%S/HATE/LOVE/GC | Update
: Argdo%S/HATE/LOVE/GC | Update
is to change the hate of all files in the argument list to love and write to the hard disk (if there is no |update, it will not be written, but the corresponding substitution will be interrupted).
Last but not least, when using a replacement command, always remember to back up, because the replacement is directly written to the hard drive drop oh ...
Well, I hope this article is useful to everyone ~