📄 taglist.vim
字号:
silent! setlocal noswapfile " Due to a bug in Vim 6.0, the winbufnr() function fails for unlisted " buffers. So if the taglist buffer is unlisted, multiple taglist " windows will be opened. This bug is fixed in Vim 6.1 and above if v:version >= 601 silent! setlocal nobuflisted endif endif silent! setlocal nowrap " If the 'number' option is set in the source window, it will affect the " taglist window. So forcefully disable 'number' option for the taglist " window silent! setlocal nonumber " Use fixed height when horizontally split window is used if g:Tlist_Use_Horiz_Window if v:version >= 602 set winfixheight endif endif if !g:Tlist_Use_Horiz_Window && v:version >= 700 set winfixwidth endif " Setup balloon evaluation to display tag prototype if v:version >= 700 && has('balloon_eval') setlocal balloonexpr=Tlist_Ballon_Expr() set ballooneval endif " Setup the cpoptions properly for the maps to work let old_cpoptions = &cpoptions set cpoptions&vim " Create buffer local mappings for jumping to the tags and sorting the list nnoremap <buffer> <silent> <CR> :call <SID>Tlist_Window_Jump_To_Tag(0)<CR> nnoremap <buffer> <silent> o :call <SID>Tlist_Window_Jump_To_Tag(1)<CR> nnoremap <buffer> <silent> p :call <SID>Tlist_Window_Jump_To_Tag(2)<CR> nnoremap <buffer> <silent> <2-LeftMouse> :call <SID>Tlist_Window_Jump_To_Tag(0)<CR> nnoremap <buffer> <silent> s \ :call <SID>Tlist_Change_Sort('cmd', 'toggle', '')<CR> nnoremap <buffer> <silent> + :silent! foldopen<CR> nnoremap <buffer> <silent> - :silent! foldclose<CR> nnoremap <buffer> <silent> * :silent! %foldopen!<CR> nnoremap <buffer> <silent> = :silent! %foldclose<CR> nnoremap <buffer> <silent> <kPlus> :silent! foldopen<CR> nnoremap <buffer> <silent> <kMinus> :silent! foldclose<CR> nnoremap <buffer> <silent> <kMultiply> :silent! %foldopen!<CR> nnoremap <buffer> <silent> <Space> :call <SID>Tlist_Window_Show_Info()<CR> nnoremap <buffer> <silent> u :call <SID>Tlist_Window_Update_File()<CR> nnoremap <buffer> <silent> d :call <SID>Tlist_Remove_File(-1, 1)<CR> nnoremap <buffer> <silent> x :call <SID>Tlist_Window_Zoom()<CR> nnoremap <buffer> <silent> [[ :call <SID>Tlist_Window_Move_To_File(-1)<CR> nnoremap <buffer> <silent> <BS> :call <SID>Tlist_Window_Move_To_File(-1)<CR> nnoremap <buffer> <silent> ]] :call <SID>Tlist_Window_Move_To_File(1)<CR> nnoremap <buffer> <silent> <Tab> :call <SID>Tlist_Window_Move_To_File(1)<CR> nnoremap <buffer> <silent> <F1> :call <SID>Tlist_Window_Toggle_Help_Text()<CR> nnoremap <buffer> <silent> q :close<CR> " Insert mode mappings inoremap <buffer> <silent> <CR> <C-o>:call <SID>Tlist_Window_Jump_To_Tag(0)<CR> " Windows needs return inoremap <buffer> <silent> <Return> <C-o>:call <SID>Tlist_Window_Jump_To_Tag(0)<CR> inoremap <buffer> <silent> o <C-o>:call <SID>Tlist_Window_Jump_To_Tag(1)<CR> inoremap <buffer> <silent> p <C-o>:call <SID>Tlist_Window_Jump_To_Tag(2)<CR> inoremap <buffer> <silent> <2-LeftMouse> <C-o>:call \ <SID>Tlist_Window_Jump_To_Tag(0)<CR> inoremap <buffer> <silent> s \ <C-o>:call <SID>Tlist_Change_Sort('cmd', 'toggle', '')<CR> inoremap <buffer> <silent> + <C-o>:silent! foldopen<CR> inoremap <buffer> <silent> - <C-o>:silent! foldclose<CR> inoremap <buffer> <silent> * <C-o>:silent! %foldopen!<CR> inoremap <buffer> <silent> = <C-o>:silent! %foldclose<CR> inoremap <buffer> <silent> <kPlus> <C-o>:silent! foldopen<CR> inoremap <buffer> <silent> <kMinus> <C-o>:silent! foldclose<CR> inoremap <buffer> <silent> <kMultiply> <C-o>:silent! %foldopen!<CR> inoremap <buffer> <silent> <Space> <C-o>:call \ <SID>Tlist_Window_Show_Info()<CR> inoremap <buffer> <silent> u \ <C-o>:call <SID>Tlist_Window_Update_File()<CR> inoremap <buffer> <silent> d <C-o>:call <SID>Tlist_Remove_File(-1, 1)<CR> inoremap <buffer> <silent> x <C-o>:call <SID>Tlist_Window_Zoom()<CR> inoremap <buffer> <silent> [[ <C-o>:call <SID>Tlist_Window_Move_To_File(-1)<CR> inoremap <buffer> <silent> <BS> <C-o>:call <SID>Tlist_Window_Move_To_File(-1)<CR> inoremap <buffer> <silent> ]] <C-o>:call <SID>Tlist_Window_Move_To_File(1)<CR> inoremap <buffer> <silent> <Tab> <C-o>:call <SID>Tlist_Window_Move_To_File(1)<CR> inoremap <buffer> <silent> <F1> <C-o>:call <SID>Tlist_Window_Toggle_Help_Text()<CR> inoremap <buffer> <silent> q <C-o>:close<CR> " Map single left mouse click if the user wants this functionality if g:Tlist_Use_SingleClick == 1 " Contributed by Bindu Wavell " attempt to perform single click mapping, it would be much " nicer if we could nnoremap <buffer> ... however vim does " not fire the <buffer> <leftmouse> when you use the mouse " to enter a buffer. let clickmap = ':if bufname("%") =~ "__Tag_List__" <bar> ' . \ 'call <SID>Tlist_Window_Jump_To_Tag(0) <bar> endif <CR>' if maparg('<leftmouse>', 'n') == '' " no mapping for leftmouse exe ':nnoremap <silent> <leftmouse> <leftmouse>' . clickmap else " we have a mapping let mapcmd = ':nnoremap <silent> <leftmouse> <leftmouse>' let mapcmd = mapcmd . substitute(substitute( \ maparg('<leftmouse>', 'n'), '|', '<bar>', 'g'), \ '\c^<leftmouse>', '', '') let mapcmd = mapcmd . clickmap exe mapcmd endif endif " Define the taglist autocommands augroup TagListAutoCmds autocmd! " Display the tag prototype for the tag under the cursor. autocmd CursorHold __Tag_List__ call s:Tlist_Window_Show_Info() " Highlight the current tag periodically autocmd CursorHold * silent call s:Tlist_Window_Highlight_Tag( \ fnamemodify(bufname('%'), ':p'), line('.'), 1, 0) " Adjust the Vim window width when taglist window is closed autocmd BufUnload __Tag_List__ call s:Tlist_Post_Close_Cleanup() " Close the fold for this buffer when leaving the buffer if g:Tlist_File_Fold_Auto_Close autocmd BufEnter * silent \ call s:Tlist_Window_Open_File_Fold(expand('<afile>:p')) endif " Exit Vim itself if only the taglist window is present (optional) if g:Tlist_Exit_OnlyWindow autocmd BufEnter __Tag_List__ nested \ call s:Tlist_Window_Exit_Only_Window() endif if s:tlist_app_name != "winmanager" && \ !g:Tlist_Process_File_Always && \ (!has('gui_running') || !g:Tlist_Show_Menu) " Auto refresh the taglist window autocmd BufEnter * call s:Tlist_Refresh() endif if !g:Tlist_Use_Horiz_Window if v:version < 700 autocmd WinEnter * call s:Tlist_Window_Check_Width() endif endif augroup end " Restore the previous cpoptions settings let &cpoptions = old_cpoptionsendfunction" Tlist_Window_Refresh" Display the tags for all the files in the taglist windowfunction! s:Tlist_Window_Refresh() call s:Tlist_Log_Msg('Tlist_Window_Refresh()') " Set report option to a huge value to prevent informational messages " while deleting the lines let old_report = &report set report=99999 " Mark the buffer as modifiable setlocal modifiable " Delete the contents of the buffer to the black-hole register silent! %delete _ " As we have cleared the taglist window, mark all the files " as not visible let i = 0 while i < s:tlist_file_count let s:tlist_{i}_visible = 0 let i = i + 1 endwhile if g:Tlist_Compact_Format == 0 " Display help in non-compact mode call s:Tlist_Window_Display_Help() endif " Mark the buffer as not modifiable setlocal nomodifiable " Restore the report option let &report = old_report " If the tags for only one file should be displayed in the taglist " window, then no need to add the tags here. The bufenter autocommand " will add the tags for that file. if g:Tlist_Show_One_File return endif " List all the tags for the previously processed files " Do this only if taglist is configured to display tags for more than " one file. Otherwise, when Tlist_Show_One_File is configured, " tags for the wrong file will be displayed. let i = 0 while i < s:tlist_file_count call s:Tlist_Window_Refresh_File(s:tlist_{i}_filename, \ s:tlist_{i}_filetype) let i = i + 1 endwhile if g:Tlist_Auto_Update " Add and list the tags for all buffers in the Vim buffer list let i = 1 let last_bufnum = bufnr('$') while i <= last_bufnum if buflisted(i) let fname = fnamemodify(bufname(i), ':p') let ftype = s:Tlist_Get_Buffer_Filetype(i) " If the file doesn't support tag listing, skip it if !s:Tlist_Skip_File(fname, ftype) call s:Tlist_Window_Refresh_File(fname, ftype) endif endif let i = i + 1 endwhile endif " If Tlist_File_Fold_Auto_Close option is set, then close all the folds if g:Tlist_File_Fold_Auto_Close " Close all the folds silent! %foldclose endif " Move the cursor to the top of the taglist window normal! ggendfunction" Tlist_Post_Close_Cleanup()" Close the taglist window and adjust the Vim window widthfunction! s:Tlist_Post_Close_Cleanup() call s:Tlist_Log_Msg('Tlist_Post_Close_Cleanup()') " Mark all the files as not visible let i = 0 while i < s:tlist_file_count let s:tlist_{i}_visible = 0 let i = i + 1 endwhile " Remove the taglist autocommands silent! autocmd! TagListAutoCmds " Clear all the highlights match none silent! syntax clear TagListTitle silent! syntax clear TagListComment silent! syntax clear TagListTagScope " Remove the left mouse click mapping if it was setup initially if g:Tlist_Use_SingleClick if hasmapto('<LeftMouse>') nunmap <LeftMouse> endif endif if s:tlist_app_name != "winmanager" if g:Tlist_Use_Horiz_Window || g:Tlist_Inc_Winwidth == 0 || \ s:tlist_winsize_chgd != 1 || \ &columns < (80 + g:Tlist_WinWidth) " No need to adjust window width if using horizontally split taglist " window or if columns is less than 101 or if the user chose not to " adjust the window width else " If the user didn't manually move the window, then restore the window " position to the pre-taglist position if s:tlist_pre_winx != -1 && s:tlist_pre_winy != -1 && \ getwinposx() == s:tlist_winx && \ getwinposy() == s:tlist_winy exe 'winpos ' . s:tlist_pre_winx . ' ' . s:tlist_pre_winy endif " Adjust the Vim window width let &columns= &columns - (g:Tlist_WinWidth + 1) endif endif let s:tlist_winsize_chgd = -1 " Reset taglist state variables if s:tlist_app_name == "winmanager" let s:tlist_app_name = "none" endif let s:tlist_window_initialized = 0endfunction" Tlist_Window_Refresh_File()" List the tags defined in the specified file in a Vim windowfunction! s:Tlist_Window_Refresh_File(filename, ftype) call s:Tlist_Log_Msg('Tlist_Window_Refresh_File (' . a:filename . ')') " First check whether the file already exists let fidx = s:Tlist_Get_File_Index(a:filename) if fidx != -1 let file_listed = 1 else let file_listed = 0 endif if !file_listed " Check whether this file is removed based on user request " If it is, then don't display the tags for this file if s:Tlist_User_Removed_File(a:filename) return endif endif if file_listed && s:tlist_{fidx}_visible " Check whether the file tags are currently valid if s:tlist_{fidx}_valid " Goto the first line in the file exe s:tlist_{fidx}_start " If the line is inside a fold, open the fold if foldclosed('.') != -1 exe "silent! " . s:tlist_{fidx}_start . "," . \ s:tlist_{fidx}_end . "foldopen!" endif return endif " Discard and remove the tags for this file from display call s:Tlist_Discard_TagInfo(fidx) call s:Tlist_Window_Remove_File_From_Display(fidx) endif " Process and generate a list of tags defined in the file if !file_listed || !s:tlist_{fidx}_valid let ret_fidx = s:Tlist_Process_File(a:filename, a:ftype) if ret_fidx == -1 return endif let fidx = ret_fidx endif " Set report option to a huge value to prevent informational messages " while adding lines to the taglist window let old_report = &report set report=99999 if g:Tlist_Show_One_File " Remove the previous file if s:tlist_cur_file_idx != -1 call s:Tlist_Window_Remove_File_From_Display(s:tlist_cur_file_idx) let s:tlist_{s:tlist_cur_file_idx}_visible = 0 let s:tlist_{s:tlist_cur_file_idx}_start = 0 let s:tlist_{s:tlist_cur_file_idx}_end = 0 endif let s:tlist_cur_file_idx = fidx endif " Mark the buffer as modifiable setlocal modifiable " Add new files to the end of the window. For existing files, add them at " the same line where they were previously present. If the file is not " visible, then add it at the end if s:tlist_{fidx}_start == 0 || !s:tlist_{fidx}_visible if g:Tlist_Compact_Format let s:tlist_{fidx}_start = line('$') else let s:tlist_{fidx}_start = line('$') + 1 endif endif let s:tlist_{fidx}_visible = 1 " Goto the line where this file should be placed if g:Tlist_Compact_Format exe s:tlist_{fidx}_start else exe s:tlist_{fidx}_start - 1 endif let txt = fnamemodify(s:tlist_{fidx}_filename, ':t') . ' (' .
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -