How can I make vim show the current class and method I'm editing
This will work if you install both the airline and tagbar plugins. These two plugins integrate automatically and you'll get the current function displayed in the status bar. If you want to have the full object hierarchy (e.g. class + method), you'll have to configure that in your .vimrc:
let g:airline#extensions#tagbar#flags = 'f' " show full tag hierarchy
You might have to setup the tags file for tagbar to identify the current code position, if you are not using ctags, yet. If you don't know about that yet, here's a short intro to ctags.
This script puts the name of the current function in the title bar and/or the status line. It uses ctags to generate a list of tags for the current file and assumes that the tag preceding the cursor location is the name of the current function. Since it uses ctags, it can be customized to work with different languages, even structured text files. It works well in practice, but has some limitations. If nothing else, it might give you a starting point for hacking.
I would suggest using https://github.com/wellle/context.vim. It shows current context that you are in. Here is image from project
Having recently tried this, I believe the simplest solution is:
-
Install Universal Ctags https://ctags.io/
-
Install Tagbar https://github.com/preservim/tagbar
-
call
tagbar#currenttag()
when setting your statusline, e.g. in .vimrc::set statusline=%<%f\ %h%m%r%=%{tagbar#currenttag('%s\ ','','f')}%-.(%l,%c%V%)\ %P
Airline completely changes your statusbar and it's non-trivial to get
Note that:
-
Spaces must be slash-escaped in the strings you pass to
currenttag()
...and it's even different between running the command inside vim and putting it in your .vimrc?? Anyway, spaces can be weird, and they're probably something you want when outputting the function name. -
It took me some digging but the default statusline is
:set statusline=%<%f\ %h%m%r%=%-14.(%l,%c%V%)\ %P