I believe that the problem is not so much
that shell commands typically end with a newline,
but that read
is a line-oriented command
(i.e., an ex command).
It was present in the original version of ed
,
in the 1970s, before :r!command
existed,
and the common use case was to read a bunch of lines
(e.g., a C function or a paragraph of text)
from one file into another.
Most users would have wanted to insert them
as new, separate lines most of the time.
You can check / demonstrate this by doing :r!printf Tuesday
.
Even though the printf Tuesday
command doesn’t write a newline
(since you didn’t specify \n
),
you will get Tuesday
on a line all by itself.
Perhaps the simplest workaround is to do
i Enter Esc (to break the current line),
- or k to move back up a line,
then do your :r!command
,
and then J to Join
the lines back together.
If this is something you do very often,
it might be beneficial to map a macro for it.
Disclosure: I know vi
reasonably well,
but there’s lots of stuff in vim
that I haven’t learned.
There might be an easier way to do this in vim
.