为什么“定位文件名|” xargs vim”导致奇怪的终端行为?
当我执行“locate 50local.policy | xargs vim”时,出现错误“Vim: Warnung: Die Eingabe kommt nicht von einem Terminal”(翻译:Vim:警告:输入不是来自终端)。
我可以使用 vim 成功编辑,但关闭它后,我的终端表现得很奇怪(我无法输入字母,当我按 Enter 键时,shell 提示符会重复出现。 当我使用“xargs gedit”执行此操作时,它不会产生这些问题。
我将 Ubuntu 11.10 与 Gnome 3 和 Gnome-Terminal 3.0.1 一起使用。
When I do "locate 50local.policy | xargs vim", I get the error "Vim: Warnung: Die Eingabe kommt nicht von einem Terminal" (translation: Vim: Warning: The input does not come from a terminal).
I can edit successfully with vim but after I close it my terminal behaves strangely (I can't type letters and when I hit enter the shell prompt simply gets repeated.
When I do it with "xargs gedit" it does not create those problems.
I use Ubuntu 11.10 with Gnome 3 and Gnome-Terminal 3.0.1.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Vim 期望连接到真实终端并发送适合该终端的代码。
使用最简单的解决方法重置终端
:
否则:
或者,
您可以通过不使用参数启动 vim,而是从 vim 添加参数来避免这个问题!事实上,Vim 在运行 shell 方面比 shell 在运行 vim 方面要好得多。
在 vim 中:
这会将参数列表设置为从刻度之间的 shell 命令返回的文件; :rewind 然后转到该列表中的第一个文件。
如果您正在编辑多个匹配项,请尝试以下操作:
此命令序列(用 | 分隔)将当前缓冲区写入文件,然后转到 args 列表中的下一个文件。
Vim expects to be connected to a real terminal and sends codes appropriate to that.
Reset the terminal with
The easiest workaround:
Otherwise:
Alternatively
You can dodge the issue by not starting vim with the arguments, but adding the arguments from vim! Vim is in fact a lot better at running shells than shells are at running vim.
Whilst in vim:
This sets the argument list to the files returned from the shell command between the ticks; :rewind then goes to the first file from that list.
If you were editing multiple matches, try this:
This sequence of commands (separated by |) writes the current buffer to file, then goes to the next file in the args list.
另一种替代方法是使用
-o
选项执行xargs
。从手册页:注意,
-o
是 xargs 的 BSD 扩展。达到相同效果的更便携的方法是:
An other alternative is to execute
xargs
with the-o
option. From the man page:Note,
-o
is a BSD extension to xargs.A more portable means to achieve the same effect is:
虽然“重置”可以解决问题,但您还可以使用以下命令显式地重新激活回显行为:
While 'reset' fixes the problem, you can also explicitely re-activate the echo behaviour with: