I edit a large C, C++, or Java file, say, about 15000 lines, with pretty long function definitions, say, about 400 lines. When the cursor is in middle of a function definition, it would be cool to see the function name in Vim status line.
When we set :set ls=2
in Vim, we can get the file path (relative to the current directory), line number, etc. It would be really cool if we could see the function name too. Any ideas how to get it?
Currently I use [[
to go to start of the function and Ctrl-O to get back to the line I'm editing.
You can use ctags.vim for this, it will show the current function name in the title or status bar.
SOURCE: https://superuser.com/questions/279651/how-can-i-make-vim-show-the-current-class-and-method-im-editing
To show current function name in C programs add following in your vimrc:
Or if you need the "f" key, just map the function to whatever you like.
My solution is as follows:
I'm actually attempting to match the C/C++/Java allowed names for functions. This generally works for me (including for overloaded operators) but assumes that the opening { is at column 0 on a line by itself.
I just noticed today that it fails if included in a namespace {}, even if otherwise formatted as expected.
Based on @manav m-n's answer
The 'n' flag in
search()
won't move the cursor, so a shorter version of this with the same functionality would be:Reference: run
:help search()
I use https://github.com/mgedmin/chelper.vim for this. It doesn't needs a tags file, instead it parses the source code on the fly.
There are several plugins for status line or on-demand with a mapping, e.g.: