vim - tags
Tags in Vim
cTags in Vim
https://andrew.stwrt.ca/posts/vim-ctags/
You would have to install cTags separately. It does not come with Vim.
How to generate tags and use them for navigation in a big java project? Go to the root folder of the project and execute this command : ctags -R
The next step is to get the full path of this tags file - in Linux, use the readlink utility to get the full path. [n0281526@VDDP14P-4UCXMSH renters-api-sb2]$ readlink -f tags /home/n0281526/Downloads/GitRepositories/renters-api-sb2/tags
open a file in the root folder of the project and run this command from within vim (use semi-colon and then type it) set tags=./tags;/ (It starts with a tags file in the current directory and goes up to the root directory.)
One line that always goes in my .vimrc: set tags=./tags;/ This will look in the current directory for “tags”, and work up the tree towards root until one is found. In other words, you can be anywhere in your source tree instead of just the root of it.
Ctrl+] - go to definition Ctrl+T - Jump back from the definition. Ctrl+W Ctrl+] - Open the definition in a horizontal split
Add these lines in vimrc map <C-\> :tab split<CR>:exec(“tag “.expand("<cword>”))<CR> map <A-]> :vsp <CR>:exec(“tag “.expand("<cword>”))<CR>
Ctrl+\ - Open the definition in a new tab Alt+] - Open the definition in a vertical split
After the tags are generated. You can use the following keys to tag into and tag out of functions:
Ctrl+Left MouseClick - Go to definition Ctrl+Right MouseClick - Jump back from definition
command | description |
---|---|
:ta t↵ | jump to tag t |
:nta↵ | jump to nth newer tag in list |
^] ^T | jump to the tag under cursor, return from tag |
:ts t↵ | list matching tags and select one for jump |
:tj t↵ | jump to tag or select one if multiple matches |
:tags↵ | print tag list |
:npo↵ :n^T↵ | jump back from, to nth older tag |
:tl↵ | jump to last matching tag |
^W} :pt t↵ | preview tag under cursor, tag t |
^W] | split window and show tag under cursor |
^Wz or :pc↵ | close tag preview window |