2

I'm using ctags to code C++ with vim.

I set two shortcuts of ctags as below:

autocmd VimEnter * silent! !eval 'ctags -R --c++-kinds=+p --fields=+iaS --extras=+q --language-force=C++ -o newtags; mv newtags .tags' &
function! Jump(type)
    if filereadable(".tags")
        if a:type == "single"
            execute "normal! 2\<C-]>"
            execute "normal :NERDTreeFind\<CR>"
            execute "normal :wincmd p\<CR>"
        else
            execute "normal! g\<C-]>"
            "execute "normal :redraw!"
        endif
    else
        execute "normal :echo 'tags file not ready'\<CR>"
    endif
endfunction
nnoremap <C-]> :call Jump('single')<CR>
nnoremap g<C-]> :call Jump('multi')<CR>

As the autocmd command may need some time to finish, I write a function Jump.

For now, everything works well except that I always get a Press ENTER or type command to continue after typing g<C-]>.

I've tried to add execute "normal :redraw!" but it doesn't seem to work...

Also, I cannot use silent too, because g<C-]> has some necessary output: enter image description here

If I use silent, all the output above will disappear.

  • And you press the number on the output of g<C] and then get the "Press ENTER..." prompt? – Ralf Jan 15 at 11:55
  • @Ralf No, I simply press g<C] and then get that. I cannot understand because execute "normal :redraw!" works on my Mac OS but doesn't work on my ubuntu. – Yves Jan 15 at 12:14
3

Could you try the following. It directly uses :tag and :tjump instead of using the mappings. I also removed the unneeded execute ... stuff.

function! Jump(type)
    if filereadable(".tags")
        if a:type == "single"
            execute "tag " . expand("<cword>")
            NERDTreeFind
            wincmd p
        else
            execute "tjump " . expand("<cword>")
        endif
    else
        echo 'tags file not ready'
    endif
endfunction
  • Wonderful! It works. – Yves Jan 15 at 12:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.