



















If you have a source file with hundreds or thousands of lines of code. How to you see its structure and go to some classes or methods quickly in Nvim? The solution is to use tagbar.
To use tagbar, you have to install universal-ctags, which will generate tag files for tagbar to use.
We need to build and install by ourself:
git clone https://github.com/universal-ctags/ctags.git
cd ctags
./autogen.sh
./configure --prefix=/where/you/want/to/install # install to where you have access
make -j && make install # may require extra privileges depending on where to installUnder the install directory, there are two directories: bin 和 share. The
ctags executable is in the bin directory. We need to add this bin directory
to the system PATH variable:
# suppose that you have install ctags to $HOME/tools/ctags
echo export PATH=$HOME/tools/ctags/bin:$PATH >> ~/.bash_profile
source ~/.bash_profileFor Mac OS, if you have installed Homebrew, you can simply using the following command to install ctags:
brew install --HEAD universal-ctags/universal-ctags/universal-ctagsHomebrew will do everything for you. No need to set up install path.
Then install tagbar with your favorite plugin manager such as vim-plug:
Plug 'majutsushi/tagbar'Use :PlugInstall to install tagbar.
Open your code and use :TarbarToggle to toggle the tagbar window. You should
be able to see the tagbar window with all your classes, methods and variables.

In the above image, the window on the right is the tagbar window.
If you frequently use tagbar, you should consider adding a shortcut for this command like the following:
nnoremap <silent> <C-K><C-T> :TagbarToggle<CR>Tagbar also provides some shortcut for tag operation. Place the cursor on some tags in the tagbar window:
<Enter>: go to the line in the code where the tag occur, the cursor will be in the source codep: Like the <Enter> key, except that the cursor is still in tagbar windowq: quit the tagbar window此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。