How to copy all text from vim editor using vim command line?

I want to select all the text from the vim editor, I tried the command :%y+ , but I get the error E850: Invalid register name . I get this command from this link . Please help me how to copy all the text from a file that is open in vim. They use yank what that means.

+7
linux vim
source share
4 answers

I had a similar problem. I don’t know why you have so many votes. The problem is that you did not install vim-gnome , which takes about 24 MB and adds a feature to the built-in vim.

 sudo apt-get install vim-gnome 

then your team will work. %yy+ This command copies all text to the system clipboard.

+6
source share

TL; DR: If you want to copy the text in Vim to the system clipboard type g g V g " * y . Explanation below ...

Vim works in the terminal and, depending on how you use it and what type of Vim you use, it is not designed to select text with the mouse and copy and paste in the traditional way.

If you want to select all the text using Vim, use g g V g y (pay attention to the upper case V g in the middle). This command moves the cursor to the top of the file, switches to visual mode, moves to the bottom of the file (thus, selecting all the text), and then yanks (copies) it. Then you can use p to enter (insert) this code, but only inside Vim.

If you want to copy to the clipboard for use somewhere outside of Vim , try the following:

First select everything using the commands described above, but without the final y : ( g g V g ). Then press " * y . Now it should copy it to the operating system clipboard, and you can simply paste ( Ctrl / Cmd + V ) anywhere except Vim. This may vary depending on what settings you have for Vim but it should work.


A brief description of the commands used. g g goes to the beginning of the file. V goes into visual mode line by line. g comes to the end of the file. y yanks (copy) the text, but not to the clipboard. p puts (inserts) the text.

More advanced (i.e. cool) stuff:

" allows you to access the registers. For example, " a provides access to register a.

* is the system clipboard, therefore "* provides access to the system keyboard. Therefore, "*y occupies the system clipboard.

+5
source share

To select the entire file, you can go to the beginning, start the visual mode, go to the end:

ggVG

+1
source share

While there is a great explanation on how to use the system clipboard in vim, it looks like you are just having trouble getting your vim to go to the clipboard first. Try installing vim-gnome, it will give you the packages you need to get on the system clipboard.

For some reason, "* does not work for me, but the exact same command with the register" + "did.

+1
source share

All Articles