V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
codeplay
V2EX  ›  Vim

VI,VIM 如何使用管道?

  •  
  •   codeplay · Feb 23, 2013 · 7416 views
    This topic created in 4811 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
        1
    liwei  
       Feb 23, 2013 via iPad   ❤️ 2
    vim -
    luin
        2
    luin  
       Feb 23, 2013
    ls -lrt |vim -
    Mutoo
        3
    Mutoo  
       Feb 23, 2013
    ls -lrt | vim -
    napoleonu
        4
    napoleonu  
       Feb 23, 2013
    ls | xargs vim # 同时打开多个文件
    :n [file_name] #切换文件
    napoleonu
        5
    napoleonu  
       Feb 23, 2013
    哦,我理解错了。不好意思。
    codeplay
        6
    codeplay  
    OP
       Feb 23, 2013
    @liwei
    @luin
    @Mutoo
    @napoleonu

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

    比如你可以写个程序看到参数里有-就去读标准输入,你也可以写个程序直接读标准输入。。
    Mutoo
        8
    Mutoo  
       Feb 23, 2013   ❤️ 1
    @codeplay vim 本身没有直接从 stdin 读入信息。而 - 参数相当于一个开关,表示从标准输入读入信息。而管道的功能就是把前一个程序的 stdout 作为下一个程序的 stdin
    wanghui
        9
    wanghui  
       Feb 24, 2013   ❤️ 1
    @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   ·   Solana   ·   4884 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 78ms · UTC 09:54 · PVG 17:54 · LAX 02:54 · JFK 05:54
    ♥ Do have faith in what you're doing.