1

while coding in vim I use often special comment to denote section of the file. For example in C it is

//;; some title 1
//;; some title 2

I have also configured a shortcut to print with a global command (g/.../p) all such entries in the file.

The output print looks like

16 //;; some title 1
32 //;; some title 2

then I just type : and the line number to jump directly to the line.

Although I am quite satisfied with it, it would be much faster If i could navigate in this list like a mini buffer and then select the entry.

As I use fzf in vim I was thinking about creating a vim list to input to fzf. However the idea got much harder to implement as expected.

Is there some easier way to do it?

2

This seems like a pretty good use-case for the location list, so here is one "vanilla vim" solution:

:lvimgrep '\V//;;' % | lopen

You can make a mapping or a command around this.

Breakdown: lvimgrep loads the location list with lines matching //;; (we use \V to make it easier to enter this pattern), from the current file (%). Then we open the location list using lopen.

You can also use :lnext and :lprev (among other commands) to navigate between positoins.

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.