Reply to message «Multiple commands to vim on command line, save output», sent 03:25:56 18 July 2011, Monday by Keith Christian:
> Below, I'd like to save the output of the "scriptnames" command in a
> file called "vim_output" and quit the editor with no further
> interaction, in order to examine the vim_output file later.
Use :redir to save outputs:
vim -c 'redir > vim_output' \
-c 'scriptnames' \
-c 'redir END' \
-c 'qa!'
> Is this possible without writing a VIM script? I don't see any way to
> issue three VIM commands from the command line. What is the command
> separator in this case, or is there one?
In all cases command separator is a bar. Read :h :bar before using it: you
can't
do it in all cases. You can also use newline as a command separator but it is
handled like in :execute: «vim -c $'normal! abc\ndef'» will insert «bc\ndef»
instead of complaining about :def being an unknown command while the same trick
with redir will work:
vim -c $'redir > vim_output\nscriptnames\nredir END\nqa!'
. The only way to make newline work like in a script file without actually
writing it is to use :function:
vim -c $'function RunNormal()\nnormal! abc\ndef\nendfunction' \
-c $'call RunNormal()\ndelfunction RunNormal\nqa!'
will complain about :def as expected (I don't know why it is necessary to put
:call in the next -c argument though). You can also use advanced shell
features:
in zsh
vim -S <(<<< '
redir > vim_output
scriptnames
redir END
qa!')
(for bash you should probably replace «<<<» with «echo»). What will be done you
will see in vim_output in this case: last script shown in output is
/proc/{PID}/fd/{Number}. More info in `man zshexpn', search for PROCESS
SUBSTITUTION there. In `man bash' you may search for `<\('.
Original message:
> What would be the command format to run three commands from a shell
> command line (e.g. BASH) to run a VIM command, save the output, and
> quit?
>
> Below, I'd like to save the output of the "scriptnames" command in a
> file called "vim_output" and quit the editor with no further
> interaction, in order to examine the vim_output file later.
>
> This doesn't work:
>
> vim +"scriptnames" +":w vim_output" +":q"
>
> Is this possible without writing a VIM script? I don't see any way to
> issue three VIM commands from the command line. What is the command
> separator in this case, or is there one?
>
> If I have to write a VIM script to do these three actions, is there a
> command line option to have VIM run a script to do these things, and
> then exit cleanly?
>
> Thanks.
signature.asc
Description: This is a digitally signed message part.
