Vim 配置ctags、winmanager、NERDTree、Taglist若干问题

时间:2023-02-06 17:23:16

Vim 配置遇到的一些问题


1. winmanager合并显示NERDTree和TagList 后自动开启 wm会出现空白窗口

" 修改plugin/winmanager.vim配置文件
function! <SID>ToggleWindowsManager()
if IsWinManagerVisible()
call s:CloseWindowsManager()
else
call s:StartWindowsManager()
exe 'q' "####添加此行
end
endfunction
"####添加如下内容
if g:AutoOpenWinManager
autocmd VimEnter * nested call s:ToggleWindowsManager()|3wincmd w
endif

网上流传的其他方法测试无效

比如 

"添加 
autocmd VimEnter * nested call s:StartWindowsManager()|1wincmd w|q
"或者修改
function! <SID>ToggleWindowsManager()
if IsWinManagerVisible()
call s:CloseWindowsManager()
else
call s:StartWindowsManager()
exe '1wincmd w'"###添加此行
exe 'q' "###添加此行
end
endfunction
总结:问题的关键是将StartWindowsManager()函数换成ToggleWindowsManager()


2.关于ctag插件 总是 提示“E426:找不到 tag:xxxx”
添加如下配置即可

map <leader>cd  :cd %:p:h<cr>
map <Leader>tag <leader>cd:!ctags -R<cr> "使用\tag命令在程序目录生成tags文件
set tags=tags;

附:

我的VIM配置文件

set nocompatible
source $VIMRUNTIME/vimrc_example.vim
source $VIMRUNTIME/mswin.vim
behave mswin

set diffexpr=MyDiff()
function MyDiff()
let opt = '-a --binary '
if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif
if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif
let arg1 = v:fname_in
if arg1 =~ ' ' | let arg1 = '"' . arg1 . '"' | endif
let arg2 = v:fname_new
if arg2 =~ ' ' | let arg2 = '"' . arg2 . '"' | endif
let arg3 = v:fname_out
if arg3 =~ ' ' | let arg3 = '"' . arg3 . '"' | endif
let eq = ''
if $VIMRUNTIME =~ ' '
if &sh =~ '\<cmd'
let cmd = '""' . $VIMRUNTIME . '\diff"'
let eq = '"'
else
let cmd = substitute($VIMRUNTIME, ' ', '" ', '') . '\diff"'
endif
else
let cmd = $VIMRUNTIME . '\diff'
endif
silent execute '!' . cmd . ' ' . opt . arg1 . ' ' . arg2 . ' > ' . arg3 . eq
endfunction

set expandtab "设置tab
set shiftwidth=4 "设置tab的间隔
set tabstop=4 "四个空格代表一个tab
set sts=4
set showmatch "在输入括号时光标会短暂地跳到与之相匹配的括号处
set autoindent "设置自动缩进
" set smartindent "设置智能缩进
set nowrap "设置自动换行


colorscheme desert " 主题设置
set number " 显示行号
set guifont=Courier_new:h13:b:cDEFAULT " 设置字体大小
set helplang=cn " 帮助中文支持
syntax enable
syntax on

"ctags 配置
set autochdir
map <leader>cd :cd %:p:h<cr>
map <Leader>tag <leader>cd:!ctags -R<cr>
set tags=tags;


" taglist 配置
let Tlist_Show_One_File=1
let Tlist_Exit_OnlyWindow=1
let Tlist_Use_Right_Window=1 "让窗口显示在右边,0的话就是显示在左边
map <F3> :TlistToggle<CR>

" winmanager配置
"let g:winManagerWindowLayout='TagList|FileExplorer'
let g:winManagerWindowLayout='NERDTree|TagList'
nmap <silent> <F8> :WMToggle<cr>
let g:winManagerWidth = 30
let g:AutoOpenWinManager =1
map wm :WMToggle<cr>

"NERDTree 配置
let g:NERDTree_title="[NERDTree]"
function! NERDTree_Start()
exec 'NERDTree'
endfunction
function! NERDTree_IsValid()
return 1
endfunction

"编码相关
set fileencodings=ucs-bom,utf-8,cp936,gb18030,big5,euc-jp,euc-kr,latin1
set fileencoding=utf-8
set encoding=gbk
"set termencoding=gbk
"set gfn=Monaco:h10:cANSI
"set gfw=NSimsun:h12

set nocp
filetype plugin on