Question

I am using ctags to generate tags and put set tags+=~/.vim/tags/cpp(just followed this wiki page) in .vimrc.In my vimrc file there is also the setting like below so I can auto sync the nerdtree viewer for the current file(see this):

" 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()

The problem lies in that ~/.vim is actually a symbolic link to another folder(So I can manage all my dotfiles using git or other VCSs easily). When I use Ctrl+] to look for a definition(whose tag information is in ~/.vim/tags/cpp), there would be always the error:

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

Does it mean that I have to use set tags+=/real/path/to/cpp instead in vimrc?

Was it helpful?

Solution

In Vim, the resolve() function can process symbolic links. Try replacing in plugin/NERD_tree.vim

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

with

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

If that works, I'd send a patch to the plugin's author.

OTHER TIPS

While it is not strictly an answer to your question, my answer will certainly help fix your underlying problem.

I have my "real" vimrc under version control in ~/.vim/vimrc and ~/.vimrc is not a symlink because I hate symlinks. Instead, ~/.vimrc is a regular file with only one line:

runtime vimrc
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top