ex(vim)为空线添加了额外的空间字符
我想对EX(在EX/Silent Mode中的VIM)进行一些处理。但是,如果一条线是空的,则存在一种奇怪的行为。即使在二进制模式下,也将额外的空间字符添加到该行中。可以消除这一点吗?
查看:
$ printf "a\n1st\n\n3rd\n.\n%%p\n" | ex -b | hexdump -C
00000000 31 73 74 0a 20 0a 33 72 64 0a
注意printf中的ex行:a
用于附加文本,三行,。
以关闭附加模式,%p
以打印所有内容)
a
1st
3rd
.
%p
预期的结果是
00000000 31 73 74 0a 0a 33 72 64 0a
I would like to do some processing with ex (vim in ex/silent mode). There is however a strange behaviour if a line is empty. An extra space character is added to that line - even in binary mode. Is it possible to eliminate that?
Check out:
$ printf "a\n1st\n\n3rd\n.\n%%p\n" | ex -b | hexdump -C
00000000 31 73 74 0a 20 0a 33 72 64 0a
Note the Ex rows in printf: a
for appending text, three rows, .
to close append mode, %p
to print everything)
a
1st
3rd
.
%p
The expected result is
00000000 31 73 74 0a 0a 33 72 64 0a
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
printf
似乎并不是额外空间到来的地方:ex
似乎也不涉及,至少以更多的“正常”方式使用:但是您不会这样使用
ex
。您以某种方式将一种屏幕转储到stdout
中,可能会解释该空间的外观。在不知道您实际要做的事情的情况下,很难提供更好的解决方案。无论如何,作为面向文档的程序,
ex
通常不适合在管道中使用,因此您可能需要寻找其他方法。printf
doesn't seem to be where that extra space comes:ex
doesn't seem to be involved either, at least used in a somewhat more "normal" way:but you are not using
ex
that way. You are somehow making a kind of screen dump tostdout
, which might explain the appearance of that space.Without knowing what you are actually trying to do it is hard to provide a better solution. In any case, being a full screen document-oriented program,
ex
is generally not suited for use in a pipe so you might want to look for a different approach.