vim cant map <C-Tab> to :tabnext
Asked Answered
S

4

9

I have the following mappings in my .vimrc:

map <C-S-Tab> :tabprevious<CR>
nmap <C-S-Tab> :tabprevious<CR>
imap <C-S-Tab> <Esc>:tabprevious<CR>i

map <C-Tab> :tabnext<CR>
nmap <C-Tab> :tabnext<CR>
imap <C-Tab> <Esc>:tabnext<CR>i

I want to switch the tabs with Strg+Tab forward and with Strg+Shift+Tab backward. Why does this mapping not work?

Sidle answered 4/6, 2010 at 23:43 Comment(2)
Your mappings read correct, it's probably your terminal not forwarding the keys. Check the shell can even receive the ctrl-tab using "read" in bash. It will block for character input and show you what keystrokes are received. On my xterm, there is no difference between c-tab and c-s-tab. Read shows "^[[Z" for both. HTH.Baluchi
Why it doesn't work and how to make it work in Xterm.Mindamindanao
B
10

Are you using xterm? If so, you can't map ctrl-tab without a lot of hackery. xterm and many other terminal emulators don't recognise ctrl-tab and simply send a tab character.

See my answer here for more details: Mapping <C-Tab> in my vimrc fails in Ubuntu

Or you can just use gvim if that is suitable - it should work without any mucking around.

Bobbette answered 7/7, 2010 at 11:23 Comment(0)
D
1

Something is probably blocking vim from seeing the C-Tab. This could be your terminal or your window manager.

On some OSes/WMs you can set exceptions to the window manager shortcuts, but how you do this varies crazily between the WMs.

I'm not sure if there is a solution if it is your terminal blocking the key presses.

Dumm answered 5/6, 2010 at 3:54 Comment(1)
The window manager is not the problem. If I switch to a tty-terminal without X11/GUI, the binding still does not work. I use Ubuntu 9.04.Sidle
S
0

oh ... is it need to be mapped? just use this predefined combos:

  • gt: == :tabnext

  • gT: == :tabprevious

  • [n]gt: == jump to N tab , e.g. 1gt , 3gt

defining to many short keys is easy, but how can you remember all of them and don't mixing them up with 'ctrl + tab' , 'alt + tab' ( common and usual short keys in most OS )

check this page for more details : http://vim.wikia.com/wiki/Alternative_tab_navigation

Spokane answered 11/1, 2013 at 6:55 Comment(0)
L
0

All you need is xterm.

Put this in your .Xresources file (you can copy-paste in this case):

xterm*VT100.Translations: #override \
             Ctrl ~Shift <Key>Tab: string(0x1b) string("[27;5;9~") \n\
             Ctrl Shift <Key>Tab: string(0x1b) string("[27;6;9~")

Then do cd ; xrdb .Xresources and restart xterm.


Put this in your .vimrc:

!! Important - instead of XXXX you must type CTRL-V and then Esc OR copy-paste the whole text and run %s/\(set <F1[34]>=\)XXXX/\=submatch(1) . "\33"/g which is copy-pastable (insert it with <CTRL-R> +).

set timeout timeoutlen=1000 ttimeoutlen=100
set <F13>=XXXX[27;5;9~
nnoremap <F13> gt
set <F14>=XXXX[27;6;9~
nnoremap <F14> gT

And restart vim.

Done.

Litchfield answered 12/8, 2015 at 7:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.