Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Pretty simple - how can one select just pasted text (after pasting it) ?

I'm editing some files which are purely data, and I get "lost" sometimes ... so it would help if I could select it or somehow otherwise mark the text I've just pasted as to have a visual confirmaton, and to know from where to continue.

Can it be done ?

share|improve this question
did you see my edit? – asdfg Apr 5 '10 at 6:35
@nsharish - no, sorry. saw it just now. – Rook Apr 5 '10 at 11:01
up vote 1 down vote accepted

Did you try 'gv' in normal mode...
It does n't actually select last pasted text...
It selects last selected text..

nmap p :call Paster()<CR> 
nmap '; :call LastPasted()<CR>
nmap y :call ClearList()<CR>

let s:linelist=[]
let s:lastidx=len(s:linelist)
if !exists("*Paster")
    function! Paster()
        let x=getpos(".")
        let s:linelist+=[x]
        let s:lastidx=len(s:linelist)
        if s:lastidx>50
            let s:lastidx-=1
        "echo s:linelist
        exec "normal! \"0gp"
if !exists("*LastPasted")
    function! LastPasted()
        if s:lastidx>0
            let s:lastidx=s:lastidx-1
            let s:lastidx=len(s:linelist)-1
        let pos=s:linelist[s:lastidx-1]
        call setpos(".",pos)
if !exists("*ClearList")
    function! ClearList()
        let s:linelist=[getpos(".")]
        let s:lastidx=0
        exec "normal! :y\<CR>"

This might help you.. Add this to your vimrc file.
Here I remapped 'y'(yank) and 'p'(paste) such a way that, the cursor position is saved for every copy and paste. You can use '; to cycle thro the positions. It does not select the pasted text but takes you to the positions where you pasted the text. For every new copy the buffer(a list) is cleared.

I just limited the buffersize to 50. You may remove the section if not needed.

share|improve this answer
Yes, but it doesn't actually work in this case. – Rook Mar 31 '10 at 14:28



as in:

m'                " set the 'context' mark
gp                " paste the stuff and place the cursor after the
                  " new text
v                 " visual mode
''                " jump to the 'context' mark and selecting
                    the previous pasted text
share|improve this answer
I think gp (“Just like "p", but leave the cursor just after the new text.”) could simplify things to just m'gpv''. Wrap it up in a mapping for ease of access. The OPs problem is then solved with undo and re-paste with this method. – Chris Johnsen Mar 31 '10 at 19:24
@chris: right, better. – akira Mar 31 '10 at 19:52

Undo then Redo. Doesn't select the text but it tells you where the change was. If you made some other edit since pasting... there's always multiple undo.

share|improve this answer
I know where one side of the paste was (cursor is there, or the cursorline) but what about the other ? Where does the paste end ? – Rook Mar 30 '10 at 23:55
@ldigas re-pasting via Shift+Insert instead of Redo will put the cursor at the end (and kill any further Redos). Otherwise maybe you could write a vim script which counted the chars in the clipboard / vim register and moved the cursor by that amount. – Hugh Allen Mar 31 '10 at 0:07

Well, it is still in your clipboard, ready to paste. If you get lost, you could do another paste to an empty text file, and see where you were by what was pasted.

share|improve this answer
No, I think you misunderstood. I have for example, a file full of x,y,z points. Now, I paste some coordinates in the middle of the already existing ones, turn my head around, and ... I don't know anymore where I ones I just pasted are. So it would help for example, to retain the selection on just those. As a visual aid. – Rook Mar 30 '10 at 22:08
Yes, I misunderstood. That's a problem I've had too, and I don't know the solution. So I'll upvote your question, because I'd like to know too. – thursdaysgeek Mar 30 '10 at 22:12
The ugly way would be to do a search on the file, and paste your text into the search box. It would be nicer if it just stayed highlighted until you pasted something else. – thursdaysgeek Mar 30 '10 at 22:13
Oh, okey. Yes, the search could work ... but they're all numbers ... not something I can remember (I don't think about them, just position them where they need to be ...). – Rook Mar 30 '10 at 22:29

paste v '' (that is, paste text, v, single quote twice). seems to select what was just pasted, in gvim73 on windows.

share|improve this answer

You can select just pasted text using following mapping:

nnoremap <expr> gp '`[' . getregtype()[0] . '`]'

Found on SO. Here's also some additional data how it works.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .