I'm running into some trouble using Vim in OSX which is: whenever I copy outside of Vim and COMMAND + P to paste text inside, a few characters of the copied text gets deleted.
COPY: Function(){......
+ 20 lines
PASTE n(){.....
+ 20 lines)
I know Vim has a lot of ins and outs... I use it without trouble on my Ubuntu setup. But I am not really expert with it yet and I have a feeling this is a basic issue mac users will have encountered. However, I was looking through the forums and googling it, and I cannot seem to find an answer.
Appreciate so much any help.
EDIT: I know this is a very basic question that someone might ask if they didn't understand the basics of Vi insert mode and hadn't like run Vimtutor. For me that was not quite the issue; I actually have been working of Vim for a while, but this default behavior had been changed early on (so I never noticed it).
I definitely would have wasted a lot of time before considering the basics of how insert mode works, so really thank you so much for your awesome, timely responses! I hope that this thread is useful to some other folks who're perhaps inadvisably pulled some "boilerplate" .vimrc off the internet, or have gotten used to Vim as configured by others... because the point of Stack Overflow isn't to explain to people things they should have picked in like 10 seconds from a man page or whatever.
It looks like you're not in insert mode when you're pasting, so Vim interprets the text as commands, until one letter (e.g. i
or o
) accidentally switches to insert mode. [1]
You need to go into insert mode first (i
, also consider :set paste
, and the 'pastetoggle'
option; :help 'paste'
has some background information).
Or (when supported), access the clipboard from within Vim, e.g. via "+p
(normal mode) or <C-R><C-R>+
(insert mode).
As only the terminal-based versions of Vim have this problem of differentiating between typed and pasted keys, switching to the GUI GVIM (I think called MacVim there) would avoid this problem, too.
[1] Vim understands the example as:
Fu
: backward find character u
n
: next search matchcti
: change until before the next character i
(which aborts insert mode when there's no such character)o
: new line below the cursor and insert textIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With