11

'vimdiff a b' always prints "2 files to edit". I don't want to see that. How can I avoid it?

Here is an example:

⚡ vimdiff  a b                                                                                                                               
2 files to edit

I want to use vimdiff from a bash script and don't want to see this output

10
  • 1
    You could of course just launch it with 2>/dev/null. Why do you need this?It seems like such a minor annoyance. Oh, on a completely irrelevant note, could you share your $PS1? What is the character you are using as a prompt?
    – terdon
    Feb 1, 2013 at 14:55
  • 1
    vimdiff a b 2>/dev/null does not work for me. Feb 1, 2013 at 15:00
  • I'm just sticking the unicode character in there. My $PS1 is defined here: github.com/kablamo/dotfiles/blob/master/links/.bash/prompt.sh Feb 1, 2013 at 15:02
  • Nice, thanks :). And you're right, redirecting STDERR does not seem to work. I thought it did, but I just didn't see the line.
    – terdon
    Feb 1, 2013 at 15:12
  • The answer seems to be here. Make sure to read the comments.
    – terdon
    Feb 1, 2013 at 15:21

4 Answers 4

4

Looking through the vim source, it looks like that message can only be suppressed when launching the executable as ex and using its -s option, or by not having a console.

Neither approach will work for diffing.

However, the message is only output if there is more than one file specified on the command line.

So let's trick it:

vim a -c "vert diffsplit b"

Which basically says "Edit file a with vim, and once a is loaded, open a vertical split with file b and diff them".

5
  • Hey that works! Awesome, thanks! Now I have remember where it was that I wanted this. Good news is I think its still useful info for me. Aug 29, 2014 at 17:01
  • If your second file has a space in the path or filename, this solution doesn't work. I worked around it by instead calling vim with the -d flag and sending output to /dev/null, like this (The quotes will correctly pass the arguments with spaces.): vim -d "$a" "$b" >/dev/null Apr 20, 2017 at 16:45
  • @DevDaddyNick Doesn't that hide vim altogether for you? It does for me, using zsh as my shell, with oh-my-zsh based configuration.
    – codelahoma
    May 13, 2017 at 15:43
  • Yeah, I found out later my solution only works when you're not using Vim in the terminal. I was using Macvim, but the next time I tried this solution when SSH'd into another machine, it suppressed Vim altogether. May 15, 2017 at 13:18
  • For anyone else wanting to dig around in the code, the relevant line in the code as of today's date is here in main.c
    – xdhmoore
    Sep 1, 2017 at 1:58
0

--not-a-term option can suppress the message.

vimdiff --not-a-term a b

Document :h --not-a-term

-1

Set in your .vimrc

set shortmess=at

More tips and triks.

1
  • 3
    This does not work for me. I suspect this only affects messages inside vim not on the commandline. Feb 1, 2013 at 15:03
-1

According to this post on SO, setting this in your vimrc should do the trick:

set shortmess=filnxtToO
1
  • 3
    Sorry this doesn't work for me either even when I use --noplugin. I still get a msg. I'm not talking about the msg in the editor. After you close the editor, there is a msg and thats what i want to get rid of. Thanks though Feb 2, 2013 at 13:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .