Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
881 views
in Technique[技术] by (71.8m points)

vim - Mapping <C-Tab> in my vimrc fails in Ubuntu

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 and fluxbox installed on top. I'm using xterm 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 for ctrl-tab. See my full answer below for details.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.8k users

...