When modifying code I find I often have to go through dozens of files to change the simplest of things. For example lets say I have a function pretty_print and I change it to conform to camel case prettyPrint. Now I want to go through the files apple1.js to apple99.js, and possibly a few orange.js files in there. Is there a quick way to do this in Vim?
NOTE: this is not something I can automate, I actually need to go in and modify the code myself.
I know I can do :b <fileName>, but, although it supports name completion/pattern matching, I don’t think the pattern is carried over.
For example, if I do
:b apple*.js
and I hit tab, I’ll get
:b apple1.js
but if I revisit that function (either by pressing : + upArrow or q:) then if I hit tab it won’t go to
:b apple2.js
What I want is to specify something like
:b apple*.js
edit the file, then when I type :w, it moves to the next buffer. I would prefer to stay in Vim, I don’t want to come out, type vim apple*.js, go back into Vim and then use the :x command. I realize this works, but I still need all the other files in case I want to, for example jump between tags.
Probably the most suitable solution for you in this case would be to use the
grep capabilities integrated in Vim. The following command performs a search
for the pattern
\<pretty_print\>in files matching the wildcardapple*.js,and stores locations of the pattern’s occurrences in the quickfix list
allowing to easily jump through all the matches.
For more detailed introduction into the quickfix list with regard to searching
in files, see my answer to the question “Loading a set of files obtained
via cmd-exec into Vim buffers“.
If you would like to simply open a list of files matching a particular
wildcard, load that files’ names into the argument list
and then navigate between them using
:nand:N, as usual.