From: Hari Krishna Dara <[EMAIL PROTECTED]> Subject: Re: Hiding lines Date: Sun, 17 Sep 2006 14:05:38 -0700 (PDT)
> > On Sun, 17 Sep 2006 at 7:17pm, Meino Christian Cramer wrote: > > > From: Tim Chase <[EMAIL PROTECTED]> > > Subject: Re: Hiding lines > > Date: Sun, 17 Sep 2006 11:15:13 -0500 > > > > > > One could hide lines matching or !matching a certain pattern. Any > > > > further edit actions were only executed with the visible lines as > > > > target. Regardless what you were doing -- only the visible lines were > > > > affected. You had to give the "unhide" command explicitely to return > > > > to "full text mode". > > > > > > > > There is a script snipped in the VimTips (#77) which does something > > > > like this, but the "hidden" lines are not protected or "really > > > > invisible until unhide"... > > > > > > > > Is there a way to mimic this feature with vim in any way ? > > > > > > Well, while it sounds like you may have already uncovered folding > > > (which will collapse/hide a bunch of lines into one), but as you > > > describe, it doesn't really protect those lines. However, there > > > are some things you can do do make them a little more protected. > > > If you're doing :s commands (or other Ex commands), you can > > > have them operate only over things that aren't currently folded > > > away by modifying your Ex statement to be: > > > > > > :foldd s/foo/bar/g > > > > > > You can read all about folding at > > > > > > :help fold.txt > > > > > > wherein you'll find > > > > > > :help folddoopen > > > :help folddoclosed > > > > > > which allow you to perform operations over sections of the file > > > that are/aren't folded. > > > > > > You don't really describe what "protected" means...so perhaps if > > > there are particular things that stymie you, you can mention them > > > and perhaps a solution can be found for the particular problems. > > > > > > If you just want to extract certain lines, you can make use of a > > > :g command, something like > > > > > > :let @a='' > > > :g/pattern/y A > > > > > > will gather all the lines matching "pattern" into the "a" > > > register. This can be dumped in another buffer if needed. > > > > > > Or, I often find myself doing something like > > > > > > :g/pattern/# > > > > > > which will show me all the line numbers in the current file for > > > lines matching "pattern" (after which I can just jump to that > > > line by typing the line-number followed by "G"). > > > > > > Just a couple ideas... > > > > > > -tim > > > > > > > Hi Tim, > > > > thank you for your explanations ! :O) > > > > With "protected" I mean the effect of doing as follows (but I mean > > the result only ... not the way which leads to it...) > > > > There is a text with some lines containing the word "gold". > > Those lines should never be changed/edited. > > Therefore I will do a :g/gold/d > > Then I will do all commands, mistakes or whatever, which I will > > do -- all "gold" lines will not be affected. > > After all that I will do a "undo delete of all lines containing > > 'gold'" -- and that's it. > > > > In reality an "undo delete all lines containing /pattern/" is not > > pratical, impossible, irritationg or whatelse. This is only as an > > example for "being protected". > > > > An Unix "chmod a-w" on all lines matching /pattern/ cames a little > > closer to it -- unless you are root, hehehehe.... > > > > But in the last example those lines were not hidden. > > > > Examples are only ...examples, therefore... > > > > Hope my german English is english enough... ;) > > > > Keep hacking! > > mcc > > Tim's :foldd and :foldo suggestions are actually very good in deed > (didn't know about them), especially with the help of tools to create > folds and operate commands on them. I would like to suggest you take a > look at my foldutil.vim (http://www.vim.org/script.php?script_id=158). > The benefit for you is that you can execute a single command to create > folds that include/exclude all the lines that are matching or > not-matching your specified pattern. You can then use :foldo or :foldd > commands to issue commands on them. > > Also configure the 'foldopen' setting such that the folds will not be > automatically opened by Vim when you move cursor around. I think, > setting an empty value will help keep them closed as much as possible. > > You might also be interested in my multiselect.vim plugin > (http://www.vim.org/script.php?script_id=953). It provides commands that > are similar in nature to :foldo and :foldd to restrict normal mode and > ex mode commands to selected regions. You can also use mouse to create > selections. > > -- > HTH, > Hari > > __________________________________________________ > Do You Yahoo!? > Tired of spam? Yahoo! Mail has the best spam protection around > http://mail.yahoo.com > Hi, I have downloaded your script and genutils but got some problems... It displays: Folds created: 0 line 75: E117: Unknown function: RestoreHardPosition There is another message, which appears for a very short time -- too short for me to read it. What did I wrong here ? Keep hacking! mcc