Vim searching through all existing buffers

前端 未结 8 564
刺人心
刺人心 2021-02-01 13:23

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 o

相关标签:
8条回答
  • 2021-02-01 14:24

    Here is your gospel: https://github.com/jeetsukumaran/vim-buffersaurus

    This lovely plugin shows you all the files that match your query in a separate window, from which you can choose. It support regex.

    0 讨论(0)
  • 2021-02-01 14:30

    I have the following mappings (inspired by Vimperator) that make switching previous/next buffer easier.

    nmap <C-P> :bp<CR>
    nmap <C-N> :bn<CR>
    

    This works really well with 'n'. When you're done working with your file, just hit CTRL-n before hitting n again and you're searching in the next buffer. Redo until you're through all buffers.


    Another way of working with many files is the argument list.

    It contains any files passed as parameters when you started vim (e.g: vim someFile.txt someOtherFile.py). The file within [brackets] is the current file.

    :args
    [someFile.txt] someOtherFile.py
    

    :n will bring you to the next file in the list and :N will bring you back. You can also add to the argslist with :argadd, or create a new args list with

    :n some.py files.py you.py want.py to.py work.py with.py
    or to open all *.py files recursively from some project.
    :n ~/MyProjects/TimeMachine/**/*.py
    

    The args list work well with macros too (see :help q), if you have similar changes to your files. Just record your macro on the first file, finish with :n to move to the next file, and stop recording.

    qq/searchForSomethingAndDoStuffOrWhatever:nq
    

    Then run your macro through all files (6@q), have a look to make sure everything went well, and finish with a :wall.


    It kinda depends on what you want to do. If you just have one change that is exactly the same across many files (and those are the only ones you have loaded), I also like the :ba (:tabdo sp) command. It's very quick and you can see what's happening.

    And if you have a bunch of buffers open, you can load up the files you want to work within, each in a window, and do a regexp on all of them.

    CTRL-w v :b someFile
    :sp anotherFile
    ...
    :windo :%s/foo/bar/g
    

    I really recommend FuzzyFinder, it makes your life a lot easier when opening files.

    http://www.vim.org/scripts/script.php?script_id=1984

    MMmMmmmm VIM IS NICE! SO SEXY! : )

    0 讨论(0)
提交回复
热议问题