Reputation: 2055
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..
Upvotes: 36
Views: 29032
Reputation: 593
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.
Upvotes: 29
Reputation: 289
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.
Upvotes: 1
Reputation: 642
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.
Upvotes: 1
Reputation: 771
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.
Upvotes: 3
Reputation: 3487
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.
Upvotes: 18
Reputation: 678
To select the whole file you can jump to the beginning, start visual mode, jump to the end:
ggVG
Upvotes: 1