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

Reply via email to