9

While working in various source files, (C, Ruby, etc.) I find that I'm often hunting around for functions. Is there a way to have an auto-generated HUD that lists the structure of the current file? It would be fantastic if it linked to different parts of the file, similar to how NERDTree links to different files. Or, similar to the side-navs in the screenshots here: https://stackoverflow.com/questions/16895610/gen-file-missing-incomplete-in-eclipse

Assuming that this doesn't exist as a plugin or something, how do people usually navigate around files like this?

3 Answers 3

12

You could try either TagList or TagBar but such a list could be generated as needed (no third party tool or configuration needed) with a simple:

:g/func/#

See :help :global.

If you don't mind a little bit of per-filetype configuration, the :dlist command could be used to list every function in the current file and included files:

:dlist /

See :help definition-search, :help 'include', :help 'define', :help 'suffixesadd'.

2
  • not a very smart approach though. Would rather have the screen splitted and read the fucntion list in a draft
    – milaniez
    Commented Sep 4, 2019 at 20:36
  • 1
    Learned about dlist today, thanks
    – D. Ben Knoble
    Commented Sep 5, 2019 at 0:52
0

Instead of writing a regex as @romainl seem to be suggesting, You can have taglists installed and add the following to .vimrc:

nnoremap <C-l> :TlistToggle<CR>

Now by pressing Ctrl + l you'll show/hide the list of functions, structures and more.

0

This works for my python files.

zM folds the file to the lowest number of lines, then zo unfolds the line that is folded to show functions in classes which can be searched, then when you want to look at a function content, goto its folded lines and unfold all with zO.

:help fold
3
  • 1
    You probably have foldmethod set to syntax, right?
    – D. Ben Knoble
    Commented Feb 19, 2021 at 15:15
  • well for python, indent is sufficient, i tried both and didnt see a difference
    – msudder
    Commented Feb 20, 2021 at 21:47
  • Ah, or indent, yes. I dont know that either is the default, so its worth mentioning in the answer.
    – D. Ben Knoble
    Commented Feb 20, 2021 at 22:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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