Mapping <C-Tab> in my vimrc fails in Ubuntu
Solution 1
It's definitely a terminal issue.
Apparently xterm, and lots of other terminal emulators, don't intercept ctrl-tab by default and just send a tab signal. This Vim wiki page states that ctrl-tab doesn't work for xterm, Eterm, and aterm. There's also this Arch linux form post claiming that it's a terminal issue.
The solution can be found by combining the info from this blog post with this vim wiki for mapping keycodes. This gist of it is that you need to configure xterm to intercept and send a unique code for ctrl-tab and ctrl-shift-tab in your .Xresources
file, then hack that into your .vimrc
with some funky mappings.
Long story short is that it's hard to do (still haven't got it working here) because xterm and vim both need to be tricked into doing it. I'm personally gonna move on and use another mapping... this issue is a serious time sucker and I don't think it's worth pressing on to get it working!
Thanks for the help guys.
Solution 2
I used the blog and wiki posts from @nfm's answer and solved it:
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.
Related videos on Youtube
Charles Enrick Cajan
Updated on March 06, 2020Comments
-
Charles Enrick Cajan about 4 years
I want to map ctrl-tab to :tabn, and ctrl-shift-tab to :tabp.
I had it working for gVim in Windows XP, but moved it to my .vimrc in Ubuntu 9.10 and it doesn't work (vim 7.2).
Here's the relevant section of my .vimrc:
nmap <C-Tab> :tabn<CR> nmap <C-S-Tab> :tabp<CR> nmap <C-t> :tabnew<CR>
<C-t>
works fine, so mapping the ctrl key doesn't seem to be a problem. I really have no idea where to start! What could be going wrong here, considering it worked fine under Windows?More info: I'm running Ubuntu 9.10 server, with
xorg
andfluxbox
installed on top. I'm usingxterm
as my terminal.Ctrl-tab mapping works in fluxbox: I can map ctrl-tab and ctrl-shift-tab successfully in my window manager; if I start tabbing my xterms, I can cycle through those tabs as expected. I'm not sure what this means, but I think the issue is not a window manager/xorg issue.
The keys don't seem to be mapped to something else, and can be recognised together successfully.
Answer: It's an
xterm
issue - it doesn't intercept and send a unique keycode forctrl-tab
. See my full answer below for details.-
Cascabel about 14 yearsDoes C-Tab possibly have special meaning for your terminal?
-
Charles Enrick Cajan about 14 yearsPossibly... I'll look into it. I'm running xterm.
-
Quasímodo about 3 yearsFor a detailed Xterm solution to disambiguate Ctrl-I, Tab, Ctrl-Tab, etc. have a look at unix.stackexchange.com/q/631241
-
-
Charles Enrick Cajan about 14 yearsMore info: I'm running Ubuntu server with xorg installed and fluxbox as my window manager
-
Faktor 10 about 9 yearsIf you want as an interim try the solution in superuser.com/questions/410982/… . This uses the key combination of gt or gT which seems to work through a terminal
-
wukong almost 9 yearswhat the alternative terminals could resolve this issue?
-
statquant about 8 years@wukong that's also what I am thinking, I see that tmux should be configured with
screen-256color
anyway, so can we have this working with some other terminal ? -
MichalH about 8 years@statquant it works perfectly for me. Can you write what part exactly is not working for you?
-
statquant about 8 yearsI can't switch tabs with this, I copied the
.Xresources
file with those tabulations, thencd; xrdb .Xresources
then updated the.vimrc
using the change fromXXXX
to^[
with your line restarted all terminals and vim... that's not working -
MichalH about 8 yearsThen I'm sorry, we probably have different versions and something isn't supported at yours, or something interrupts these settings.
-
Pierre almost 8 yearsWorked for me, thanks. Except that I needed to map <C-Tab> to vim windows navigation. All I had to do was to change the map of F13 and F14 in my .vimrc: map <F13> <C-w><C-w> map <F14> <C-w><S-w> Hope it helps someone.