LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   I don't understand pasting in Vim (https://www.linuxquestions.org/questions/linux-software-2/i-dont-understand-pasting-in-vim-4175644511/)

lucmove 12-18-2018 06:41 AM

I don't understand pasting in Vim
 
I have Vim configured to paste external text (i.e. text copied from an external source, not inside Vim) in two manners: Ctrl+v and Ctrl+Shift+v.

The former used to paste text subject to autocorrect action; the latter didn't.

I don't know exactly how I did it. I found this in my .vimrc:

Code:

" Pasting blockwise and linewise selections is not possible in Insert and
" Visual mode without the +virtualedit feature. They are pasted as if they
" were characterwise instead.
" Note: the same stuff appears in menu.vim.
if has("virtualedit")
        nnoremap <silent> <SID>Paste :call <SID>Paste()<CR>
        func! <SID>Paste()
                let ove = &ve
                set ve=all
                normal `^
                if @+ != ''
                        normal "+gP
                endif
                let c = col(".")
                normal i^[
                if col(".") < c        " compensate for i<ESC> moving the cursor left
                        normal l
                endif
        let &ve = ove
        endfunc
        inoremap <script> <C-V>        x<BS><Esc><SID>Pastegi
        vnoremap <script> <C-V>        "-c<Esc><SID>Paste
else
        nnoremap <silent> <SID>Paste        "=@+.'xy'<CR>gPFx"_2x
        inoremap <script> <C-V>        x<Esc><SID>Paste"_s
        vnoremap <script> <C-V>        "-c<Esc>gix<Esc><SID>Paste"_x
endif

I am 100% sure I didn't write any of that myself. I took it from someone else in the internets. It seems to explain where Ctrl+v is configured, but I still don't know where Ctrl+Shift+v is. I can't find any references to it in my .vimrc. I have many key bindings, but none involves the letter v. I've triple checked. Maybe it's in the code above, which I can't read very well. I'm not fluent in vimscript.

But I remember I changed something one day and neither key combination now is affected by autocorrect. They have the exact same effect... or almost.

The only difference between them now is that there is some limit to the amount of text I can paste with Ctrl+v. If I go above that limit, something else is pasted. Something I copied elsewhere some time ago, often hours ago and I don't know how or why it is still hanging somewhere.

Ctrl+Shift+v doesn't seem to have any limit. It seems to have infinite capacity. I have pasted hundreds of MB of text and it works.

My questions today are:

- Why is there such a limit? Why do the two actions work so differently?
- Where is the Ctrl+Shift+v action configured?
- How can I improve my handling of copy/pasting from/into Vim, in case you have a better idea?

TIA

business_kid 12-18-2018 01:00 PM

I gave up farting about totally with vim. It's a bit like the lost chord - you get it out once and never find it again. Use Nano. No sweat with the middle mouse button.

frankbell 12-18-2018 08:52 PM

I have never managed to paste into vim with CTRL-v; I always use CTRL-SHIFT-v. I just tested CTRL-v on Debian Testing; did not paste.

I think the question that should be asked is "why am I able to paste with CTRL-v?"

I used to find vim frustrating, then I realized I was approaching it wrong. I was trying to learn too much at once. I concentrated on becoming proficient with a few basic commands (x, i, o, y, p, dd, x, and / mainly) and am now quite comfortable using vim with the kinds of text files that I need to edit.

Mechanikx 12-18-2018 09:59 PM

Quote:

Originally Posted by lucmove (Post 5938562)
- How can I improve my handling of copy/pasting from/into Vim, in case you have a better idea?

TIA

I'm not sure if this is a better idea but I use vim on a regular basis and to copy I use 'Ctrl + alt + c' and to paste 'Shift + insert'. I've never had any problems with copying text and pasting into vim this way. Of course, I've never copied and pasted a hundred or more MBs of text.

Also, it might be worth it for you to create your own .vimrc. That way when you come across some functionality you would like to have, you can learn about it, add it to your .vimrc, and that way you know what every line of your .vimrc does. Just an idea. That's how I like to do things :)

frankbell 12-19-2018 10:40 PM

I think the .vimrc suggestion is an excellent one. I used to have one on this computer until I had to reinstall:(.

It didn't do much. Mostly it turned on line numbering and a few other odds and ends.

A web search for "vimrc" will turn up a number of excellent articles and examples.

I should have a copy somewhere. If I can find it, I'll post it tomorrow. I've made a note . . . .

chrism01 12-19-2018 10:43 PM

You could start here https://www.vim.org/ :)

lucmove 12-20-2018 04:17 AM

Quote:

Originally Posted by MYSELF (Post 5938562)
I found this in my .vimrc:

Quote:

Originally Posted by Mechanikx (Post 5938844)
Also, it might be worth it for you to create your own .vimrc.

Quote:

Originally Posted by frankbell (Post 5939240)
I think the .vimrc suggestion is an excellent one.

Yes. Never mind.

pan64 12-20-2018 05:52 AM

I would try simply :r file and that will insert the content. Or you can open several files within vim and yank/put will work among those files. You do not need to complicate it. Originally vi was not meant to handle [external] copy&paste buffers.

frankbell 12-20-2018 04:15 PM

As promised, here's a .vimrc from one of my machines:

Code:

$ cat .vimrc
set ruler laststatus=2 number title hlsearch
syntax on
set textwidth=80
set spell spelllang=en_us
set spellfile=$HOME/.vim/spell/en.utf-8.add



All times are GMT -5. The time now is 07:51 PM.