Vim Tips Wiki
No edit summary
 
(Adjust previous/next navigation)
(5 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 
{{review}}
 
{{review}}
  +
{{TipImported
{{Tip
 
 
|id=950
 
|id=950
  +
|previous=949
|title=search multiple buffers for next match
 
  +
|next=952
|created=June 15, 2005 3:13
+
|created=June 15, 2005
 
|complexity=basic
 
|complexity=basic
 
|author=Bill Weir
 
|author=Bill Weir
 
|version=5.7
 
|version=5.7
 
|rating=-8/12
 
|rating=-8/12
  +
|category1=
|text=
 
  +
|category2=
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. I'm kind of hoping somebody will tell me a better way of doing this ...
 
 
 
 
function! Nextmatch()
 
 
let v:errmsg = "X"
 
 
let s:x = bufnr("%")
 
 
while v:errmsg != ""
 
 
bnext
 
 
if bufnr("%") == s:x
 
 
break
 
 
endif
 
 
1
 
 
let v:errmsg = ""
 
 
silent! /
 
 
endwhile
 
 
endfunction
 
 
 
 
And on a related note, can anyone tell me why this bufdo command doesn't work properly (to show all matching lines in all buffers):
 
 
 
 
bufdo g/pattern/p
 
 
 
 
It always seems to miss a few lines.
 
 
}}
 
}}
 
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.
   
  +
<pre>
== Comments ==
 
 
function! Nextmatch()
You ought to ask this type of question on the mailing list, not submit it as a tip (yet).
 
 
let v:errmsg = "X"
 
let s:x = bufnr("%")
 
while v:errmsg != ""
  +
bnext
 
if bufnr("%") == s:x
  +
break
  +
endif
  +
1
 
let v:errmsg = ""
 
silent! /
  +
endwhile
 
endfunction
  +
</pre>
   
 
==Comments==
'''Anonymous'''
 
  +
{{Todo}}
, June 15, 2005 9:03
 
  +
It has been suggested that [[Category_talk:Candidates_for_deletion/Archive4#Tip 950 Search multiple buffers for next match|this tip should be deleted]], mainly because it doesn't function totally satisfactorily, and the script mentioned below is superior.
----
 
This website should make it more obvious that there are forum (forii?) when tips/scripts can be perfected.
 
   
  +
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. --[[User:JohnBeckett|JohnBeckett]] 12:46, 22 April 2008 (UTC)
http://groups-beta.google.com/group/comp.editors
 
   
and also a Vim specific Website at Yahoo
 
 
http://groups.yahoo.com/group/vim/
 
 
anony--AT--mous.com
 
, June 17, 2005 7:42
 
 
----
 
----
  +
{{script|id=1062}} does the same thing but better.
Take a look at the :BufGrep command in the greputils.vim plugin (script 1062) for a similar functionality but better navigability.
 
 
hari_vim at yahoo dot com
 
, June 17, 2005 14:42
 
----
 
Thanks Hari, that's just the kind of thing I was looking for.
 
 
--
 
Bill
 
   
Bill Weir
 
, June 20, 2005 2:24
 
 
----
 
----
<!-- parsed by vimtips.py in 0.861921 seconds-->
 

Revision as of 03:12, 30 June 2008

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 != ""
    bnext
    if bufnr("%") == s:x
      break
    endif
    1
    let v:errmsg = ""
    silent! /
  endwhile
endfunction

Comments

 TO DO 
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.