书可以在同步路径时处理符号链接



我正在使用ctags生成标签并将set tags+=~/.vim/tags/cpp(刚刚关注此维基页面)放入.vimrc。在我的vimrc文件中,还有如下所示的设置,因此我可以自动同步当前文件的nerdtree查看器(请参阅此内容):

" returns true iff is NERDTree open/active
function! rc:isNTOpen()        
  return exists("t:NERDTreeBufName") && (bufwinnr(t:NERDTreeBufName) != -1)
endfunction
" returns true iff focused window is NERDTree window
function! rc:isNTFocused()     
  return -1 != match(expand('%'), 'NERD_Tree') 
endfunction 
" calls NERDTreeFind iff NERDTree is active, current window contains a modifiable file, and we're not in vimdiff
function! rc:syncTree()
  if &modifiable && rc:isNTOpen() && !rc:isNTFocused() && strlen(expand('%')) > 0 && !&diff
    NERDTreeFind
    wincmd p
  endif
endfunction
autocmd BufEnter * call rc:syncTree()

问题在于~/.vim实际上是指向另一个文件夹的符号链接(所以我可以使用 git 或其他 VCS 轻松管理我所有的点文件)。当我使用 Ctrl+] 查找定义(其标签信息在 ~/.vim/tags/cpp 中)时,总是会出现错误:

detected while processing function rc:syncTree..<SNR>15_findAndRevealPath..102:
line    2:
E605: Exception not caught: NERDTree.InvalidArgumentsError: /home/hongxuchen/.vim/tags/cpp_src/stl_iterator.h should be under /home/hongxuchen/data_backup/dotfiles/_vim/tags/cpp_src

这是否意味着我必须在vimrc中使用set tags+=/real/path/to/cpp

在 Vim 中,resolve() 函数可以处理符号链接。尝试在plugin/NERD_tree.vim中更换

function! s:findAndRevealPath()
    try
        let p = s:Path.New(expand("%:p"))

function! s:findAndRevealPath()
    try
        let p = s:Path.New(resolve(expand("%:p")))

如果可行,我会向插件的作者发送补丁。

虽然严格来说这不是您问题的答案,但我的回答肯定会帮助您解决潜在的问题。

我在~/.vim/vimrc中将我的"真实"vimrc置于版本控制之下,~/.vimrc不是符号链接,因为我讨厌符号链接。相反,~/.vimrc是一个只有一行的常规文件:

runtime vimrc

最新更新