tags:

views:

86

answers:

2

I have an editor I am attempting to emulate that has some very nice features. One feature of the editor is to hide lines of a file (similar to a fold but without decorations) and apply commands operations only to those lines which remain visible. The hidden lines can then be brough back.
For example the user sees

    Smurf
    Apple
    Bubble
    Tree
    Dog

The user says show-non-matching-lines (SNML) e

    Smurf
    Dog

The user runs a command paste-after-line (PAL) followed by a token, $ say, and gets

    Smurf$
    Dog$

The user says show-all-lines (SAL)

    Smurf$
    Apple
    Bubble
    Tree
    Dog$

I know this is doable in VIM but I am at a loss at how to store per line properties without resorting to modifying the lines in some way. Please nudge me in the right direction or way of thinking...

Update: Using

:set foldtext=MyFoldingFunction

I can manipulate how text is folded with help from the following variables

v:foldstart Line num of 1st folded line 
v:foldend Line num of last folded line

I guess I would have to enumerate all the folds while applying functions as I am applying text formatting and figure out if a line is folded away. I really want a method to store per line properties in vim... I guess I am out in the dark corners here.

+3  A: 

Do you know of :he :g (global). If you can account for the lines by way of regex, (which may not be in your case but often is) and apply an ex command upon it. eg.

:g/\(Smurf\|Dog\)/norm A$

finds a line with Smurf or Dog, then uses :he normal to apply normal mode append $ at the end of line.

This may not be as 'visual' as your editor, but may be potentially a lot more powerful

michael
+5  A: 

folddoopen does what you want; it executes some command on every line that isn't part of a closed fold. To append a $ to every line that isn't currently folded, you can do

:foldd norm A$

See :h folddoopen and :h folddocclosed. It doesn't completely "hide" the folded text, you can still see the fold markers, but it's pretty close.

Brian Carper