emacs - [控制上移] 不起作用
我尝试将热键定义如下,
(global-set-key [(control shift up)] 'other-window)
但它不起作用(没有错误,只是不起作用),
(global-set-key [(control shift down)] 'other-window)
但是
(global-set-key [(control shift right)] 'other-window)
和也
(global-set-key [(control shift left)] 'other-window)
不起作用!
但因为最后两个组合键由 emacs 使用(默认),我不想将它们更改为其他功能。
那么我怎样才能使 control-shift-up 和 control-shift-down 工作呢?
我用google搜索过“(control shift up)”,似乎control-shift-up被其他人使用,(但结果不是很少)。
I tried to define hotkey as following
(global-set-key [(control shift up)] 'other-window)
but it doesn't work (no error, just doesn't work), neither does
(global-set-key [(control shift down)] 'other-window)
But
(global-set-key [(control shift right)] 'other-window)
and
(global-set-key [(control shift left)] 'other-window)
work!
But because the last two key combinations are used by emacs (as default), I don't wanna change them for other functions.
So how could I make control-shift-up and control-shift-down work?
I have googled "(control shift up)", it seems that control-shift-up is used by other people, (but not very few results).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
其原因不是 Emacs 问题,而是由于您的终端无法生成 CS-up 的按键序列。
您可以很容易地验证这一点。打开终端,然后键入:
Control-v 部分将使下一个键的控制序列逐字插入到 shell 中。在我们的例子中,它将插入 Control-Shift 向右的序列,看起来像这样:
现在,尝试对 CS-up 执行相同的操作:
您将看到没有输入任何控制序列,这暗示了事实上,当您在 Emacs 中按 CS-up 时,它实际上永远不会收到任何内容,因为终端无法生成任何内容来传递给 Emacs。
如果您只是启动一个新的
emacs -nw
并输入Ch k
来调用 Emacs 的describe-key
函数,我们可以双重验证这一点。系统会要求您在迷你缓冲区中键入一个键以查看它绑定到什么函数。如果您现在输入 CS-up 则不会发生任何事情 - 当然不会,因为运行 Emacs 的终端不会产生任何结果。但是,如果您只是在寻找未使用的组合键,那么只使用 Shift-up(甚至 Shift-right)而不使用 Control 怎么样?该版本应该可以在终端 emacs 和窗口版本中运行。
The reason for this is not an Emacs problem, but comes from the fact that your terminal cannot produce a key sequence for C-S-up.
You can verify this very easily. Open a terminal and then type:
The Control-v part will make the control sequence for the next key be inserted verbatim into your shell. In our case, it will insert the sequence for Control-Shift right, and that'll look something like this:
Now, try the same thing for C-S-up:
You'll see that no control sequence is entered, which hints at the fact that when you press C-S-up in Emacs, it will actually never receive anything, because the terminal is not able to produce anything to pass on to Emacs.
We can double-verify this if you just start a new
emacs -nw
and typeC-h k
to invoke Emacs'describe-key
function. You'll get asked in the minibuffer to type a key to see what function it is bound to. If you now type C-S-up nothing happens - of course not, since the terminal in which your Emacs runs doesn't produce anything.However, if you're just looking for an unused key-combination, how about just Shift-up (or even Shift-right) without Control? That one should work both in a terminal emacs and in the windowed version.
最后,在 superuser.com 上的 grawity 的帮助下,我让它工作起来了。请此线程
https://superuser.com/questions/230852 /get-ubuntu-terminal-to-send-an-escape-sequence-controlshiftup
Finally, with the help from grawity on superuser.com, I got it working. Please this thread
https://superuser.com/questions/230852/get-ubuntu-terminal-to-send-an-escape-sequence-controlshiftup
这很可能是以下内容的重复:/ M-<向下>在 emacs 23.1.1 中
绑定 M-
如果是这种情况,Gilles 的答案应该会为您解决问题(不过,无疑使用不同的转义序列。)
编辑(为了更好的可见性 - 请参阅 答案如下):
原来gnome终端不传输这些组合键,所以解决方案依赖于以下: https://superuser.com/questions/230852 /get-ubuntu-terminal-to-send-an-escape-sequence-controlshiftup
This could well be a duplicate of:
Binding M-<up> / M-<down> in emacs 23.1.1
If this is the case, Gilles' answer should sort you out (undoubtedly with different escape sequences, though.)
edit (for better visibility -- see answer below):
It turned out that gnome terminal does not transmit these key combinations, so the solution relies upon the following: https://superuser.com/questions/230852/get-ubuntu-terminal-to-send-an-escape-sequence-controlshiftup