September 10, 2018

The Vim "taglist" plugin

TagList is the top rated and most often downloaded vim plugin. Or so it claims on the old Taglist page on Sourceforge.

This plugin has not been maintained since about 2013. That could be good or bad.

Note below that I map "F5" to toggle the taglist on and off, and I move it to the right side to allow the NERDtree plugin to use the left side. Having a command to just "open" the taglist is sort of useless and academic.

You can set a variable so that the taglist window comes up automatically each time you start vim. There are a bunch of variables you can set in your .vimrc to control the behavior of taglist. Here is a set that one guy suggests.

" TagList options
let Tlist_Close_On_Select = 1 "close taglist window once we selected something
let Tlist_Exit_OnlyWindow = 1 "if taglist window is the only window left, exit vim
let Tlist_Show_Menu = 1 "show Tags menu in gvim
let Tlist_Show_One_File = 1 "show tags of only one file
let Tlist_GainFocus_On_ToggleOpen = 1 "automatically switch to taglist window
let Tlist_Highlight_Tag_On_BufEnter = 1 "highlight current tag in taglist window
let Tlist_Process_File_Always = 1 "even without taglist window, create tags file, required for displaying tag in statusline
let Tlist_Use_Right_Window = 1 "display taglist window on the right
let Tlist_Display_Prototype = 1 "display full prototype instead of just function name
"let Tlist_Ctags_Cmd = /path/to/exuberant/ctags

nnoremap <F5> :TlistToggle<CR>
nnoremap <F6> :TlistShowPrototype

set statusline=[%n]\ %<%f\ %([%1*%M%*%R%Y]%)\ \ \ [%{Tlist_Get_Tagname_By_Line()}]\ %=%-19(\LINE\ [%l/%L]\ COL\ [%02c%03V]%)\ %P
In particular note the mapping for F5. There is no way I am going to use taglist if I have to type :TlistToggle every time.

Putting the "CR" on the end makes it happen with one keystroke, which is just what I want. Also the "GainFocus" option gives sane behavior.

To use this effectively, you need a trick to move focus between windows. Apparently (Ctrl-w)w moves to the "other" window, which is kind of hard to remember, but gets the job done. Also note that the usual vim "hjkl" motions work along with (Crtl-w) to move among windows.


Feedback? Questions? Drop me a line!

Tom's Computer Info / tom@mmto.org