I have a file called test
, I open it using vi as such:
vi test
Now I want to insert a line through a shell command, for simplicity I use a printf
:
:r! printf %s hello
However the line that is entered is
tests
i.e. the name of the file with a s
appended.
If I enter the same command in terminal directly, it works fine.
What I want to do is ultimately be able to encode a string in base64 and enter it on the same line as where my cursor is in vi, so that I won't have to copy the string in a separate terminal, encode it, and copy it back into vi. How can I do this? What am I doing wrong?
The first stage of processing a command line in vim
is expand
ing it. %
is expanded to the name of the current file — test
in your case. %s
is expanded to tests
.
To avoid expanding protect the special character with a backslash:
:r! printf \%s hello