【问题标题】:open taglist window only for c files仅为 c 文件打开 taglist 窗口
【发布时间】:2017-01-12 16:26:19
【问题描述】:

我只想为 C 文件打开 taglist 窗口

如果我在.vimrc 中输入以下命令,则会打开所有文件的窗口

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

【问题讨论】:

    标签: vim tags taglist


    【解决方案1】:

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

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

    :autocmd FileType c,cpp,h.py TlistOpen
    

    【讨论】:

    • 非常感谢您的回答。这可行,但还有另一个问题。如果我使用 vim-buffers 打开第二个 C 文件,那么它会切换 taglist 窗口。有没有办法检查它是否已经打开?
    • 哦,那就改用:TlistOpen吧。我虽然:Tlist 只打开,因为还有:TlistToggle。似乎假设是错误的......
    • 很好用!一个侧面问题。默认情况下,光标在 TList 窗口中,是否可以改为在打开的文件中?或者那是另一个问题? ;)
    • 使用TlistOpen | wincmd p;这会将光标发送回previous 窗口。
    • 在autocmd中,还是一般?输入时它对我有用。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-09
    • 1970-01-01
    • 2011-08-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多