1

Opening all 49 files in my working folder in separate buffers, I wanted to see if there were any em dashes.

I typed :bufdo /— and vim immediately went to work, processing a page of buffers at a time. All but one file appeared to not contain my string. The thing is, I wasn’t able to check. Everything just wizzed by and I just happened to see that there was one file that wasn’t marked as “Pattern not found”. What I was expecting was for it to stop at the first occurrence and then let me use n and N to scroll through the search findings.

My question is, is there a way to search through multiple buffers (without replacing) in a way that behaves similarly to searching in a single buffer?

2
  1. bufdo runs a command (here, the ex command :/), so there's no real interactivity
  2. For a search over multiple files (or buffers), use :grep/:vimgrep. For example:
:grep -R pat .
" or
:vimgrep /pat/ **/*
" or whatever you need

Then you navigate with the quickfix list (:help quickfix). Probably :cnext/:cprevious are useful, or :cwindow if you want to browse the list of matches.

3
  • vimgrep worked. Is there a way of specifying a range in each file similar to :10,$? (I have a yaml header and need to search for stray hyphens in the text while avoiding the six hyphens in the yaml section.) – BrianWilson Mar 24 at 18:18
  • 1
    @BrianWilson :help /\%>l (the last character is a lowercase L) – D. Ben Knoble Mar 24 at 19:02
  • 1
    Thank you! For those following along at home the full command was :vimgrep /\%>10l-/ *.txt – BrianWilson Mar 24 at 20:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.