Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
292 views
in Technique[技术] by (71.8m points)

Vim searching through all existing buffers

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?

question from:https://stackoverflow.com/questions/2450887/vim-searching-through-all-existing-buffers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...