In evil mode surround keys dont work without spaces

What happened?

In evil mode use keys such as cs([ It will not work when the example line is (test) But will work when theres space around the character Consider ( test )

What did you expect to happen?

There are several commands that only works when theres a space around text.

Steps to reproduce

  1. open a buffer

  2. Paste this following content (Test) Also paste this one ( Test )

  3. Try to execute the command by placing cursor on start of the bracket cs([

Do the same thing on second example.

This will fail for first text (Test) But will work on the second example.

Any thoughts? Appreciate any help!

System information


Loading data dump...

Use cs)] instead. Same rule goes for all paren/braces. E.g. ysiw[ == [ word ] but ysiw] == [word].

Thank you so much, this really helps! Do you think I can replace/keep the original key behavior?

I think I have gotten use to with the muscle memory of the original shortcut.

No worries, if I cant. Once again, I really appreciate the help – it had bothered me enough to ask this question.

Original? This has always been evil-surround’s behavior.

But you can change it by changing evil-surround-pairs-alist. E.g. Here’s how you’d flip their semantics:

;;; add to $DOOMDIR/config.el
(after! evil-surround
  (setf (alist-get ?\( evil-surround-pairs-alist) '("(" . ")")
        (alist-get ?\[ evil-surround-pairs-alist) '("[" . "]")
        (alist-get ?\{ evil-surround-pairs-alist) '("{" . "}")
        ;; optionally:
        (alist-get ?\) evil-surround-pairs-alist) '("( " . " )")
        (alist-get ?\] evil-surround-pairs-alist) '("[ " . " ]")
        (alist-get ?\} evil-surround-pairs-alist) '("{ " . " }")))

This is amazing! Thank you!!!

This topic was automatically closed after 90 days. New replies are no longer allowed.