2

I am actually stuck level 10 at vim-adventures, but this question concerns vim in general.

I have a new file with this content:

99 bottles of beer    

If I yank the line with "aY I get 99 bottles of beer<cr>, if I do "a0y$ I get 99 bottles of beer without the new line.

The question is how can I just append <cr> that I yank from somewhere into my registers?

  • 1
    If you can do "aYwhy don't you use it? – romainl Aug 24 '16 at 18:33
  • Because "aY will yank the whole line. I just need to yank the <cr> to append it to another register. – nowox Aug 24 '16 at 18:34
  • "will yank the whole line" - and that's exactly what you wanted! – VanLaser Aug 24 '16 at 21:14
  • Related: :put a will do a linewise put of register a. – Antony Aug 25 '16 at 9:24
2

One way is to use a capital "A" for the yank command which appends to the register instead of replacing it. So you would need to position your cursor on a blank line and then do "AY.

See :h quote for more info.

Another way to do it would be to run the following command:

:let @a = @a . "\n"

Registers can be address like variables with @ notation.

  • So you need a bank line. That what I need to find then. – nowox Aug 24 '16 at 18:33
1

Another option is to use the setreg() function:

:call setreg('a', "\n", 'a')

With the help of :h setreg():

  • The first parameter is the name of the register to modify
  • The second one is the string to put into the register
  • The third one is optional, if it contains a then the string is appended to the content of the register otherwise it replace the existing content.
1

There is setreg() method, you can not only modify the value of the register, but also the "mode" see :h setreg(.

you can just convert the char-based selection/yank to line-based selection/yank, without changing the value of @a:

:call setreg('a',@a,'V')

or

:call setreg('a',@a,'l')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.