27

I am trying to copy a selection of text from vim to another windows application...say firefox or notepad for example. However I can't seem to do this with the y command. I have windows hotkeys enabled so by pressing ctrl-c I can achieve this but was hoping to get rid entirely of these windows commands in Vim.

Is this possible? also what about vice versa copying from windows and pasting into vim

0

8 Answers 8

32

I have

set clipboard=unnamed

in my ~/.vimrc. Then "yy", "D", etc, yank directly to the Windows clipboard. It also works in MacVim. For Linux gvim, you have to remember to prefix these operations with "+

0
20

I don't see any harm in using Windows command keys in GVim. Alternatively, you can also use the hotkey "+y for yanking (copying) and "+p for pasting to and from the system clipboard. This works on most platforms (Vim instances that are not directly attached to an X server on unix are a bit more difficult).

6
  • 1
    I believe that should read "* (quote for selecting buffer, asterix for system clipboard), or am I mistaken?
    – falstro
    Commented Mar 3, 2009 at 12:52
  • You are mistaken - search for "cliboard" in the gvim help
    – anon
    Commented Mar 3, 2009 at 13:54
  • Sorry, ignore that - I guess the answer is you can use both!
    – anon
    Commented Mar 3, 2009 at 13:59
  • 1
    @konrad if you are talking to me, I actually upvoted you. My comments were directed @roe. Gosh, I wish these comments were threaded!
    – anon
    Commented Mar 3, 2009 at 16:57
  • Can someone explain how to type this command? I tried different combinations, and it says "Mark not set" Commented Jun 26, 2016 at 5:01
10

as per above answers:

"*y
"*p

Using ctrl-v will make entering control characters tough in insert mode, and ctrl-v is visual-block in normal mode, although so is ctrl-q.

Personally have found the following quite natural & little finger friendly

vmap <a-c> "*y 
imap <a-p> "*p
8

Don't use windows bindings as you then won't be able to be as good in Vim on other platforms.

Use "*y - copy to system clipboard. It works well on Mac Os, Windows, Linux.

4
  • "*y? that is "quote - asterisk - y"?
    – innaM
    Commented Mar 3, 2009 at 14:44
  • I don't agree with your reason not to use the Windows binding. Besides the fact that a text editor is not an operating system (except for these emacs users out there) and that UI idioms change from OS to OS anyway, Command+C is actually the same across all systems known to me (even though OS X … Commented Mar 3, 2009 at 14:52
  • (cont'd) … uses an “own” command key (across all applications!) while Windows and Linux GUIs use the control key). Commented Mar 3, 2009 at 14:53
  • 1
    @Konrad: why should we make our life more complicated and get used to different key bindings among OSes if Vim already gives us all we need. Commented Mar 3, 2009 at 15:17
3

If you want to copy from a window (or from vim), try :

:set paste

But be careful other options may be modified. Everything is detailed in :

:help paste

Hope it helps.

2

For Windows 7, you need to edit the vim config file at:

C:\users\<User>\vimfiles\vimrc

just add the following line to the config file:

set clipboard=unnamed
0

Save the file, open it in another editor that uses standard Windows conventions, then copy and paste as you usually would.

0

To paste into Vim using Alt-P when using a Powershell terminal I added this line to my _vimrc file.

nnoremap <A-p> :r!powershell.exe Get-Clipboard<CR>

Not the answer you're looking for? Browse other questions tagged or ask your own question.