如何使用 Emacs 将指针向上或向下移动多行?
在 Emacs 中,我可以用箭头键将指针上下移动一行,所以我想重新定义 Cn 和 Cp,以便一次上下移动 5 行。
我刚刚开始学习如何使用 Emacs,elisp 对我来说很陌生。我尝试使用 GNU Emacs lisp 参考,但我不能找不到如何将击键绑定到多个命令。
这是我到目前为止所得到的(集中于向上移动的定义):
(global-set-key "\C-p" '(loop for i in '(1 2 3 4 5) do ('previous-line)))
但是,当我点击 Cp 时,这会显示一条错误消息,“类型参数错误”。
有什么建议吗?
谢谢!
I can move my pointer up and down one line with my arrow key just fine in Emacs, so I'd like to redefine C-n and C-p to move up and down 5 lines at a time.
I'm just beginning to learn how to use Emacs, and elisp is very alien to me. I tried using the GNU Emacs lisp reference, but I couldn't find how to bind a keystroke to multiple commands.
Here's what I have so far (concentrating on the moving up definition):
(global-set-key "\C-p" '(loop for i in '(1 2 3 4 5) do ('previous-line)))
But, this brings up an error message when I hit C-p, "Wrong type argument."
Any suggestions?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这些函数(我相信
next-line
和previous-line
)接受 Cu 的可选参数,所以我认为(next-line 5)
会做你想做的事。编辑:所以我刚刚尝试过,这
与 Cp 和
previous-line
相同。(用手机键盘在文本区域写代码并不简单^^)
Those function (I believe
next-line
andprevious-line
) accept an optionnal argument with C-u, so i think that(next-line 5)
would do what you want.Edit: so I just tried and that would be
And the same with C-p and
previous-line
.(Fiew not simple to write code in a textarea with a phone keyboard ^^)
根据我的 emacs 配置中的警告和 Peter Ajtai 的评论,我建议使用
init.el
中的forward-line
版本,当然还有
forward-char
,工作原理相同,只是方向不同。唯一缺少的是一个
complex-forward
,它将一个复数作为参数,并且可以用于在所有 4 个方向上导航:Paccording the warning in my emacs config, and the comment from Peter Ajtai, I propose the version that uses
forward-line
from myinit.el
Of course there is also
forward-char
, works the same, just in a different direction.The only thing that's missing is a
complex-forward
that takes a complex number as an argument, and can be used to navigate in all 4 directions :P