If the 'infile.txt' is opened by another vim instance, you can
just "set noswapfile" in that instance, and then your command will
complete.
If the swapfile is just there because of a previous crash, then you
could just delete the swapfile and vim won't ask you again.
If however all fails, then just proceed with the following "brutal"
command.
vim -u NONE -c "normal gg=G" -c "wq" infile.txt
> Thanks,
> Peng
Regards,
Ag.
You might want to execute the command in "not compatible" mode
for the 'indentexpr' to work. Use "-N" in that case.
Regards,
Ag.
Your command is valid, and it shouldn't raise any kind of warnings,
unless:
a. Another vim instance is running with the same file you want to operate,
and you have already 'set swapfile' in your 'vimrc'.
This is normal and desired.
You can avoid the warning (if you intent to keep this file open) and
you want/have to run your command in sporadic time with a cron job or
something, with the 'set noswapfile' command.
b. You have already a swap file laying around possible from a previous
crash, which is what probably happens in your case.
So you can delete that swap file and you shouldn't receive that warning
anymore (about the swap file) and the operation will be silent.
> Do these two different options affect the speed of vim?
It's not a matter of speed in that case.
It is possible for Vim to start in vi compatible mode, but which then any
of the 'indentexpr' or 'cindent' or 'equalprg' options is not going to work
(one of those needed for the '=' operator), because these options could be
only set in *not* compatible mode.
See for references:
:help 'swapfile'
:help =
:help 'indentexpr'
:help 'cindent'
:help 'equalprg'
:help 'compatible'
Regards,
Ag.
Try either bunging in some :silent commands:
vim -N -u NONE -c "sil normal gg=G" -c "sil wq" file.txt
or even
vim -N -u NONE -c "sil! normal gg=G" -c "sil! wq" file.txt
or using 'silent Ex mode'
vim -N -u NONE -e -s file.txt << 'END'
normal gg=G
wq
END
See
:help :silent
:help -e
:help -s-ex
Note that :help -s is different, and not what is used here.
Cheers,
Ben.
I've been using a command like the following to edit a file in a
script and never see a vim window.
vim -X -E -s -u NONE -c ... -c 'wq' "$@"
I didn't use :silent in front of any of the commands.
HTH,
Gary
Try adding the -n option.
Gary
Perl, awk and others were designed to be "like a
more powerful sed". Vi and vim were designed for a
different job, namely *visual* editing.
That's not to say vim can't be used for stream
editing. But since it wasn't designed for it, it
shouldn't come as a surprise if there are hiccups
along the way.
My 2 cents would be: use the right tool for the
job.
--
JR