LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 12-18-2018, 06:41 AM   #1
lucmove
Senior Member
 
Registered: Aug 2005
Location: Brazil
Distribution: Debian
Posts: 1,434

Rep: Reputation: 110Reputation: 110
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

Last edited by lucmove; 12-18-2018 at 06:42 AM.
 
Old 12-18-2018, 01:00 PM   #2
business_kid
LQ Guru
 
Registered: Jan 2006
Location: Ireland
Distribution: Slackware, Slarm64 & Android
Posts: 16,376

Rep: Reputation: 2336Reputation: 2336Reputation: 2336Reputation: 2336Reputation: 2336Reputation: 2336Reputation: 2336Reputation: 2336Reputation: 2336Reputation: 2336Reputation: 2336
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.
 
Old 12-18-2018, 08:52 PM   #3
frankbell
LQ Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Ubuntu MATE, Mageia, and whatever VMs I happen to be playing with
Posts: 19,351
Blog Entries: 28

Rep: Reputation: 6147Reputation: 6147Reputation: 6147Reputation: 6147Reputation: 6147Reputation: 6147Reputation: 6147Reputation: 6147Reputation: 6147Reputation: 6147Reputation: 6147
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.
 
1 members found this post helpful.
Old 12-18-2018, 09:59 PM   #4
Mechanikx
Member
 
Registered: Jul 2018
Distribution: Slackware
Posts: 351

Rep: Reputation: 258Reputation: 258Reputation: 258
Quote:
Originally Posted by lucmove View Post
- 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
 
Old 12-19-2018, 10:40 PM   #5
frankbell
LQ Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Ubuntu MATE, Mageia, and whatever VMs I happen to be playing with
Posts: 19,351
Blog Entries: 28

Rep: Reputation: 6147Reputation: 6147Reputation: 6147Reputation: 6147Reputation: 6147Reputation: 6147Reputation: 6147Reputation: 6147Reputation: 6147Reputation: 6147Reputation: 6147
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 . . . .

Last edited by frankbell; 12-19-2018 at 10:43 PM.
 
Old 12-19-2018, 10:43 PM   #6
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,363

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
You could start here https://www.vim.org/
 
Old 12-20-2018, 04:17 AM   #7
lucmove
Senior Member
 
Registered: Aug 2005
Location: Brazil
Distribution: Debian
Posts: 1,434

Original Poster
Rep: Reputation: 110Reputation: 110
Quote:
Originally Posted by MYSELF View Post
I found this in my .vimrc:
Quote:
Originally Posted by Mechanikx View Post
Also, it might be worth it for you to create your own .vimrc.
Quote:
Originally Posted by frankbell View Post
I think the .vimrc suggestion is an excellent one.
Yes. Never mind.
 
Old 12-20-2018, 05:52 AM   #8
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,948

Rep: Reputation: 7326Reputation: 7326Reputation: 7326Reputation: 7326Reputation: 7326Reputation: 7326Reputation: 7326Reputation: 7326Reputation: 7326Reputation: 7326Reputation: 7326
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.
 
Old 12-20-2018, 04:15 PM   #9
frankbell
LQ Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Ubuntu MATE, Mageia, and whatever VMs I happen to be playing with
Posts: 19,351
Blog Entries: 28

Rep: Reputation: 6147Reputation: 6147Reputation: 6147Reputation: 6147Reputation: 6147Reputation: 6147Reputation: 6147Reputation: 6147Reputation: 6147Reputation: 6147Reputation: 6147
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
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Fedora shows 'man vim' but when execute 'vim' got "bash: vim: command not found..." ? flash_os Linux - Newbie 19 01-03-2015 11:56 PM
Switching from vim to vim -g from inside vim iDragoon Linux - Software 4 05-15-2009 11:46 AM
Editor comparison: vim VS vim-lite, Cleaning vim Ruler2112 *BSD 4 04-13-2009 04:26 PM
yanking/pasting text across vim sessions derzok Linux - Software 2 08-08-2008 05:00 PM
copy pasting from X app to vim Furlinastis Linux - General 3 12-05-2005 09:05 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 04:57 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration