How to write buffer content to stdout?

后端 未结 9 1715
执笔经年
执笔经年 2020-12-09 01:54

Is there any chance to write the content of the current vim buffer to stdout?

I\'d like to use vim to edit content that was passed via stdin - without the need of a

相关标签:
9条回答
  • 2020-12-09 02:34

    I think :w !tee would work perfectly,

    0 讨论(0)
  • 2020-12-09 02:35

    You can also use pipe.vim. It does use a temporary file, but at least you don't have to worry about it in your own script.

    To the second part of your question, you use the -s command line option with vim to remap :w to something else (like :w !tee).

    0 讨论(0)
  • 2020-12-09 02:37

    Since you use Linux/Unix, you might also be interested in trying out moreutils. It provides a command called vipe, which reads from stdin, lets you edit the text in $EDITOR, and then prints the modified text to stdout.

    So make sure you set your editor to Vim:

    export EDITOR=vim
    

    And then you can try these examples:

    cat /etc/fstab | vipe
    cut -d' ' -f2 /etc/mtab | vipe | less
    
    0 讨论(0)
提交回复
热议问题