sh1ftst0rm sh1ftst0rm - 1 month ago 5x
Python Question

Show my current semantic location in a python file

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

method, I may know I'm in a
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?


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>