Search code examples
vimneovim

Using expression register without <C-r> in vim script


I have a vim script that I am currently running with nvim -s commands.txt file.txt. I am trying to do something in the expression register with this script and I do not know how I can access it without the control key. I tried stuff like this:

:insert <C-r>=<C-r>"<Enter>

and even stuff like this:

^R=^R"

but to no avail. All help is appreciated thanks.


Solution

  • -s option requires data entered "as one types". That is, :h recording by "macro". Otherwise, you have to translate all the stuff into binary keycodes yourself. In particular, "control-r" becomes byte #18 etc.etc.

    So it is always preferred to create ordinary VimScript file and use :h :normal when one needs to simulate key presses. Or, at least, prepare the file by "recording" feature. Trying to "compile into binary" by hand is no good.