映射我的 vimrc 在 Ubuntu 中失败

发布于 2024-08-30 10:58:18 字数 845 浏览 1 评论 0 原文

我想将 ctrl-tab 映射到 :tabn,将 ctrl-shift-tab 映射到 :tabp。

我让它在 Windows XP 中适用于 gVim,但将其移至 Ubuntu 9.10 中的 .vimrc 中,但它不起作用(vim 7.2)。

这是我的 .vimrc 的相关部分:

nmap <C-Tab> :tabn<CR>
nmap <C-S-Tab> :tabp<CR>
nmap <C-t> :tabnew<CR>

工作正常,因此映射 ctrl 键似乎不是问题。我真的不知道从哪里开始!考虑到它在 Windows 下运行良好,这里可能出了什么问题?

更多信息:我正在运行 Ubuntu 9.10 服务器,上面安装了 xorgfluxbox。我使用 xterm 作为我的终端。

Ctrl-tab 映射适用于 Fluxbox:可以在窗口管理器中成功映射 ctrl-tab 和 ctrl-shift-tab;如果我开始使用 xterms,我可以按预期循环浏览这些选项卡。我不确定这意味着什么,但我认为问题不是窗口管理器/xorg 问题。

这些按键似乎没有映射到其他东西,并且可以成功地一起识别。

回答:这是一个 xterm 问题 - 它不会拦截并发送 ctrl-tab 的唯一键码。有关详细信息,请参阅下面我的完整答案。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

等风来 2024-09-06 10:58:18

肯定是终端问题。

显然,xterm 和许多其他终端模拟器默认情况下不会拦截 ctrl-tab,而只是发送 Tab 信号。这个 Vim wiki 页面指出 ctrl-tab 不适用于 xterm、Eterm 和 aterm。还有这个 Arch linux 表单帖子 声称这是一个终端问题。

解决方案可以通过结合这篇博文 以及 vim wiki映射键码。其要点是,您需要配置 xterm 以拦截并发送 .Xresources 文件中 ctrl-tab 和 ctrl-shift-tab 的唯一代码,然后将其破解到您的 中。 vimrc 带有一些时髦的映射。

长话短说,这很难做到(仍然没有让它在这里工作),因为 xterm 和 vim 都需要被欺骗才能做到这一点。我个人将继续使用另一个映射...这个问题是一个严重的时间浪费,我认为不值得继续努力让它工作!

谢谢你们的帮助。

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.

揪着可爱 2024-09-06 10:58:18

我使用了 @nfm 的答案中的博客和 wiki 帖子并解决了它:

将其放入您的 .Xresources 文件中(在这种情况下您可以复制粘贴):

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~")

然后执行 cd ; xrdb .Xresources 并重新启动 xterm。


将其放入您的 .vimrc 中:

!!重要 - 您必须输入 CTRL-V,然后输入 Esc,而不是 XXXX 复制粘贴整个文本并运行 %s/\(设置 =\)XXXX/\=submatch(1) 。 “\33”/g 可复制粘贴(使用 + 插入)。

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

并重新启动vim。

完毕。

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.

清晨说晚安 2024-09-06 10:58:18

如果您使用 Ubuntu,您可能启用了 Compiz 之类的功能。

我不能确定,但​​您应该查看 Compiz 扩展以及其中是否定义了该快捷方式。我曾经遇到过类似的问题,不是用 vim,但仍然如此。

它也可能是 X 服务器拦截某些击键(例如:xbindkeys)。

If you're using Ubuntu, you probably have something like Compiz enabled.

I can't know for sure, but you should take a look at Compiz extensions and whether on of them defines that shortcut. I had a similar problem once, not with vim, but still.

It could also be the X server that intercepts some keystrokes (example: xbindkeys).

蓝海 2024-09-06 10:58:18

就我而言,
我在 rxvt-unicode(urxvt,v9.22)上解决如下,

terminal (.Xresource)
URxvt.keysym.Control-Tab: \033[27;5;9~ 

vim v8.0 (.vimrc) 
map <Esc>[27;5;9~ :tabnext<CR>

祝你好运!

In my case,
I solved on rxvt-unicode (urxvt, v9.22) as below,

terminal (.Xresource)
URxvt.keysym.Control-Tab: \033[27;5;9~ 

vim v8.0 (.vimrc) 
map <Esc>[27;5;9~ :tabnext<CR>

Good Luck!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文