open taglist window only for c files

open taglist window only for c files

我想打开 taglist window 只针对 C 文件

如果我在我的 .vimrc 中输入以下命令,那么 window 会为所有文件打开

let Tlist_Auto_Open=1

但是,当我根据文件类型使用autocmd时,它打不开。我需要检查任何类型的依赖关系吗?

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

我的 .vimrc 的一部分如下所示 -

" 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

这是一个计时问题。 taglist 插件在加载期间评估 Tlist_Auto_Open 配置。那时,您的 ~/.vimrc 已被读取,但尚未打开任何文件。您的 :autocmd 只有在 :edit 编辑了此类文件后才会激活,到那时,taglist 初始化就结束了。此外,除非您在 Vim 会话中只编辑一个 [类型] 文件,否则您的方法将导致 所有 个后续文件打开标签列表!

因此,您不能使用 taglist-provided 配置功能,但幸运的是,通过 :TlistOpen 命令可以很容易地实现插件的自动触发。只需将您的 autocmd 修改为:

:autocmd FileType c,cpp,h.py TlistOpen