codeplay
V2EX  ›  Vim

VI,VIM 如何使用管道?

  •  
  •   codeplay · Feb 23, 2013 · 7852 views
    This topic created in 5004 days ago, the information mentioned may be changed or developed.
    ls -lrt |vim

    报错提示:
    Vim: Warning: Input is not from a terminal

    Error detected while processing /Users/xiang/.vimrc:
    line 1:
    E518: Unknown option: transparency=15
    Press ENTER or type command to continueVim: Error reading input, exiting...
    Vim: preserving files...
    9 replies  •  1970-01-01 08:00:00 +08:00
    liwei
    liwei
    Feb 23, 2013 via iPad❤️2
    1
    vim -
    luin
    luin
    Feb 23, 2013
    2
    ls -lrt |vim -
    Mutoo
    Mutoo
    Feb 23, 2013
    3
    ls -lrt | vim -
    napoleonu
    napoleonu
    Feb 23, 2013
    4
    ls | xargs vim # 同时打开多个文件
    :n [file_name] #切换文件
    napoleonu
    napoleonu
    Feb 23, 2013
    5
    哦,我理解错了。不好意思。
    codeplay
    codeplay
    OP
    Feb 23, 2013
    6
    @liwei
    @luin
    @Mutoo
    @napoleonu

    原理是什么呢?为什么more或者less不需要那个“-”呢?
    swulling
    swulling
    Feb 23, 2013
    7
    @codeplay 和具体程序的内部逻辑有关,没啥需要不需要的。。

    比如你可以写个程序看到参数里有-就去读标准输入,你也可以写个程序直接读标准输入。。
    Mutoo
    Mutoo
    Feb 23, 2013❤️1
    8
    @codeplay vim 本身没有直接从 stdin 读入信息。而 - 参数相当于一个开关,表示从标准输入读入信息。而管道的功能就是把前一个程序的 stdout 作为下一个程序的 stdin
    wanghui
    wanghui
    Feb 24, 2013❤️1
    9
    @codeplay 前不久刚好查过这方面资料

    Many commands use a hyphen (-) in place of a filename as an argument to indicate when the input should come from stdin rather than a file.

    man vim
    - The file to edit is read from stdin. Commands are read from stderr, which should be a tty.
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1084 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 23:43 · PVG 07:43 · LAX 15:43 · JFK 18:43
    ♥ Do have faith in what you're doing.