How to disable warning measage when using vim like sed?

5 views
Skip to first unread message

Peng Yu

unread,
Jun 22, 2008, 12:17:28 AM6/22/08
to vim_use
Hi,

I use the following command to indent the file infile.txt. But there
is a swap file, it still ask to confirm what to do. How to make vim
run quietly just like using sed?

vim -c "normal gg=G" -c "wq" infile.txt

Thanks,
Peng

Ag. D. Hatzimanikas

unread,
Jun 22, 2008, 2:50:18 AM6/22/08
to vim...@googlegroups.com


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.

Ag. D. Hatzimanikas

unread,
Jun 22, 2008, 3:02:20 AM6/22/08
to vim...@googlegroups.com

You might want to execute the command in "not compatible" mode
for the 'indentexpr' to work. Use "-N" in that case.

Regards,

Ag.

Peng Yu

unread,
Jun 22, 2008, 12:02:18 PM6/22/08
to vim_use
I don't quite understand why "compatible" or "not compatible" matters.
What I want is just to indent the file silently. Do these two
different options affect the speed of vim?

Thanks,
Peng

Ag. D. Hatzimanikas

unread,
Jun 23, 2008, 1:13:32 AM6/23/08
to vim...@googlegroups.com

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.

Peng Yu

unread,
Jun 23, 2008, 5:49:00 PM6/23/08
to vim_use
vim -N -u NONE -c "normal gg=G" -c "wq" file.txt

It seems the above command is not completely non-interactive. I still
can see it transiently shows how much of the file has been processed.

Thanks,
Peng

Ben Schmidt

unread,
Jun 24, 2008, 12:16:42 AM6/24/08
to vim...@googlegroups.com
> vim -N -u NONE -c "normal gg=G" -c "wq" file.txt
>
> It seems the above command is not completely non-interactive. I still
> can see it transiently shows how much of the file has been processed.

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.

Peng Yu

unread,
Jun 24, 2008, 2:12:11 AM6/24/08
to vim_use


On Jun 23, 11:16 pm, Ben Schmidt <mail_ben_schm...@yahoo.com.au>
wrote:
> > vim -N -u NONE -c "normal gg=G" -c "wq" file.txt
>
> > It seems the above command is not completely non-interactive. I still
> > can see it transiently shows how much of the file has been processed.
>
> 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

I tried the above method. It seems that vim still briefly show up
something (maybe just some blank screen) and switch back to the
original terminal. The switch takes in the order of maybe tenths of
second.

Is it the correct behavior?

Thanks,
Peng

Gary Johnson

unread,
Jun 24, 2008, 2:34:18 AM6/24/08
to vim...@googlegroups.com
On 2008-06-23, Peng Yu <Peng...@gmail.com> wrote:
> On Jun 23, 11:16 pm, Ben Schmidt <mail_ben_schm...@yahoo.com.au>
> wrote:
> > > vim -N -u NONE -c "normal gg=G" -c "wq" file.txt
> >
> > > It seems the above command is not completely non-interactive. I still
> > > can see it transiently shows how much of the file has been processed.
> >
> > 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
>
> I tried the above method. It seems that vim still briefly show up
> something (maybe just some blank screen) and switch back to the
> original terminal. The switch takes in the order of maybe tenths of
> second.
>
> Is it the correct behavior?

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

Peng Yu

unread,
Jun 29, 2008, 12:56:03 PM6/29/08
to vim_use


On Jun 24, 1:34 am, Gary Johnson <garyj...@spk.agilent.com> wrote:
The above command works when no other vim is opening the same file.
Otherwise, it just hangs there without responding at all.

Is it so difficult to make vim like a more powerful sed?

Thank,
Peng

Peng Yu

unread,
Jun 29, 2008, 1:01:44 PM6/29/08
to vim_use


On Jun 23, 11:16 pm, Ben Schmidt <mail_ben_schm...@yahoo.com.au>
wrote:
> > vim -N -u NONE -c "normal gg=G" -c "wq" file.txt
>
> > It seems the above command is not completely non-interactive. I still
> > can see it transiently shows how much of the file has been processed.
>
> 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
The above command would hang there, if file.txt is opened in other vim
session.

>
> or using 'silent Ex mode'
>
> vim -N -u NONE -e -s file.txt << 'END'
> normal gg=G
> wq
> END

The above command would fail to do anything, if file.txt is opened by
another vim session.

Gary Johnson

unread,
Jun 29, 2008, 1:20:16 PM6/29/08
to vim...@googlegroups.com

Try adding the -n option.

Gary

Jean-Rene David

unread,
Jun 29, 2008, 8:48:00 PM6/29/08
to vim...@googlegroups.com
* Peng Yu [2008.06.29 13:00]:

> Is it so difficult to make vim like a more
> powerful sed?

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

Reply all
Reply to author
Forward
0 new messages