Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!dali.cs.montana.edu!ogicse!intelhf!ichips!iwarp.intel.com!gargoyle!chinet!les From: les@chinet.chi.il.us (Leslie Mikesell) Newsgroups: comp.editors Subject: Re: Restricted Searches in VI Message-ID: <1991Apr23.144457.5857@chinet.chi.il.us> Date: 23 Apr 91 14:44:57 GMT References: <1991Apr22.071658.1059@cerberus.bhpese.oz.au> <91112.182420FFAAC09@cc1.kuleuven.ac.be> Organization: Chinet - Chicago Public Access UNIX Lines: 30 fozzy@mips.bhpese.oz.au (Andrew Steele) says: >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. If you just want to see the relevant lines, :address,addressg/pattern/p will work and the start and end address can be represented by the usual ways (line number, .=current line, marks, search patterns, etc.) so you could position to the beginning of a function to search, then use :.,/^}/g/pattern/p But it might be just as informative to :set number, note the start and end lines of the function, and search the whole file with :g/pattern/p. Another way is to insert a temporary marker at the beginning of the relevant lines (easy with ex commands) so you can easily see where you are and restrict the search by including the marker in your search pattern (or just pay attention to the display). Often, though it is easier to just use explicit temporary files. Keep in mind that you have more than the editor built-ins at your disposal - there is a general purpose OS and file system out there as well. If you need to use more than the two files that vi handles internally, you can always run another copy in a subshell without losing your current environment. Les Mikesell les@chinet.chi.il.us