copying text from vim to windows
Asked Answered
B

8

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

Bordelon answered 3/3, 2009 at 12:34 Comment(0)
B
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).

Breger answered 3/3, 2009 at 12:36 Comment(6)
I believe that should read "* (quote for selecting buffer, asterix for system clipboard), or am I mistaken?Corron
You are mistaken - search for "cliboard" in the gvim helpWoodcraft
Sorry, ignore that - I guess the answer is you can use both!Woodcraft
@konrad if you are talking to me, I actually upvoted you. My comments were directed @roe. Gosh, I wish these comments were threaded!Woodcraft
Can someone explain how to type this command? I tried different combinations, and it says "Mark not set"Villiers
@ThomasSebastian It's a double quote not a single quote. You need to hold Shift while you type the first character (at least on a standard US keyboard), same with the +.Stack
S
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 "+

Strident answered 10/3, 2009 at 7:28 Comment(0)
B
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).

Breger answered 3/3, 2009 at 12:36 Comment(6)
I believe that should read "* (quote for selecting buffer, asterix for system clipboard), or am I mistaken?Corron
You are mistaken - search for "cliboard" in the gvim helpWoodcraft
Sorry, ignore that - I guess the answer is you can use both!Woodcraft
@konrad if you are talking to me, I actually upvoted you. My comments were directed @roe. Gosh, I wish these comments were threaded!Woodcraft
Can someone explain how to type this command? I tried different combinations, and it says "Mark not set"Villiers
@ThomasSebastian It's a double quote not a single quote. You need to hold Shift while you type the first character (at least on a standard US keyboard), same with the +.Stack
M
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
Masterly answered 3/3, 2009 at 16:48 Comment(0)
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.

Permission answered 3/3, 2009 at 13:40 Comment(4)
"*y? that is "quote - asterisk - y"?Palua
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 …Breger
(cont'd) … uses an “own” command key (across all applications!) while Windows and Linux GUIs use the control key).Breger
@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.Permission
L
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.

Lilith answered 3/3, 2009 at 22:53 Comment(0)
E
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
Entrails answered 21/4, 2017 at 10:3 Comment(0)
P
0

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

Principium answered 14/12, 2011 at 23:19 Comment(0)
S
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>
Shameful answered 22/4 at 8:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.