8

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?

9

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 Sep 4 '19 at 20:36
  • 1
    Learned about dlist today, thanks – D. Ben Knoble Sep 5 '19 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 Feb 19 at 15:15
  • well for python, indent is sufficient, i tried both and didnt see a difference – msudder Feb 20 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 Feb 20 at 22:16

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.