以下命令成功启动vim,从标准输入读取编辑缓冲区。
echo hi | vim -
但是这个不起作用。
echo hi | vim --remote-tab-silent -
运行上述命令时,会出现以下警告并退出vim。
Vim: Warning: Input is not from a terminal
Vim: Error reading input, exiting...
Vim: preserving files...
Vim: Finished.
为什么在第二种情况下不能从标准输入读取?
vim的帮助信息似乎表明它应该有用吗?
$ vim -h | head
VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Mar 31 2015 23:36:07)
usage: vim [arguments] [file ..] edit specified file(s)
or: vim [arguments] - read text from stdin
or: vim [arguments] -t tag edit file where tag is defined
or: vim [arguments] -q [errorfile] edit file with first error
Arguments:
-- Only file names after this
-g Run using GUI (like "gvim")
$ vim -h | grep remote
--remote <files> Edit <files> in a Vim server if possible
--remote-silent <files> Same, don't complain if there is no server
--remote-wait <files> As --remote but wait for files to have been edited
--remote-wait-silent <files> Same, don't complain if there is no server
--remote-tab[-wait][-silent] <files> As --remote but use tab page per file
--remote-send <keys> Send <keys> to a Vim server and exit
--remote-expr <expr> Evaluate <expr> in a Vim server and print result
答案 0 :(得分:2)
使用--remote
时无法从 stdin 进行编辑。
:h --remote
--remote [+{cmd}] {file} ...
Open the file list in a remote Vim. When
there is no Vim server, execute locally.
There is one optional init command: +{cmd}.
This must be an Ex command that can be
followed by "|".
The rest of the command line is taken as the
file list. Thus any non-file arguments must
come before this.
You cannot edit stdin this way |--|.
The remote Vim is raised. If you don't want
this use >
vim --remote-send "<C-\><C-N>:n filename<CR>"
--remote-silent [+{cmd}] {file} ...
As above, but don't complain if there is no
server and the file is edited locally.
--remote-tab-silent Like --remote-silent but open each file in a
new tabpage.