Reputation: 110163
A common pattern I find myself doing in a non-vim text editor is:
Cmd
a
Cmd
c
to copy all the content in the entire file, and then open a new file and
Cmd
v
to then paste in all that content. When all is said and done, I can usually do this entire copy-paste in about 0.5s. What would be the most common/efficient way to do this in vim?
Upvotes: 4
Views: 9744
Reputation: 2857
I do the same quite often by running the following commands: ggVGy
.
The first command, gg
, jumps to the beginning of the file. Then we select the entire first line with V
. Still in visual mode, we jump to the end of the file with G
, before copying (yanking) everything with y
.
You can make this even faster and easier by mapping all of these commands to one key. With the mapping below, pressing the leader key and X will copy the entire file.
nnoremap <leader>X ggVGy
If you need the content to be available to the system clipboard, and not only in Vim, you should use "+y
instead of y
. This will yank to the "+
register used for the system clipboard. You can find more information on this topic in this question.
Upvotes: 3