1

In the ex linage of editors, one can append to a register(vim)/buffer(ex,vi) by specifying the register name in uppercase. As an example

g/pat/y A

will append every line match pat to register a. But if a already has content, it will need to be cleared first.

How?

In vim, one can do let @a = ''. But this depends on having a vim compiled with the expression evaluation feature +eval. One can also do qaq, to record nothing into a, but recording is disabled while executing a register, inside mappings or in :normal, so it does not lend itself to automating.

vi/ex has no let, and no q or 'recording' equivalent , so how is buffers(registers) cleared in practical use?

To my disappointment, :0y a put line 1 in a, so the only way I can gleam is doing "ay$ on an empty line. (EDIT: Apparently there is a discrepancy in how y$ works on empty lines between vim and vi)

Anything better?

11
  • 2
    What's wrong with +eval? If one does any "automating", he certainly should have it. Otherwise, use qaq interactively.
    – Matt
    May 12, 2020 at 11:06
  • @Matt I'm asking how this was done in ex/vi, which has append to register functionality but no +eval or q
    – aktivb
    May 12, 2020 at 11:12
  • "ay$ in an nvi does not clear the buffer for me. I suppose the easiest is to restart ex/vi, if you for some reason do not want to use vim. May 12, 2020 at 11:36
  • @ChristianBrabandt I only tested that in vim. Curiously, in busybox vi, "ay$ yanks until newline if the line is not empty, but yanks the newline if it is. What does it do in nvi, is it just a noop?
    – aktivb
    May 12, 2020 at 11:59
  • This works in Vim. Does it do in Vi too? 0"ayh
    – Matt
    May 12, 2020 at 13:10

1 Answer 1

2

So it turns out that all Vi clones are, well, different. For example, 0"ayh clears register "a" in Vim, but not in Elvis; while 0"ad0 works in Elvis, but not in Vim.

As Busybox seems to ship "Vi" of its own, you have no other choice than to experiment and to find the right keys yourself.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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