vimtagstaglist

open taglist window only for c files


I want to open the taglist window only specifically for the C files

If I put the following command in my .vimrc then the window opens for all the files

let Tlist_Auto_Open=1

However, when I used autocmd based on filetype, it does not open. Is there any kind of dependency that I need to check for ?

autocmd FileType c,cpp,h,py let Tlist_Auto_Open=1

A part of my .vimrc looks like below -

" Install pathogen
execute pathogen#infect()  

set number                      " Display Line Numbers         
set autoindent                  " Auto-indenting               
set showmatch                   " Highlight Matching brackets  
set tabstop=4                   " Default tabstop value        
set shiftwidth=4
set smarttab                    " Enable smart tab             
set hlsearch                    " highlight searched items     
set ignorecase                  " ignore case when searching   
set smartcase                   " ignore case if search pattern is all lowercase, case-sensitive otherwise
" set scrolloff=999             "Start scrolling when we're 8 lines away from margins

" No annoying sound on errors
set noerrorbells
set novisualbell
set timeoutlen=500

filetype plugin on
filetype plugin indent on
set ic 
autocmd filetype python set expandtab

" Remove the trailing white-spaces in the C-file
autocmd FileType c,cpp,h,py autocmd BufWritePre <buffer> %s/\s\+$//e

" Unmap the tab-key in the taglist window.
:autocmd BufEnter __Tag_List__ silent! nunmap <buffer> <Tab>

" Syntax higlight for Groovy
au BufRead,BufNewFile *.atc set filetype=groovy


""""""""""""""""""""""""""""""""""
" Taglist configuration
""""""""""""""""""""""""""""""""""
"
" To automatically close the tags tree for inactive files.
" let Tlist_File_Fold_Auto_Close = 1

" Display only one file in taglist.
let Tlist_Show_One_File = 1

" Taglist window size
let Tlist_WinWidth = 30

" Open Taglist by default
autocmd FileType c,cpp,h,py let Tlist_Auto_Open=1

" Close VIM when only taglist window is open
let Tlist_Exit_OnlyWindow = 1

Solution

  • This is a timing problem. The taglist plugin evaluates the Tlist_Auto_Open configuration during its load. At that point in time, your ~/.vimrc has been read, but no file has yet been opened. Your :autocmd only activates after such file has been :edited, and by then, the taglist initialization is over. Also, until you only edit one [type of] file in a Vim session, your approach would have resulted in all subsequent files opening the taglist!

    So, you cannot use the taglist-provided config feature, but fortunately it is very easy to implement an automatic triggering of the plugin via the :TlistOpen command. Just modify your autocmd to this:

    :autocmd FileType c,cpp,h.py TlistOpen