为什么“定位文件名|xargs vim"导致奇怪的终端行为? [英] Why does "locate filename | xargs vim" cause strange terminal behaviour?

查看:44
本文介绍了为什么“定位文件名|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 一起使用.

解决方案

Vim 期望连接到真正的终端并发送相应的代码.

重置终端

重置

最简单的解决方法:

locate 50local.policy |xargs gvim

<块引用>

基本原理 gui vim 不需要终端

否则:

vim $(locate 50local.policy)

<块引用>

基本原理 vim 启动时直接连接到终端(而不是作为 xargs 下的子进程,后者又在子 shell 中运行标准输入/标准输出连接到管道而不是终端).就像在说

vim/usr/some/dir/50local.policy/usr/local/some/dir/50local.policy

或者

您可以通过不以参数启动 vim,而是从 vim 添加参数来避免该问题!事实上,Vim 在运行 shell 方面比 shell 在运行 vim 方面要好得多.

在 vim 中:

:args `locate 50local.policy`:倒带

这将参数列表设置为在滴答声之间从 shell 命令返回的文件;:rewind 然后转到该列表中的第一个文件.如果您正在编辑多个匹配项,请尝试以下操作:

:w|next

这一系列命令(以 | 分隔)将当前缓冲区写入文件,然后转到 args 列表中的下一个文件.

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.

解决方案

Vim expects to be connected to a real terminal and sends codes appropriate to that.

Reset the terminal with

reset

The easiest workaround:

locate 50local.policy | xargs gvim

Rationale gui vim doesn't require a terminal

Otherwise:

vim $(locate 50local.policy)

Rationale vim is started directly connected to the terminal (instead of as a child process under xargs which in turn runs in a subshell with stdin/stdout connected to pipes instead of a terminal). It is like saying

vim /usr/some/dir/50local.policy /usr/local/some/dir/50local.policy

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:

:args `locate 50local.policy`
:rewind

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:

:w|next

This sequence of commands (separated by |) writes the current buffer to file, then goes to the next file in the args list.

这篇关于为什么“定位文件名|xargs vim"导致奇怪的终端行为?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆