How do I visually select the last pasted text with
gv reselects the last visual selection. I'd like a function/snippet that does the same for my last pasted text.
Emacs Stack Exchange is a question and answer site for those using, extending or developing Emacs. It only takes a minute to sign up.Sign up to join this community
.vimrc I have
nnoremap <leader>v '[V']
to do exactly this.
Amazingly, the sequence
'[V'] works in
evil just fine. To have a shortcut in Emacs, I wrote the following function:
(defun my/evil-select-pasted () (interactive) (let ((start-marker (evil-get-marker ?\[)) (end-marker (evil-get-marker ?\]))) (evil-visual-select start-marker end-marker)))
The function can be bound to e.g.
(evil-leader/set-key "v" 'my/evil-select-pasted)
I'm relatively new to Emacs, so this might not be ideal, but it works for me.
How I got there:
C-h k ' shows that
evil-goto-mark-line. Looking at the source in
evil-commands.el shows that
evil-goto-mark, which itself makes use of the
evil-get-marker function. Looking at
evil-states.el, found with
C-h k V, leads to the
When using @andreas solution to select last pasted text and tried to change indentation on it and then repeating the indentation with
evil-repeat) it gave me errors. I had to modify the function to be like this, which now works fine for me:
(defun evil-select-pasted () "Visually select last pasted text." (interactive) (evil-goto-mark ?\[) (evil-visual-char) (evil-goto-mark ?\]))