doom的用户是怎么绑定多点编辑(evil-mc)的快捷键的?

我用的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 :thinking:

不过 evil hydra 这些我都没用过,怎么混搭更是只能摊手 :person_shrugging:

这是我的 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))
2 个赞

就是这种效果˜

这两个为啥要单独绑定?

evil-visual-block 后,交给 evil-mc 来处理多光标编辑。

这样就可以实现在选中行的开头/结尾各创建一个光标?

A 和 I 依然是对块所在的行尾和行首进行编辑的意思,只不过更灵活些,自己体验下就行。

感谢分享,正是我需要的

pause resume是两个函数,但完全可以合起来 :rofl:

(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 个赞

现在这两个好像都可以了

5 g z d

手动数 可太麻烦了

嗯,对于一眼能看清楚的我感觉还是这样最快。对于不确定的想逐个选择的还是用 hydra 方便