0

Evil-unimpaired (https://github.com/zmaas/evil-unimpaired/) tries to replicate vim-unimpaired, but the paste behaviour is just a dumbed down version of the original. The evil-unimpaired behaviour on [p:

(defun evil-unimpaired-paste-below ()
  (interactive)
  (evil-insert-newline-below)
  (evil-paste-after 1 evil-this-register))

It just inserts a newline and then pastes the register content. It doesn't care whether register content has a newline or not. It just inserts a new line anyway. Let's say I have the following text and I copy the second line with yy:

first line
   |second line

When I paste with [p it becomes

first line
    second line
    
   |second line

which is not a desirable output. Compare it to vim-unimpaired behaviour:

first line
   |second line

Paste with [p

first line
    second line
   |second line

The same problem applies to ]p which is supposed to paste text above current line. I want to know if there is a existing solution or can someone show me how to update the evil-unimpaired function so it works properly. My emacs-fu is pretty much nonexistent, unfortunately

2
  • I don't think the question is very clear at this point. Please edit it to clarify what you would like to achieve.
    – TerryTsao
    May 6, 2021 at 5:37
  • @TerryTsao updated
    – evakuator
    May 6, 2021 at 6:25

1 Answer 1

0

The following satisfies your requirements I believe. I had the same problem, and I've used the following to get behavior like in Vim.

(defun +ani/evil-unimpaired-paste-above ()
  (interactive)
  (let ((register (if evil-this-register
                      evil-this-register
                    ?\")))
    (when (not (member 'evil-yank-line-handler (get-text-property 0 'yank-handler (evil-get-register register))))
      (evil-insert-newline-above))
    (evil-paste-before 1 register)))

(defun +ani/evil-unimpaired-paste-below ()
  (interactive)
  (let ((register (if evil-this-register
                      evil-this-register
                    ?\")))
    (when (not (member 'evil-yank-line-handler (get-text-property 0 'yank-handler (evil-get-register register))))
      (evil-insert-newline-below))
    (evil-paste-after 1 register)))

Credits goes to anihm136 on GitHub where I took this code from:

https://github.com/hlissner/doom-emacs/issues/5422#issuecomment-939250010

3
  • This is a link-only answer. Please delete this answer, or summarize the info for it that's at that link.
    – Drew
    Apr 27, 2022 at 20:00
  • @Drew Thanks for the heads up! Fixed it.
    – PsyFish
    Apr 29, 2022 at 11:04
  • Thanks..........
    – Drew
    Apr 29, 2022 at 16:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.