Question

When editing python files, I frequently loose track of where I am in the structure of the file. For instance, if I have several large classes that all implement a foo method, I may know I'm in a foo function, but not know which class I'm in. Or more simply, if I have very large functions, I may not even know what function I'm in if the function definition is off the screen.

Is there someway in Vim that I can print out a path to my current location in the file? For instance, show the class or classes I'm in, and the function I'm in?

Was it helpful?

Solution

I think both Tagbar and Taglist have that kind of feature but you can always do [[ to jump to the class definition and `` (backtick backtick) to jump back to your current location.

This quick and dirty mapping will echo the first class and method definitions above your current cursor location:

nnoremap <F6> :echo getline(search('^class', 'bn')) . "\n" . getline(search('^\s*def', 'bn'))<CR>

OTHER TIPS

Have a look at the Tagbar - Display tags of the current file ordered by scope plugin. Using information generated by ctags (so it supports several languages, not just Python), it shows the buffer's structure (i.e. classes > methods) in a sidebar, and can update the "you are here" marker based on the cursor position.

Do keep in mind that Vim is not an IDE, so you won't find the same comfort (but really efficient text editing features).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top