The image shows that global variable Class A, but the local variable can't be show in tagbar,why? I want tagbar show local variable str,m,n and how to set??
Can the vim tagbar display a local variable?
3.3k Views Asked by Da Lin At
3
There are 3 best solutions below
0

What gets parsed by ctags depends on the language; based on the screenshot, you're interested in C/C++, where it doesn't do this. I don't know the original reasons, but I guess:
- With huge code bases (and who hasn't?), you (and maybe also the editor) would be overwhelmed by the number of tags. Remember that tagbar is kind of special in that it only shows the tags for the current file; usually the tags database is for an entire project.
- It's good practice to keep individual functions short and small; who needs tags lookup when ideally each function fits onto the screen in its entirety?!
The Exuberant Ctags parser can be extended with custom language definitions based on regular expressions (see the --langdef=<language>
and --regex-<language>
arguments). If you can come up with a good pattern for local variables, you could have them parsed.
0

first, tagbar show all tags from ctags and ctags default do not deal with function prototypes, external variable, and local variables (try this in shell: ctags --list-kinds=c++);
second, tagbar's tagbar_type_cpp variable use for this:
let g:tagbar_type_cpp = {
\ 'kinds' : [
\ 'd:macros:1',
\ 'g:enums',
\ 't:typedefs:0:0',
\ 'e:enumerators:0:0',
\ 'n:namespaces',
\ 'c:classes',
\ 's:structs',
\ 'u:unions',
\ 'f:functions',
\ 'm:members:0:0',
\ 'v:global:0:0',
\ 'x:external:0:0',
\ 'l:local:0:0'
\ ]
\ }
Look at the last two lines.
that's all.
Exuberant Ctags has support for local variables as tags, they're just turned off by default. I'd imagine they'd make your tags file huge for a project of any significant size, and I've never turned them on for just that reason (my tags files are already many megabytes). But if you want to give them a try, just add
--c++-kinds=+l
(assuming c++) to yourctags
command when you generate the tags file and that should work.