How can I map Ctrl-TAB to something in Vim?

Viewed 33500

I'd like to map Ctrl-TAB to gt in Vim so that I can switch tabs with one keystroke.

I tried...

nmap <C-T> gt
nmap <C-Tab> gt
nmap <C-TAB> gt

That didn't work. How do you say "the tab key" in Vimese?

8 Answers

I use the mintty terminal in cygwin. This terminal has an option of using ctrl-tab to cycle between the various instances of cygwing or alternatively, you can use to go to the next or previous screen window (so ctrl-tab does the same as ctrl-a+n and s-ctrl-tab does the same as ctrl-a+p. This last behavior is very convenient in my opinion. Check

Using_Ctrl+Tab_to_switch_session_in_GNU_Screen

git-bash (mintty)

First, disable the Switch window option in Options > Keys. Then you can use the following maps.

Note: you cannot simply copy and paste these into your .vimrc. Instead, where ^[[1;6I is, you need to press Ctrl-V while in insert mode and then type Ctrl-Shift-Tab. The same goes for ^[[1;5I and Ctrl-Tab.

nnoremap ^[[1;6I :tabprevious<CR>
nnoremap ^[[1;5I :tabnext<CR>
inoremap ^[[1;6I <Esc>:tabprevious<CR>
inoremap ^[[1;5I <Esc>:tabnext<CR>

I got this working with Konsole 19.12.3. Here's how:

  1. Menu-bar -> Settings -> Configure Keyboard Shortcuts
  2. Delete the existing keybinds for Ctrl+Shift+Tab and Ctrl+Tab by binding them to "None"
  3. Menu-bar -> Settings -> Profiles -> Edit -> Keyboard -> Edit
  4. Bind Backtab+Ctrl+Ansi (or probably just Backtab+Ctrl-Ansi if you have a non-ANSI keyboard) to \E[27;6;9~. Use the test area to confirm that the binding is working; it should echo the sequence above. Delete any binding that conflicts with it.
  5. Bind Tab+Ctrl+Ansi (or non-ANSI equivalent) to \E[27;5;9~.
  6. In your .vimrc add your bindings in the form of: nnoremap <C-Tab> :tabn<CR> and nnoremap <C-S-Tab> :tabp<CR>
Related