2

I would like to setup a command to yank the whole file without moving the cursor.

Here is the macro I created:

qaggVGy

However, this moves the cursor to the beginning of the file. How can I yank the whole file without losing the cursors position ?

verdammelt
  • 922
  • 10
  • 22
edi9999
  • 19,701
  • 13
  • 88
  • 127
  • 1
    Do you mean /page/ or /file/? Your macro yanks the entire file. – verdammelt Jan 13 '14 at 20:49
  • What do you want to do with that yanked text? – romainl Jan 13 '14 at 21:20
  • I want to paste it on an other window. I have set up + as the default yank register – edi9999 Jan 14 '14 at 10:53
  • In general, if you want to execute some commands and then return the cursor to its previous position, just set a mark before running the commands `m'` then return to the mark at the end `\`'`. Just add those characters to the beginning and end of your macro. – lwassink Jul 11 '16 at 15:48

1 Answers1

19

I usually use :%y+ to yank the complete file into the system clipboard. You can of course use any other register as you like.

Christian Brabandt
  • 8,038
  • 1
  • 28
  • 32