Emacs Evil“repeat” (点)行为 [英] Emacs Evil "repeat" (dot) behavior

查看:148
本文介绍了Emacs Evil“repeat” (点)行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的 .emacs

(define-key evil-normal-state-map\Mj(lambda()(interactive)(evil-next-line 5)))

使文件中的导航更容易。例如,使用 M-j 我下面的5行,所以我不必按 j 5次。对于所有 hjkl ,我也一样。麻烦的是,这个命令污染了邪恶(点)中的最后一次重复,所以让我们说我在给定行中替换一个字,然后我做 Mj 换一个字5行以下。如果我按,它将再次下拉5行,而不是像Vim那样替换这个单词。如果我使用任何 hjkl ,它不会污染最后一次重复。我如何做到这一点,我的功能不会污染上一次重复?

that makes navigation in a file easier. For instance, with M-j I go 5 lines below, so I don't have to press j 5 times. I do the same for all hjkl. The trouble is that this command pollutes the last repeat in Evil (the dot), so let's say I replace a word in a given line, then I do M-j to go change a word 5 lines below. If I press ., it will jump another 5 lines below, instead of replacing the word as it would happen in Vim. If I use any of hjkl though, it won't pollute the last repeat. How can I do so that my function doesn't pollute the last repeat?

编辑:我刚刚注意到它实际上并没有发生在 \Mj \Mk 之间,但只有 \Mh \Ml ,所以问题更是陌生。两者定义为:

I just noticed that it doesn't actually happen with \M-j and \M-k, but only with \M-h and \M-l, so the problem is even stranger. Both are defined as:

(define-key evil-normal-state-map\Mh'(lambda()(interactive) (evil-backward-char 5)))

(define-key evil-normal-state-map \Ml'(lambda()(interactive)(evil-forward-char 5)))

推荐答案

只需使用defun替换lambda即可:(defun my-5-line-down ...)然后(evil-宣布动议'我的5线 - 下来'
在邪恶(和可能vim?)动议不算作重复,所以这应该做的伎俩。或者,如果您想要控制跳转列表,您可以使用 evil-define-motion 而不是defun。有关定义动议,请参阅文档

Just replace the lambda with a defun say: (defun my-5-lines-down...)and then (evil-declare-motion 'my-5-lines-down) In evil (and probably vim?) motions do not count as repeatables so this should do the trick. Alternatively you can use evil-define-motioninstead of defun if you want control over the jump list. See documentation for defining a motion.

这篇关于Emacs Evil“repeat” (点)行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆