为什么没有“历史|vim"工作? [英] Why doesn't "history | vim" work?

查看:22
本文介绍了为什么没有“历史|vim"工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 Vim 查看 history 的结果(不在 shell 中).我想history |vim 可以工作(使用 history 的结果作为 vim 的输入),但它返回:

I want to use the Vim to see the result of history (not in the shell). I think history | vim will work (use the result of history as the input of vim), but it returns with:

$history | vim
Vim: Warning: Input is not from a terminal
Vim: Error reading input, exiting...

Vim: Finished.

有人能解释一下吗?

推荐答案

通过管道进入 vim,您正在更改标准输入流.因为 vim 是一个交互式程序,所以它需要标准输入作为控制台.

By piping into vim, you are changing the standard input stream. Because vim is an interactive program, it requires the standard input to be the console.

如果你想在 vim 中查看,你应该告诉它你正在从标准输入读取文件(通过提供参数 -):

If you want to view in vim, you should tell it you are reading the file from stdin (by supplying the argument -):

history | vim -

或者,您可以使用更多更少:

history | more
history | less

后两者更可取.如果你输入 vim,它会看到你的文件"有修改,所以你不能直接用 :q 命令退出.相反,您必须通过 :q! 强制退出,这有点笨拙.

These latter two are preferable. If you pipe into vim, it will see your "file" as having modifications, and so you can't quit with a straight :q command. Instead you have to force quit by :q!, which is a bit clunky.

另一方面,您只需输入q即可退出更多更少.查看这两个程序的手册页.你会经常使用它们.

On the other hand, you can exit more or less just by typing q. Have a look at the man-page for these two programs. You'll use them a lot.

正如 Russell Silva 在评论中所推荐的那样,当您从 stdin 读取时,您可以以只读模式打开 vim.只需提供 -R 参数.然后就可以正常退出了,不需要覆盖:

As recommended by Russell Silva in the comments, you can open vim in read-only mode when you read from stdin. Just supply the -R argument. Then you can quit normally without needing the override:

history | vim -R -

这篇关于为什么没有“历史|vim"工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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