Skip to main content
edited tags; edited tags
Link
Drew
  • 79.1k
  • 10
  • 123
  • 257
it should also respond to the `.` command
Source Link
Zaz
  • 143
  • 6

I'm trying to reverse some words, and I have it set up where I can visually select them and hit ,rw to reverse them.

How do I set it up so ,rw also works with a motion. E.g. ,rw3w to reverse 3 words?

(defun reverse-words (beg end)
  "Reverse the order of words in region."
  (interactive "*r")
  (apply
    'insert
    (reverse
      (split-string
        (delete-and-extract-region beg end) "\\b"))))
(define-key evil-visual-state-map (kbd ",rw") 'reverse-words)

I've also tried (define-key evil-normal-state-map ...) and (define-key evil-operator-state-map ...) but to no avail.

It should also respond to the . command to repeat the last command.

Any tips on a built-in way to do this or a better keybinding would be appreciated.

I'm trying to reverse some words, and I have it set up where I can visually select them and hit ,rw to reverse them.

How do I set it up so ,rw also works with a motion. E.g. ,rw3w to reverse 3 words?

(defun reverse-words (beg end)
  "Reverse the order of words in region."
  (interactive "*r")
  (apply
    'insert
    (reverse
      (split-string
        (delete-and-extract-region beg end) "\\b"))))
(define-key evil-visual-state-map (kbd ",rw") 'reverse-words)

I've also tried (define-key evil-normal-state-map ...) and (define-key evil-operator-state-map ...) but to no avail.

Any tips on a built-in way to do this or a better keybinding would be appreciated.

I'm trying to reverse some words, and I have it set up where I can visually select them and hit ,rw to reverse them.

How do I set it up so ,rw also works with a motion. E.g. ,rw3w to reverse 3 words?

(defun reverse-words (beg end)
  "Reverse the order of words in region."
  (interactive "*r")
  (apply
    'insert
    (reverse
      (split-string
        (delete-and-extract-region beg end) "\\b"))))
(define-key evil-visual-state-map (kbd ",rw") 'reverse-words)

I've also tried (define-key evil-normal-state-map ...) and (define-key evil-operator-state-map ...) but to no avail.

It should also respond to the . command to repeat the last command.

Any tips on a built-in way to do this or a better keybinding would be appreciated.

Source Link
Zaz
  • 143
  • 6

define a new evil command

I'm trying to reverse some words, and I have it set up where I can visually select them and hit ,rw to reverse them.

How do I set it up so ,rw also works with a motion. E.g. ,rw3w to reverse 3 words?

(defun reverse-words (beg end)
  "Reverse the order of words in region."
  (interactive "*r")
  (apply
    'insert
    (reverse
      (split-string
        (delete-and-extract-region beg end) "\\b"))))
(define-key evil-visual-state-map (kbd ",rw") 'reverse-words)

I've also tried (define-key evil-normal-state-map ...) and (define-key evil-operator-state-map ...) but to no avail.

Any tips on a built-in way to do this or a better keybinding would be appreciated.