select just pasted text

6

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 ?

Rook

Posted 2010-03-30T21:44:52.203

Reputation: 21 622

did you see my edit? – asdfg – 2010-04-05T06:35:03.437

@nsharish - no, sorry. saw it just now. – Rook – 2010-04-05T11:01:43.907

Answers

1

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

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
            remove(s:linelist,0)
            let s:lastidx-=1
        endif
        "echo s:linelist
        exec "normal! \"0gp"
    endfunction
endif
if !exists("*LastPasted")
    function! LastPasted()
        if s:lastidx>0
            let s:lastidx=s:lastidx-1
        else
            let s:lastidx=len(s:linelist)-1
        endif
        let pos=s:linelist[s:lastidx-1]
        call setpos(".",pos)
    endfunction
endif
if !exists("*ClearList")
    function! ClearList()
        let s:linelist=[getpos(".")]
        let s:lastidx=0
        exec "normal! :y\<CR>"
    endfunction
endif

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.

asdfg

Posted 2010-03-30T21:44:52.203

Reputation: 2 266

Yes, but it doesn't actually work in this case. – Rook – 2010-03-31T14:28:17.593

3

maybe:

m'gpv''

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

akira

Posted 2010-03-30T21:44:52.203

Reputation: 52 754

1I 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 – 2010-03-31T19:24:37.920

@chris: right, better. – akira – 2010-03-31T19:52:50.217

2

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.

Hugh Allen

Posted 2010-03-30T21:44:52.203

Reputation: 8 620

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 – 2010-03-30T23:55:40.873

@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 – 2010-03-31T00:07:51.530

1

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.

thursdaysgeek

Posted 2010-03-30T21:44:52.203

Reputation: 2 310

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 – 2010-03-30T22:08:22.610

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 – 2010-03-30T22:12:10.887

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 – 2010-03-30T22:13:34.283

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 – 2010-03-30T22:29:02.390

1

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

mosh

Posted 2010-03-30T21:44:52.203

Reputation: 11

1

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.

slawek

Posted 2010-03-30T21:44:52.203

Reputation: 111