ex(vim)为空线添加了额外的空间字符

发布于 2025-02-09 18:05:27 字数 444 浏览 1 评论 0原文

我想对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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

千年*琉璃梦 2025-02-16 18:05:27

printf似乎并不是额外空间到来的地方:

$ printf 'a\n1st\n\n3rd\n.\n%%p\n' | hexdump -C
00000000  61 0a 31 73 74 0a 0a 33  72 64 0a 2e 0a 25 70 0a |a.1st..3rd...%p.|
00000010

ex似乎也不涉及,至少以更多的“正常”方式使用:

$ printf "a\n1st\n\n3rd\n.\nwzob\nq\n" | ex | hexdump -C zob
00000000  31 73 74 0a 0a 33 72 64  0a                       |1st..3rd.|
00000009

但是您不会这样使用ex。您以某种方式将一种屏幕转储到stdout中,可能会解释该空间的外观。

在不知道您实际要做的事情的情况下,很难提供更好的解决方案。无论如何,作为面向文档的程序,ex通常不适合在管道中使用,因此您可能需要寻找其他方法。

printf doesn't seem to be where that extra space comes:

$ printf 'a\n1st\n\n3rd\n.\n%%p\n' | hexdump -C
00000000  61 0a 31 73 74 0a 0a 33  72 64 0a 2e 0a 25 70 0a |a.1st..3rd...%p.|
00000010

ex doesn't seem to be involved either, at least used in a somewhat more "normal" way:

$ printf "a\n1st\n\n3rd\n.\nwzob\nq\n" | ex | hexdump -C zob
00000000  31 73 74 0a 0a 33 72 64  0a                       |1st..3rd.|
00000009

but you are not using ex that way. You are somehow making a kind of screen dump to stdout, 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文