1

In evil-mode, if I use 3yy to copy three lines, then move somewhere else in my file and do P (evil-paste-before), the three lines are pasted before the line with the cursor, and the cursor is left at the top of the pasted text.

If however I copy a section of text using org-copy-visible and paste that using P, the cursor ends up at the bottom of the pasted text.

I can get the desired result (cursor left at start of text) in the latter case if I subsequently do an undo / redo but that is too hacky even for me.

How can I paste following a call to org-copy-visible and leave the cursor at the start of the pasted text?

4
  • Try C-x C-x (which runs the function exchange-point-and-mark) or its evil equivalent, after the paste. – NickD May 27 at 0:04
  • C-x C-x will activate the region incidentally, you can use C-u C-SPC to pop the mark. Or instead, use emacs' built-in C-y (yank), when adding C-u, it paste text after point. dunno whether evil provides this functionality or not. – nichijou May 27 at 2:37
  • Sorry, just found you can C-u C-x C-x to not activate the region. – nichijou May 27 at 2:40
  • @nichijou: feel free to make your comments into an answer. – NickD May 27 at 18:57
1

Per the vim manual, just p would do, but unluckily when I tried in Vim, both leave cursor after the new text, and evil didn't bind gp at all. dead end for me.

                                                        p put E353
["x]p                   Put the text [from register x] after the cursor
                        [count] times.

...

                                                        gp
["x]gp                  Just like "p", but leave the cursor just after the new
                        text.

The Emacs way:

The basic yanking command is C-y (yank). It inserts the most recent kill, leaving the cursor at the end of the inserted text. It also sets the mark at the beginning of the inserted text, without activating the mark; this lets you jump easily to that position, if you wish, with C-u C-<SPC>

With a plain prefix argument (C-u C-y), the command instead leaves the cursor in front of the inserted text, and sets the mark at the end. Using any other prefix argument specifies an earlier kill; e.g., C-u 4 C-y reinserts the fourth most recent kill.

Good news is evil's paste commands set mark of the other side of newly pasted text for you too. You can go to the other side either:

  • C-x C-x (exchange-point-and-mark) :: if transient-mark-mode is on, add C-u to avoid activating the region incidently.
  • C-u C-<SPC>
0

Thanks @NickD and @nichijou, C-x C-x seems just the job.

3
  • 2
    Please don't add "thank you" as an answer. Instead, accept the answer that you found most helpful. - From Review – Drew May 27 at 13:40
  • There was no answer, just comments, so I wanted to add an answer by pointing to a comment. – user2567544 May 27 at 16:26
  • 1
    Please don't do that. Answers are for answers, comments are for comments. Thx. – Drew May 27 at 17:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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