Using VI tool for editing config files.
How can I select all the text in a file (around 1000 lines), copy it, then paste into Google Docs?
The simplest and fastest way is to use: : % y + and then go over to Google Docs (or wherever) and paste. Explanation:
Another way is g g " + y G but you will likely admit that the above is faster and easier.
Many given replies also yank the selection, which I was not looking for.
I'm using ggVG for this purpose (needs to be run on normal mode). This command only selects the whole text inside the document.
I've even remapped Ctrl+A for this purpose, since I don't really need to increment an integer with the shortcut (default Ctrl+A map).
Just add this into your .vimrc:
map <C-a> <esc>ggVG<CR>
It has <esc> first, to make sure the user is in normal mode.
ggVG, but gg0vG$ might be more appropriate since it more closely replicates the 'normal' Ctrl+A operation.
– Sheharyar
Sep 22 '16 at 12:02
You can use cat file and then select output and copy and paste if you need to paste it into your browser.
For vi this is how you can select all text and write it into a new file:
shift v -- visual mode
shift g -- jump to eof
"*y -- yank select text
:e my_new_file -- create a new file
"*p -- paste into a new file
In theory this should work on both Linux and Windows - I tried it on a Mac but it doesn't work.
cat file is the way to go. The shift v method only copies to Vi's internal buffer.
– Aleksandr Levchuk
Dec 30 '10 at 17:31
I am using Vim 7.4 in CentOS-7 environment. Which worked me for selecting all the text is
:%y
Then just p in the next file where I want a full copy.
Or
You can use cat command.
cat copyfile > pastefile
This git repo has some other useful commands too.
gg"+yG
or
gg"*yG
depending on whether + or * is the system clipboard. (On many unixes, + is the mouse selection buffer for middle-mouse-clicking, and * is the system clipboard).
For a Mac, use pbcopy (pasteboard copy):
cat file.txt | pbcopy
The contents of file.txt are now on the clipboard for pasting into another application (e.g. browser).
You can also paste the contents of the clipboard into a file using pbpaste:
pbpaste > file.txt
While this doesn't involve vi specifically it does achieve the same goal on a Mac.
If you're using a linux desktop, you could load it into the clipboard using xclip or xsel. For something that size you might just want to use the upload feature in google docs.
Another way would be:
You press v key on your keyboard and turn VIM to VISUAL
Then select all text by scrolling down
^+ INSERT to copy
SHIFT +INSERT to paste the text wherever you want on Google Docs.
See http://vim.wikia.com/wiki/Accessing_the_system_clipboard for options on how to do this. (if compiled in "* should refer to the system clipboard). There are also instructions there for how to use xsel with vim.
Use the following command.
cat <your file name>
It will echo the content of file. Now select, scroll, copy, paste.
Game Over
Ex.:
cat bobis.txt
:%y+– Jas Jun 22 '14 at 09:41:%p+should have worked too, but it doesn't ☹ – Hi-Angel Oct 07 '14 at 08:14set clipboard=unnamedin your .vimrc, you can simply use:%y– Zenadix Dec 09 '14 at 15:15:%y+, and i getE488: Trailing characters– johny why Jul 27 '16 at 20:51:versionand see if+clipboardis there (source) – Alexander Malakhov Sep 02 '16 at 09:54gvim, or better, NeoVim (for all its performance improvements) – oligofren Jun 23 '17 at 12:33:sp file2_name, you can past it with p. And I still think there has to be a better way to do it. – user10089632 Feb 14 '18 at 07:53: % + yand not: % y +(note the position of the plus symbol). Hope that saves someone a few agonising minutes. [credits to RL] – Yannis Jul 11 '18 at 11:01Which means : <- Command mode, 1 <- line number 1 $ <- last line y <- yank
– mujjiga Jul 16 '18 at 10:00:%y *Note the space betweenyand*. – TransferOrbit Jan 12 '24 at 09:17