Qiang Li
Qiang Li

Reputation: 10865

vim copy/paste from system clipboard

hi I have macOS High Sierra, and vim with the version VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Jul 26 2017 19:10:24)

I used to be able to copy a text like :%s/abc//g into system clipboard, and go to a terminal where vim is current editing a file, and paste by doing cmd+v, and then it will just run in normal mode to do the full-text replacement.

However, I find now that this process will just paste the text :%s/abc//g in the file currently being edited, seemingly in the insert mode.

How can I get back the behavior of normal mode? Tried :set nopaste without any luck.

Upvotes: 3

Views: 18598

Answers (2)

Moshe Reubinoff
Moshe Reubinoff

Reputation: 307

Try the Plug vim-system-copy. I found it very helpful for me.

Upvotes: 0

Mateen Ulhaq
Mateen Ulhaq

Reputation: 27271

Method 1

  1. Enter command mode by typing :.
  2. Now execute <C-r>+ to paste from clipboard.
  3. Hit enter.

Method 2

  1. In normal mode, type q: to enter command history mode.
  2. Paste using "+p.
  3. Hit enter.

You might even consider creating a mapping.

" Paste to command mode while in insert mode.
inoremap <C-v> <C-o>:<C-r>+

" Not recommended. You can't go into Visual Block mode anymore.
nnoremap <C-v> <C-o>:<C-r>+

Upvotes: 5

Related Questions