Closed cjlarose closed 5 years ago
The biggest goal is compatibility to Vim. And the result of Vim actually never ends without a \n
. So, no matter whether the register is set to either foo
or foo\n
, --remote-expr
will print the same. There's no way to distinguish it and you wouldn't know when to use -n
.
And adding options come with a cost and in this case it solves a very special use case. It seems you want to use it often anyway, so please go on using an alias or wrapper script (taking the above gotcha into account).
Thanks anyway!
nvr --remote-expr "$expr"
will always add a trailing newline character when printing the output it got from thenvim
server. This is usually fine, but there are use cases where this behavior is really inconvenient.For example, if I wanted a program that read the contents of my
"
register and print it out tostdout
, it's tempting to writebut this doesn't quite work since if I yank a single word (
yw
), and try to print it with this program, the program writes to stdout a newline character at the end. If you're usingbash
or a another POSIX-compatible shell, you might try to work around this problem using command substitution like so:This program solves the single-word yank case, but fails in a different case. The problem here is that command substitution will always remove all trailing newline characters produced by the command. So, if I yank a whole line (
yy
), this new program actually removes newline characters that are significant.It's possible to write a program that correctly gets the entire output from
nvr
, then removes the final (and only the final) newline character, but it is cumbersome:What I think would be convenient is the ability to get the unmodified output from the call to
eval
, without anything added. This PR adds the-n
option, which tries to accomplish this.-n
here mirrors the behavior of the builtinecho
, sinceecho -n
will not print a trailing newline.With this change,
does exactly what it did before (print a newline at the end), but
instead reproduces the output verbatim from the call to
eval
.