Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!olivea!mintaka!bloom-beacon!eru!hagbard!sunic!mcsun!cernvax!chx400!chx400!bernina!neptune!inf.ethz.ch!wyle From: wyle@inf.ethz.ch (Mitchell Wyle) Newsgroups: comp.editors Subject: Re: Restricted Searches in VI Summary: dunno Keywords: use buffers Message-ID: <28178@neptune.inf.ethz.ch> Date: 22 Apr 91 12:06:36 GMT Sender: news@neptune.inf.ethz.ch Reply-To: wyle@inf.ethz.ch (Mitchell Wyle) Organization: Departement Informatik, ETH, Zurich Lines: 43 Greetings vi fans, RJ-rn screwed up again so I don't know who wrote this article; anyway, someone asked: >In vi is it possible to restrict the range of a search. Specifically >I want to be able to search through just one function in a .c file. >I've inherited some badly written code that has functions that just go on >and on and I'm trying to break them up into smaller units. To do this I need >to be able to find where local variables are used but not if that name is >also used in some other function later on. I apologize that this method is not a direct answer to your question. I solve this problem as follows: I start an edit session of a non-existent file, read in the C module, trim off everything except the function I want to change, and search inside it. I must admit it *sounds* complicated, but it works for me. % vi tt start vi on an empty file :r bigmodule.c read in the C file /big_bad_function find begining of big, bad C function k:1,.d delete everything above it }}jj%j find end of big, bad C function matching first brace .,$d delete everything below it. /foo_bar start searching for use of variable foo_bar >If it's too much of a hassel I'll continue as I have been by checking with >"[[" to see which function I am in, but I thought there may be some way of >combining either "[[" or "%" with a "/" to give a restricted search. I have seen people using % inside vi macros to delete everything inside a given parenthesis level, but I've never tried to restricted a search inside a given file. I usually use markers and [[ to mark and come back to places when I am searching inside big files. Also, check out using C cross-reference programs to tell you which variables are used where in which functions. It might be easier to work on paper than on-line. Cheers, -Mitch