Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to select all and copy in vim?

Tags:

vim

how to select all and copy in vim insert mode? and is there another way to do it in normal mode?

I have tried visual mode and gg and shift + gg to select all and then yank, however that doesn't transfer it to the clipboard to be able to paste it in another application like skype or chrome browser.

I am sure this is a common task, and there are a lot of varieties by smarter ppl than me out there, please feel free to share yours.

like image 304
zotherstupidguy Avatar asked Mar 25 '13 08:03

zotherstupidguy


People also ask

How do I select all in Vim?

If you want to select the entire line in a file, press V. Now when you press k or j to go up and down, vim will select the entire line above and below your cursor.

How do I select and copy 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 select all and copy to clipboard in Vim?

Use $yy To Select and Copy All There is an alternative way that can be used to select and copy all content. The yy command is used to yank or copy the current line but providing the line count we can select and copy all lines. First change to normal mode with the ESC.


2 Answers

In normal mode:

gg"+yG

In ex mode:

:%y+

like image 177
swpd Avatar answered Sep 22 '22 16:09

swpd


There are a few important informations missing from your question:

  • output of $ vim --version?
  • OS?
  • CLI or GUI?
  • local or remote?
  • do you use tmux? screen?

If your Vim was built with clipboard support, you are supposed to use the clipboard register like this, in normal mode:

gg"+yG 

If your Vim doesn't have clipboard support, you can manage to copy text from Vim to your OS clipboard via other programs. This pretty much depends on your OS but you didn't say what it is so we can't really help.

However, if your Vim is crippled, the best thing to do is to install a proper build with clipboard support but I can't tell you how either because I don't know what OS you use.

edit

On debian based systems, the following command will install a proper Vim with clipboard, ruby, python… support.

$ sudo apt-get install vim-gnome 
like image 42
romainl Avatar answered Sep 23 '22 16:09

romainl