Emacs 定义键、Viper 模式键绑定
我正在尝试学习 emacs,获取 vi 自定义键绑定。
使用Viper模式,重新绑定密钥的正确方法是什么? (我正在使用 Colemak 键盘布局(而不是 qwerty),因此必须更改 n->j 等内容)但是希望它能在 viper 模式下工作。
来自 GNU.org 上的密钥绑定指南: http://www.gnu.org/software/emacs /manual/html_node/viper/Key-Bindings.html
它说放入 .viper 文件的命令是:
(define-key viper-vi-global-user-map "\C-v" 'scroll-down)
它对我不起作用......事实上不确定我什至有“定义”功能-key"...
M-x define-key [No match]
我不确定“define-key”是否在我的 emacs 版本上可用?
这有效,但不适用于 viper 模式
(global-set-key "n" "j")
任何帮助将不胜感激。这是我第一天使用 Emacs,因为使用 Colemak 和 Emacs 很痛苦。 Viper-模式可以正常工作。
感谢您的帮助...
I'm trying to learn emacs, getting vi custom key bindings.
Using Viper-mode, what is the correct way to re-bind a key? (I'm using Colemak keyboard layout(instead of qwerty) so have to change things like n->j) But would like it to work in viper-mode.
From this key binding guide on GNU.org:
http://www.gnu.org/software/emacs/manual/html_node/viper/Key-Bindings.html
It says the command to put in your .viper file is:
(define-key viper-vi-global-user-map "\C-v" 'scroll-down)
It doesn't work for me... in fact not sure I even have the function "define-key"...
M-x define-key [No match]
I'm not sure if 'define-key' is available on my version of emacs?
This works, but not in viper-mode
(global-set-key "n" "j")
Any help would be much appreciated. This is my first day using Emacs, to it's a pain getting Colemak & Viper-mode to work properly.
Thank for any help...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
希望这里有一些有用的答案:
首先,在
.viper
中包含该行对我有用。请注意,viper-vi-global-user-map
适用于您处于命令模式而非插入模式的情况。其次,
define-key
不是一个命令,它是一个常规函数,这只是意味着它不能使用Mx调用。有关此区别的更多详细信息,请参阅此 Emacs wiki 页面。但这是一次很好的尝试。第三,
global-set-key
是一个命令,您可以尝试使用Mx global-set-key进行更改。但是,这在 当前全局地图中设置了键,与viper-vi-global-user-map
不同。 Viper 模式使用一堆不同的键盘映射来使 Emacs 的行为类似于 vi,但所有映射都覆盖在全局映射之上。我猜您发现,当您处于插入模式时,Cv 并未按照您想要的方式绑定。这可以通过将其添加到您的
.viper
中来解决:最后,
scroll-down
可能不是您想要的。down
指的是文本向下移动(给定固定窗口的视角)。 Cv 通常绑定到'scroll-up
。但是,也许这正是您想要的。警告:我不是 viper 模式用户,我什至不知道如何使用 vi。所以我的术语可能有问题。但我发现在 viper 模式下改变事物的挑战非常有趣。
编辑添加
从您的评论来看,您似乎希望 n 与默认情况下绑定的 j 相同。尝试添加此内容:
在“正常”模式下,我执行了 Mxdescribe-key j,它告诉我 j 绑定到
'viper-next-line,上面的行将把 n 绑定到同一个例程。对要移动的其余绑定重复此操作。
Hopefully some useful answers here:
First, having that line in the
.viper
works for me. Note that theviper-vi-global-user-map
applies when you're in command mode, not insert mode.Secondly,
define-key
isn't a command, it's a regular function, which just means that it cannot be called using M-x. See this Emacs wiki page for a little more detail on that distinction. But that was a good attempt.Third, the
global-set-key
is a command, you could have tried making a change using M-x global-set-key. But, that sets the key in the current global map, which isn't the same asviper-vi-global-user-map
. Viper-mode uses a bunch of different keymaps to make Emacs behave like vi, but all of the maps are overlaid on top of the global map.I'm guessing that you found that C-v wasn't bound like you want when you're in insert mode. And that can be solved by adding this to your
.viper
:Lastly,
scroll-down
may not be what you want. Thedown
refers to the text moving down (given the perspective of a fixed window). C-v is generally bound to'scroll-up
. But,maybe it is exactly what you want.Caveat: I'm not a viper-mode user, I don't even know how to use vi. So my terminology may be off. But I find the challenge of changing things in viper-mode very interesting.
Edited to add
From your comment it sounds like you want n to be the same as what j is bound to by default. Try adding this:
In "normal" mode I did M-x describe-key j, which told me that j is bound to
'viper-next-line
, and the above line will bind n to the same routine. Repeat for the rest of the bindings you want to shift around.在现代,evil-mode 是 emacs 的 vim 模拟层,并针对 colemak 进行调整,我的 https ://github.com/wbolster/evil-colemak-basics 包有很大帮助。
in modern times evil-mode is the vim emulation layer for emacs, and to tweak it for colemak, my https://github.com/wbolster/evil-colemak-basics package helps a lot.