Take the 2-minute tour ×

Is there a plugin or script to open ctags entries in a new tab? I'd like to put my cursor over a function, press ctrl+] and have the entry open in another tab. I'd also like if I visually select an entry, for ctrl+] to still work and open in a new vim tab.

share|improve this question
possible duplicate of Opening (c)tags in new tab in (G)Vim –  richq May 20 '11 at 14:03
@richq I tried the top voted solution in my .vimrc and it didn't do anything when pressing ctrl+\. –  Paul Tarjan May 23 '11 at 2:29
fair enough, I should have used stackoverflow.com/questions/539231 as the dupe, as that does contain sehe's answer too. I wonder if <C-\> works for anything? It mixes Control and <Leader> and probably just confuses vim. –  richq May 23 '11 at 7:00
I use <C-\> to toggle NERDTree. You can totally map <C-\> :) –  sidewaysmilk Jun 10 at 22:49
add comment

3 Answers

up vote 27 down vote accepted

You can


To achieve that effect

Then you can also map that:

:nnoremap <silent><Leader><C-]> <C-w><C-]><C-w>T

Edit: also, depending on what you actually want, don't forget you can open tags in preview (:ptag) with e.g. C-w}. Just mentioning it in case...

share|improve this answer
Upvote, but the mapping should be :nnoremap <silent><Leader><C-]> <C-w><C-]><C-w>T –  Walter May 20 '11 at 11:01
sadly, if the tag operation halts for any reason, this doesn't work. For example, if there are multiple tags and I have to pick between them. Any solution? –  Paul Tarjan Jun 7 '11 at 7:32
@uɐɾɹɐʇ ןnɐd: that will depend on your definition of <C-w><C-]> - with me it appears to always jump to the tag with highest prio without asking (as documented). Perhaps you have interfering mappings, see :verbose map <C-w>, :verbose imap <C-w> etc –  sehe Jun 7 '11 at 9:24
It breaks when the tag jump fails for some reason or another. Maybe there are multiple files I have to choose from, or the file is open in another buffer. Any ideas how to deal with that? –  Paul Tarjan Jul 10 '11 at 7:34
@uɐɾɹɐʇ ןnɐd: what I said in my previous comment... docs; Did you try mapping ex commands, instead of normal mode commands? You could use :stag! instead, or even :silent! stag!. Tip: Sneak in ex commands in a insert mode mapping using <C-o> –  sehe Jul 10 '11 at 23:08
add comment

Here are two pretty ad-hoc mappings (in case your tags are generated by ctags):

nnoremap <C-]> :tabnew %<CR>g<C-]>
vnoremap <C-]> <Esc>:tabnew %<CR>gvg<C-]>

First we open current buffer in a new tab; then we try to jump to a tag under cursor (g<C-]>, which is equal to :tjump, jumps to the tag directly if there's only one match, or provides a list of matches if there are many).



  • if you exit from list of matches without choosing any of them, the newly created tab will remain open
  • the same happens if there are no matches at all

P.S. Could you provide a use case for visual mode mapping?

P.P.S. If you generate tags with cscope (which is better than ctags) and use its vim mappings, replace the above mappings with the following ones:

nnoremap <C-]> :tabnew %<CR><C-]>
vnoremap <C-]> <Esc>tabnew %<CR>gv<C-]>
share|improve this answer
For visual mode mapping, our codebase has some classes in them named foo:bar:baz but my ctags breaks on : since I don't want to select foo::bar as one entity. So I usually go into visual mode over foo:bar:baz to jump to it. –  Paul Tarjan Jul 30 '11 at 5:08
I see. So have these mappings helped? The commands used in them are pretty general, so hopefully they work everywhere without conflicts. –  dorserg Aug 2 '11 at 12:23
add comment

In case somebody is still looking for a solution. On this solution when no tag is found no more blank tab will be left.

function! w:GoToTag(tagWord)

    let l:tagfile = &tags
    execute 'set tags=' . l:tagfile
    execute ':silent tjump ' . a:tagWord

    let l:tagFilename = expand('%:t')

    if l:tagFilename == ''
share|improve this answer
add comment

Your Answer


