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.
Opening a tab Probably the easiest to remember is to run the :tabnew command while in normal mode. This will open a new tab with an empty buffer. If you want to edit a file in the new tab, you can run :tabnew filename and Vim will load the file in the new tab.
To switch to the next tab, use :tabn, and to switch to the previous tab, use :tabp (short for tabnext and tabprevious respectively). You can also jump over tabs by using :tabn 2, which will move to the second next tab. To jump to the first tab, use :tabr (tabrewind) and to jump to the last tab use :tabl (tablast).
To directly move to first tab or last tab, you can enter the following in command mode: :tabfirst or :tablast for first or last tab respectively. To move back and forth : :tabn for next tab and :tabp for previous tab. You can list all the open tabs using : :tabs. To open multiple files in tabs: $ vim -p source.
Ctrl-W w to switch between open windows, and Ctrl-W h (or j or k or l ) to navigate through open windows. Ctrl-W c to close the current window, and Ctrl-W o to close all windows except the current one. Starting vim with a -o or -O flag opens each file in its own split.
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:
Cons:
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-]>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With