1

I can use 'yy' and 'p' to copy and paste in my Vim file, but when i copy some Python code from outside and try to do a 'p' in my Vim file it just pastes the last copied thing inside my Vim.

Is there anyway i can sync my vim and system clipboards ??

h1py
  • 193
  • 2
  • 9

5 Answers5

4

You can use the command below:

"+gP
pkacprzak
  • 5,537
  • 1
  • 17
  • 37
  • Doesn't seem to work when i do this in the esc mode it says Nothing in register g. – h1py Jan 19 '14 at 15:35
  • 1
    That's `"` followed by `+` followed by `g` followed by `p`. – romainl Jan 19 '14 at 15:40
  • 1
    @yappa the command is the quotation mark followed by the plus sign followed by the g letter followed by the capital P letter. Did you try this exactly? – pkacprzak Jan 19 '14 at 15:40
4

Add this to ~/.vimrc (create it if it doesn't exist):

set clipboard=unnamed

zonksoft
  • 2,400
  • 1
  • 24
  • 36
krystah
  • 3,587
  • 2
  • 25
  • 43
  • doesnt seem to work either, will i have to restart the system for it to come ion effect ?? – h1py Jan 19 '14 at 15:43
  • 1
    No, restarting Vim should be enough. You should take romainl's advice and check if your Vim has been compiled with clipboard support to achieve the desired behaviour. – krystah Jan 19 '14 at 15:47
  • yeah it did the trick. Restarted Vim and it now just works with the 'p' shortcut. Thanks. – h1py Jan 19 '14 at 15:52
3
  1. See if your Vim is built with clipboard support with this command, it should echo 1:

    :echo has("clipboard")
    
  2. If you get a 1, use "+p.

  3. If you get a 0, install a Vim built with clipboard support. MacVim is the most obvious choice.

romainl
  • 186,200
  • 21
  • 280
  • 313
0

From change.txt:

Selection and drop registers "*, "+ and "~
Use these registers for storing and retrieving the selected text for the GUI.
When the clipboard is not available or not working, the unnamed register ("") is used instead.

bPizzi
  • 975
  • 8
  • 12
0
   " map to paste from clipboard with Ctrl-Alt-p
   " put this mapping in your ~/.vimrc file
   nmap <C-M-P> "+p
   imap <C-M-P> <esc>"+pA

With this maps I have an easy way to past from outside.

SergioAraujo
  • 11,069
  • 3
  • 50
  • 40