Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

copying text from vim to windows

Tags:

vim

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

like image 988
smauel Avatar asked Mar 03 '09 12:03

smauel


People also ask

How do I copy text from vim?

In vim command mode press v , this will switch you to VISUAL mode. Move the cursor around to select the text or lines you need to copy. Press y , this will copy the selected text to clipboard. Go to any external application and CMD + v to paste.

How do I select and copy text in vim?

Press v to begin character-based visual selection, or V to select whole lines, or Ctrl-v or Ctrl-q to select a block. Move the cursor to the end of the text to be cut/copied. While selecting text, you can perform searches and other advanced movement. Press d (delete) to cut, or y (yank) to copy.

How do I copy text from VI to clipboard?

Another easy way to copy the entire file if you're having problems using VI, is just by typing "cat filename". It will echo the file to screen and then you can just scroll up and down and copy/paste.

How do I enable copy and paste in vim?

You can use :set mouse& in the vim command line to enable copy/paste of text selected using the mouse. You can then simply use the middle mouse button or shift insert to paste it.


6 Answers

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 "+

like image 50
George V. Reilly Avatar answered Oct 15 '22 10:10

George V. Reilly


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).

like image 32
Konrad Rudolph Avatar answered Oct 15 '22 08:10

Konrad Rudolph


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
like image 37
sjh Avatar answered Oct 15 '22 08:10

sjh


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.

like image 32
Mykola Golubyev Avatar answered Oct 15 '22 10:10

Mykola Golubyev


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.

like image 40
Taurus Olson Avatar answered Oct 15 '22 09:10

Taurus Olson


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
like image 39
Zhe M. Avatar answered Oct 15 '22 08:10

Zhe M.