如何让Ctrl-Backspace在gnome-terminal中删除vim中的单词?

时间:2022-03-02 07:31:30

I'd like Ctrl-Backspace to delete the current word in vim insert mode. From within xterm I can pull this off via

我想在Ctrl-Backspace中删除vim插入模式下的当前单词。从xterm内部我可以通过它来解决这个问题

:inoremap <C-H> <C-W>

but in gnome-terminal I cannot figure out a way to make it happen.

但在gnome-terminal中,我无法找到实现它的方法。

When in vim insert mode, if I type control-v and then press backspace, I get ^H in xterm, and ^? in gnome-terminal. Unfortunately,

当处于vim插入模式时,如果我键入control-v然后按退格键,我在xterm中得到^ H,而^?在gnome-terminal。不幸,

:inoremap <C-?> <C-W>

doesn't do the trick in gnome-terminal; control-backspace just erases a single character no matter what.

在gnome-terminal中没有做到这一点; control-backspace无论如何都会删除单个字符。

Regarding ASCII codes:

关于ASCII码:

Gnome-terminal lets you change the backspace character under Edit -> Profile Preferences -> Compatibility. Unfortunately, no option works, as far as I can tell: whatever character I apply to Backspace via the settings, if I try mapping the character itself, like

Gnome-terminal允许您更改编辑 - >配置文件首选项 - >兼容性下的退格字符。不幸的是,据我所知,没有选项可行:无论我通过设置应用于Backspace的任何字符,如果我尝试映射字符本身,就像

:inoremap <C-H> <C-W>

then regular backspace and control-backspace both erase an entire word; and if I try mapping control plus that character, like

然后定期退格和控制退格都擦除整个单词;如果我尝试映射控制加上那个角色,比如

:inoremap <C-^H> <C-W>

then regular backspace and control-backspace just erase a single character.

然后定期退格和控制退格只删除一个字符。

1 个解决方案

#1


10  

gnome-terminal's libvte would need to be patched.

gnome-terminal的libvte需要修补。

libvte already has several options to map backspace, none of which distinguish Ctrl-backspace. It needs an option that does, maybe one that follows the behaviour of the linux console (^? for backspace, ^H for Ctrl-backspace). See this gnome bug.

libvte已经有几个映射退格的选项,没有一个选项可以区分Ctrl-backspace。它需要一个选项,可能是一个遵循linux控制台行为的选项(^?表示退格键,^ H表示Ctrl-backspace)。看到这个gnome bug。


2015 update: this was fixed in 23c7cd0f99d504cbab06d4c27254d4f3e2807ba8.

2015年更新:这是在23c7cd0f99d504cbab06d4c27254d4f3e2807ba8中修复的。

libvte 0.41.90, 0.40.3 and newer have the fix.

libvte 0.41.90,0.40.3和更新有修复。

#1


10  

gnome-terminal's libvte would need to be patched.

gnome-terminal的libvte需要修补。

libvte already has several options to map backspace, none of which distinguish Ctrl-backspace. It needs an option that does, maybe one that follows the behaviour of the linux console (^? for backspace, ^H for Ctrl-backspace). See this gnome bug.

libvte已经有几个映射退格的选项,没有一个选项可以区分Ctrl-backspace。它需要一个选项,可能是一个遵循linux控制台行为的选项(^?表示退格键,^ H表示Ctrl-backspace)。看到这个gnome bug。


2015 update: this was fixed in 23c7cd0f99d504cbab06d4c27254d4f3e2807ba8.

2015年更新:这是在23c7cd0f99d504cbab06d4c27254d4f3e2807ba8中修复的。

libvte 0.41.90, 0.40.3 and newer have the fix.

libvte 0.41.90,0.40.3和更新有修复。