When dealing with a single file, I'm used to:
/blah do some work n do some work n do some work
Suppose now I want to search for some pattern over all buffers loaded in Vim, do some work on them, and move on. What commands do I use for this work flow?
script, and place the following in your vimrc. Pressing Alt-F12 opens a window listing the buffers, and you can press Enter on a buffer name to go to that buffer. Or, press F12 (next) or Shift-F12 (previous) to cycle through the buffers.
Just put it to your . vim/plugin directory and then use :BufOnly command to close all buffers but the active one.
:wa - save all tabs / unsaved buffers. :xa / :wqa - save all tabs / unsaved buffers and exit Vim.
Use the bufdo
command.
:bufdo command
:bufdo command
is roughly equivalent to iterating over each buffer and executing command. For example, let's say you want to do a find and replace throughout all buffers:
:bufdo! %s/FIND/REPLACE/g
Or let's say we want to delete all lines of text that match the regex "SQL" from all buffers:
:bufdo! g/SQL/del
Or maybe we want to set the file encoding to UTF-8 on all the buffers:
:bufdo! set fenc=utf-8
The above can be extrapolated for Windows (:windo
), Tabs (:tabdo
), and arguments (:argdo
). See help on :bufdo for more information.
We can do this using vimgrep
and searching across the argslist. But first let's populate our argslist with all our buffers:
:bufdo :args ## %
Now we can search in our argslist
:vimgrep /blah/ ##
Where % == the current filepath
and ## == the arglist
.
I recommend watching these vimcasts if you want to learn more: Populate the arglist, Search multiple files with vimgrep
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With