I want to select all the text from the vim editor, I tried the command :%y+
but getting error E850: Invalid register name
. I get this command from this link. Please help me how to copy all the text from file which is open in vim. They are using yank, what is meaning of it..

- 3,274
- 1
- 15
- 24

- 2,025
- 6
- 31
- 49
-
2You want to select the text, or search it? – Andy Ray Jun 15 '15 at 06:28
-
You need to have a graphical Vim such as MacVim or gVim, or terminal Vim compiled with `+xterm_clipboard` (see `vim --version`), in order to use `+` register. What exactly are you trying to do? – Amadan Jun 15 '15 at 06:30
-
Try nano instead of Vim. – romainl Jun 15 '15 at 07:20
-
What are you trying to do, really? You are using a "yank" (i.e. "copy") command, when you say you want to "select" the text, but then you ask how to "search" the text. Those are 3 different tasks! – Ben Jun 15 '15 at 15:36
-
@Ben, sorry I meant select not search. please up vote.. – geeks Jun 15 '15 at 15:41
-
@AndyRay , sorry I meant select not search. please up vote. – geeks Jun 15 '15 at 15:42
-
1OK, that clears one thing up. But, *why* do you need to do a visual selection from the command-line? What do you want to do with that selection? – Ben Jun 15 '15 at 16:24
6 Answers
I had a similar problem. Don't know why you got so many down votes.
The problem is that you haven't installed vim-gnome
which takes about 24 MB and adds a feature to the inbuilt vim.
sudo apt-get install vim-gnome
then your command will work. :%y+
This command will copy all the text in system's clipboard.

- 4,273
- 1
- 20
- 38

- 583
- 7
- 23
-
This is the correct answer, thank you! So many people saying to use `*` or `+` oblivious to the fact that without this, these registers will just beep or say `Invalid register name`. – melissa_boiko Mar 22 '18 at 17:04
-
Great answer. To copy all lines it's `%y+`. [link](https://stackoverflow.com/questions/1620018/copy-all-the-lines-to-clipboard) – Scott123180 May 26 '18 at 12:06
-
A quick note for ubuntu 19+ users: `vim-gnome` is no longer there, but `vim-gkt3` does basically the same. – Tooster Feb 07 '23 at 15:36
TLDR: If you want to copy text in Vim to the system clipboard type ggVG"*y. Explanation below...
Vim runs in the terminal and, depending upon how you are using it and which type of Vim you are running, it's not really designed for you to select text with a mouse and copy and paste in the traditional way.
If you want to select all of the text using Vim then use ggVGy (note the uppercase VG in the middle). This command moves the cursor to the top of the file, enters visual mode, moves to the bottom of the file (thus, selecting all of the text) and then yanks (copies) it. You can then use p to put (paste) this code but only inside of Vim.
If you want to copy to the clipboard to use somewhere outside of Vim then try this:
First, select everything using the commands outlined above but without the final y: (ggVG). Then press "*y. This should now copy it to your operating system's clipboard and you can just paste (Ctrl/Cmd+v) anywhere you want outside of Vim. This can vary depending on what settings you have for Vim but it should work.
A brief explanation of the commands used. gg goes to the top of the file. V enters visual mode by lines. G goes to the end of the file. y yanks (copies) the text but not to the clipboard. p puts (pastes) the text.
The more advanced (i.e. cool) stuff:
" allows you to access registers. For example "a provides access to register a.
The *
is the system clipboard so "*
provides access to the system keyboard. Therefore, "*y
yanks into the system clipboard.

- 3,389
- 23
- 39
-
great answer ggVG"*y from http://vim.wikia.com/wiki/Accessing_the_system_clipboard – jazzyfresh Sep 18 '15 at 00:09
While there's a great explanation of how to exploit the system clipboard in vim, it sounds like you're just having trouble getting your vim to access the clipboard in the first place. Try installing vim-gnome, it gives you the packages you need to get to the system clipboard.
For some reason, "* didn't work for me, but the exact same command with the "+ register did.

- 751
- 1
- 6
- 11
To select the whole file you can jump to the beginning, start visual mode, jump to the end:
ggVG

- 668
- 1
- 8
- 19
This question is a few years old now, but I had this same problem on Linux Mint 18. I found using xclip
worked for me. You can map the command vmap <F7> :!xclip -sel c<CR><CR>
in your .vimrc to have your current selection in visual mode copied to the system clipboard.
Here is a thread containing the above (and other) solutions.

- 1
- 1

- 592
- 5
- 13
You can use
Vggy/vggy or,
VGy/VGy
To visually select any number of text and then copy it, in your case it is gg / G as you want all text on the file,
gg is to copy while your cursor is at bottom of the file, gg for go to top
G is to copy while your cursor is at top of the file
Or even you can always use
Vk(as number of time)y to copy the selected lines of text.

- 1
- 1

- 273
- 2
- 10