'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

  • 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 '13 at 14:55
  • 1
    vimdiff a b 2>/dev/null does not work for me. – Eric Johnson Feb 1 '13 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 – Eric Johnson Feb 1 '13 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 '13 at 15:12
  • The answer seems to be here. Make sure to read the comments. – terdon Feb 1 '13 at 15:21

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".

  • 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. – Eric Johnson Aug 29 '14 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 – DevDaddyNick Apr 20 '17 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 '17 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. – DevDaddyNick May 15 '17 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 '17 at 1:58

Set in your .vimrc

set shortmess=at

More tips and triks.

  • 3
    This does not work for me. I suspect this only affects messages inside vim not on the commandline. – Eric Johnson Feb 1 '13 at 15:03

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

set shortmess=filnxtToO
  • 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 – Eric Johnson Feb 2 '13 at 13:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.