Search multiple buffers for next match

From Vim Tips Wiki

Jump to: navigation, search
Tip 950 Printable Monobook Previous Next

created June 15, 2005 · complexity basic · author Bill Weir · version 5.7

When editing multiple files I like to have a search operation that behaves a bit like "/*" in less (to search multiple buffers looking for the next match). The Nextmatch function (below) does this, although it doesn't behave quite as I would like.

function! Nextmatch()
  let v:errmsg = "X"
  let s:x = bufnr("%")
  while v:errmsg != ""
    if bufnr("%") == s:x
    let v:errmsg = ""
    silent! /

[edit] Comments

It has been suggested that this tip should be deleted, mainly because it doesn't function totally satisfactorily, and the script mentioned below is superior.

The decision was to keep the tip for now, and to think about it again. Please add any comments here (or just improve the tip). Let's think again whether to delete it in August 2008. --JohnBeckett 12:46, 22 April 2008 (UTC)

script#1062 does the same thing but better.

Personal tools