5

Suppose I have a very long file, for example:

class X {
    // ...
    void foo() {
        // ...
        if (something) {
            a00();
            a01();
            a02();
            // ...
            // ...
            a98();
            a99();
        }
    }
}

When scrolling down to the bottom, all the context (ie., class X, void foo, if (something)) is invisible simply because its outside the current view:

            a93();
            a94();
            a95();
            a96();
            a97();
            a98();
            a99();
        }
    }
}

Is there any way to make vim keep the current context, ie, display something like this:

class X {                    <C>
    void foo() {             <C>
        if (something) {     <C>
            a96();
            a97();
            a98();
            a99();
        }
    }
}

with some markings (<C> in my example) to denote that the lines above a96 are not directly preceding the next one?

  • 1
    As far as I know, the only way to do that is by making a new temporary window above the buffer which displays the lines you want. It's do-able, but some work. – Martin Tournoij Apr 11 '17 at 20:06
  • I remember that there was some plugin that did this for C/C++, using window above (as @Carpetsmoker said), but that was long ago and now I'm not able to find it (or I ask google wrongly). Maybe someone here uses it or knows the name? – grodzik Apr 11 '17 at 20:16
  • What about a fold expression to deal with that? – lsrdg Apr 11 '17 at 21:38
  • @lsrdg i think a fold would be the easiest way to do it... – D. Ben Knoble Apr 11 '17 at 23:58
  • 1
    @DavidBenKnoble but probably not as dinamic as needed... (: But it would be interesting to have a smart fold that would 'fould up' while scrolling down. Right now, I would go with Carpetsmoker. – lsrdg Apr 12 '17 at 5:53
5

I would simply use :rightbelow split.

1

There is a plugin for that here. I've checked it and it works with Vim8, although plugin was written for Vim6. It opens a window above and updates it on CursorHold event. It's supposed to work only with C files, but adding line:

au CursorHold  *.[cC][pP][pP] call <SID>cursorhold()

right after line 431 makes it work with C++ files as well.

EDIT: I've managed to update the script to include C++ classes (and it should work with Pike programming language f.ex. as well). I'll update it a bit more later on. Updated version can be found here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.