Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pasting to vim from clipboard cuts off first few lines

Tags:

vim

I'm using vim in terminal on OSX with a blank .vimrc file. I try to paste the following from my clipboard:

#!/bin/bash
set -e
set -o pipefail

npm run precommit

using

:set paste

but in vim, what's pasted (using cmd-v) is

et -e
set -o pipefail

npm run precommit

Anybody know what's wrong?

like image 685
kkSlider Avatar asked Mar 04 '14 22:03

kkSlider


People also ask

How do I paste properly in Vim?

That makes the default paste buffer map to X's clipboard. So, if I mark a bit of text in a terminal, I can simply press p to paste it in vim. Similarly, I can yank things in vim (e.g. YY to yank the current line into the buffer) and middle click in any window to paste it.

How do I paste from clipboard to Vim?

When using Vim under Windows, the clipboard can be accessed with the following: In step 4, press Shift+Delete to cut or Ctrl+Insert to copy. In step 6, press Shift+Insert to paste.


2 Answers

You have to enter into insert mode before you can edit the file, you can do this by pressing the i key.

like image 165
eugecm Avatar answered Oct 12 '22 03:10

eugecm


If you're using vim on OSX, you can add the following to your .vimrc:

set clipboard+=unnamed

Once you have done this, vim will use the system clipboard to read from by default for pasting. This means that, instead of having to enter insert mode first you can simply use p to paste. It also means that if you yank within vim, it's available to paste elsewhere.

I haven't tested this on any other OS, so if anyone has please feel free to add a comment...

like image 23
sanmiguel Avatar answered Oct 12 '22 03:10

sanmiguel