我用的doom,
doom的官方是这样绑定快捷键的
(:when (modulep! :editor multiple-cursors)
:prefix "gz"
:nv "d" #'evil-mc-make-and-goto-next-match
:nv "D" #'evil-mc-make-and-goto-prev-match
:nv "s" #'evil-mc-skip-and-goto-next-match
:nv "S" #'evil-mc-skip-and-goto-prev-match
:nv "c" #'evil-mc-skip-and-goto-next-cursor
:nv "C" #'evil-mc-skip-and-goto-prev-cursor
:nv "j" #'evil-mc-make-cursor-move-next-line
:nv "k" #'evil-mc-make-cursor-move-prev-line
:nv "m" #'evil-mc-make-all-cursors
:nv "n" #'evil-mc-make-and-goto-next-cursor
:nv "N" #'evil-mc-make-and-goto-last-cursor
:nv "p" #'evil-mc-make-and-goto-prev-cursor
:nv "P" #'evil-mc-make-and-goto-first-cursor
:nv "q" #'evil-mc-undo-all-cursors
:nv "t" #'+multiple-cursors/evil-mc-toggle-cursors
:nv "u" #'+multiple-cursors/evil-mc-undo-cursor
:nv "z" #'+multiple-cursors/evil-mc-toggle-cursor-here
:v "I" #'evil-mc-make-cursor-in-visual-selection-beg
:v "A" #'evil-mc-make-cursor-in-visual-selection-end)
如果要创建5个光标,就要gzd gzd gzd gzd gzd连按5次。
有没有办法变成gz d d d d d,gz进入多点编辑模式,然后每次按d就创建一个光标。
大家是怎么用evil-mc这个包的?
听起来你需要 repeat-mode 或者 hydra
不过 evil hydra 这些我都没用过,怎么混搭更是只能摊手 。
hq306
2023 年2 月 6 日 05:18
3
这是我的 evil-mc 配置,用的是 hydra,供您参考:
(use-package evil-mc
:diminish
:hook (after-init . global-evil-mc-mode)
:init
(defvar evil-mc-key-map (make-sparse-keymap))
:config
(defhydra hydra-evil-mc (:color blue :hint nil)
"
_M_ all match _m_ here _u_ undo
_n_ next match _j_ next line _s_ suspend
_p_ prev match _k_ previous line _r_ resume
_N_ skip & next match _H_ first cursor _q_ quit
_P_ skip & prev match _L_ last cursor _O_ quit
"
("m" evil-mc-make-cursor-here :exit nil)
("M" evil-mc-make-all-cursors :exit nil)
("n" evil-mc-make-and-goto-next-match :exit nil)
("p" evil-mc-make-and-goto-prev-match :exit nil)
("N" evil-mc-skip-and-goto-next-match :exit nil)
("P" evil-mc-skip-and-goto-prev-match :exit nil)
("j" evil-mc-make-cursor-move-next-line :exit nil)
("k" evil-mc-make-cursor-move-prev-line :exit nil)
("H" evil-mc-make-and-goto-first-cursor :exit nil)
("L" evil-mc-make-and-goto-last-cursor :exit nil)
("u" evil-mc-undo-last-added-cursor :exit nil)
("r" evil-mc-resume-cursors)
("s" evil-mc-pause-cursors)
("O" evil-mc-undo-all-cursors)
("q" evil-mc-undo-all-cursors))
(evil-define-key* '(normal visual) 'global
(kbd "M") 'hydra-evil-mc/body)
(evil-define-key* 'visual evil-mc-key-map
"A" 'evil-mc-make-cursor-in-visual-selection-end
"I" 'evil-mc-make-cursor-in-visual-selection-beg))
3 个赞
hq306
2023 年2 月 6 日 05:26
6
用 evil-visual-block
后,交给 evil-mc 来处理多光标编辑。
这样就可以实现在选中行的开头/结尾各创建一个光标?
hq306
2023 年2 月 6 日 05:43
8
A 和 I 依然是对块所在的行尾和行首进行编辑的意思,只不过更灵活些,自己体验下就行。
pause resume是两个函数,但完全可以合起来
(defun my/evil-mc-toggle-cursors-pause ()
"Toggle between pausing or resuming all cursors."
(interactive)
(if evil-mc-frozen
(evil-mc-resume-cursors)
(evil-mc-pause-cursors)))
回到主题,hydra是一种,另外我还发现这种要连续按的键,用modifier-x 这样的也挺好的,按住ctrl之类,然后连敲x
我的evil mc next prev match是alt-n alt-p ,evil mc next line、prev line是alt-j alt-k ,我还用evil-multiedit,它的next prev match是C-n C-p
往前三五年evil-mc很不完善完全没法用,只有evil-multiedit,所以现在就两个都用了。想下后者的优点的话大概是match all之后可以方便地在各个match中跳转然后toggle某个?
1 个赞
嗯,对于一眼能看清楚的我感觉还是这样最快。对于不确定的想逐个选择的还是用 hydra 方便
oLd-Y
2024 年4 月 8 日 12:29
17
基于老哥的代码做了点微调改了移动的方式, 更符合 Vimer 的直觉.
("j" evil-next-line :exit nil)
("k" evil-previous-line :exit nil)
("J" evil-mc-make-cursor-move-next-line :exit nil)
("K" evil-mc-make-cursor-move-prev-line :exit nil)
顺便修改了一下 hydra 触发键. M 键光标跳转到屏幕中间对我来说还是挺常用的. 发现 doom emacs 中的 SPC-j 未被占用, 把这个高频功能放到这里也还算能接受. 那个 evil-define-key*
定义按键的方法不知道为什么会重启 emacs 会卡死, 所以改用 doom 的定义方式.
(map! :leader
:desc "Evil-mc Hydra"
"j" #'hydra-evil-mc/body)
(map! :map evil-mc-key-map
:v "A" #'evil-mc-make-cursor-in-visual-selection-end
:v "I" #'evil-mc-make-cursor-in-visual-selection-beg))
完整的配置代码如下:
(use-package! evil-mc
:diminish
:hook (after-init . global-evil-mc-mode)
:init
(defvar evil-mc-key-map (make-sparse-keymap))
:config
(defhydra hydra-evil-mc (:color blue :hint nil)
"
_C-a_ all match _m_ here _u_ undo
_n_ next match _J_ mark & move next _s_ suspend
_p_ prev match _K_ mark & move prev _r_ resume
_N_ skip & next match _H_ first cursor _q_ quit
_P_ skip & prev match _L_ last cursor _O_ quit
"
("m" evil-mc-make-cursor-here :exit nil)
("C-a" evil-mc-make-all-cursors :exit nil)
("n" evil-mc-make-and-goto-next-match :exit nil)
("p" evil-mc-make-and-goto-prev-match :exit nil)
("N" evil-mc-skip-and-goto-next-match :exit nil)
("P" evil-mc-skip-and-goto-prev-match :exit nil)
("j" evil-next-line :exit nil)
("k" evil-previous-line :exit nil)
("J" evil-mc-make-cursor-move-next-line :exit nil)
("K" evil-mc-make-cursor-move-prev-line :exit nil)
("H" evil-mc-make-and-goto-first-cursor :exit nil)
("L" evil-mc-make-and-goto-last-cursor :exit nil)
("u" evil-mc-undo-last-added-cursor :exit nil)
("r" evil-mc-resume-cursors)
("s" evil-mc-pause-cursors)
("O" evil-mc-undo-all-cursors)
("q" evil-mc-undo-all-cursors))
(map! :leader
:desc "Evil-mc Hydra"
"j" #'hydra-evil-mc/body)
(map! :map evil-mc-key-map
:v "A" #'evil-mc-make-cursor-in-visual-selection-end
:v "I" #'evil-mc-make-cursor-in-visual-selection-beg))