1

I'm not from a vim background so I remap a lot of the evil commands and keys to fit my needs. I know you can use evil-repeat but I like the following better to quickly kill a few lines:

(defun evil-delete-or-repeat-delete-line ()
  (interactive)
  (if (or (eq last-command this-command)
          (eq last-command 'evil-line))
      (progn
        (setq this-command 'evil-line)
        (call-interactively 'evil-repeat)
        (kill-new (concat (cadr kill-ring) (car kill-ring))))
    (call-interactively 'evil-delete)))

This function repeats deleting lines if I press the evil-delete key multiple times and also preserves the evil-delete functionality. It appends every subsequent kills to the kill ring, too. This works with the following binding:

(define-key evil-normal-state-map (kbd "x") 'evil-delete-or-repeat-delete-line) 

I would like to have something similar for evil-yank. For this the cursor should move to the next line after every call. I tried but couldn't get it to work. Can anyone help me?

3
  • First, can you show your code that doesn't work? Second, can you clarify: do you want to yank the same text repeatedly, or do you want to step through the kill-ring on each successive call?
    – Dan
    Aug 23, 2015 at 20:49
  • @Dan In "evil-speak" yank means copy, confusing I know....I would like to copy a line move to the next line and then copy again if I press the key again. The code was in my scratch buffer and is lost now ;) But I will try it again and add the code to my question then.
    – clemera
    Aug 23, 2015 at 21:40
  • @Dan It worked now, I posted the answer, don't know what went wrong in my first try, I thought it had to be a bigger problem for some reason and posted it here. Thanks for your attention.
    – clemera
    Aug 23, 2015 at 21:57

1 Answer 1

0

I tried again and now it works:

(defun evil-copy-or-repeat-copy-line ()
  (interactive)
  (if (or (eq last-command this-command)
          (eq last-command 'evil-line))
      (progn
        (forward-line 1)
        (setq this-command 'evil-line)
        (call-interactively 'evil-repeat)
        (kill-new (concat (cadr kill-ring) (car kill-ring))))
    (call-interactively 'evil-yank)))

(define-key evil-normal-state-map (kbd "w") 'evil-copy-or-repeat-copy-line)

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.