vim: Open tag in new tab

You can

C-wC-]C-wT

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...


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).

Pros:

  • "works on my machine" ©

Cons:

  • 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-]>