How do I supress the "2 files to edit" message in vimdiff?

11

7

'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

Eric Johnson

Posted 2013-02-01T14:21:56.900

Reputation: 593

Hey @terdon, if you like that, you should check out vim's "digraph" page (:help digraph). It has all the symbols it supports with hex, decimal, descriptions, and digraphs themselves (key sequences, usually decent mnemonics.) Of course you can go the other way and pipe symbols to hd, so you can print by numeric value from your config files (generally a better idea than pasting them directly.) – John P – 2017-12-31T13:44:34.653

@JohnP I have no idea what you're talking about. Did you mean to address the comment to the OP? I don't even use vim, I'm an emacs user. I just left a link to a page that might help the OP. – terdon – 2017-12-31T13:53:27.310

"Oh, on a completely irrelevant note, could you share your $PS1? What is the character you are using as a prompt? – terdon" Although yes, it won't help you without Vim. – John P – 2017-12-31T13:58:34.173

@JohnP oh, wow, that was 4 years ago when I had barely heard of unicode :) The character is U+26A1 ‹⚡› \N{HIGH VOLTAGE SIGN} and has nothing to do with vim at all. That's the value given to PS1 and is not related to editors. It is a shell issue, not a vim one. – terdon – 2017-12-31T14:01:15.557

Haha, okay, I didn't see the age. My comment was all about special characters and how to add them to your config, using the editor you were commenting about, so I think it follows. I don't know what prompted your explanations at the end there, but great, we both understand. – John P – 2017-12-31T14:24:54.710

1You 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 – 2013-02-01T14:55:14.443

1vimdiff a b 2>/dev/null does not work for me. – Eric Johnson – 2013-02-01T15:00:45.120

I'm just sticking the unicode character in there. My $PS1 is defined here: https://github.com/kablamo/dotfiles/blob/master/links/.bash/prompt.sh

– Eric Johnson – 2013-02-01T15:02:29.033

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 – 2013-02-01T15:12:15.733

The answer seems to be here. Make sure to read the comments.

– terdon – 2013-02-01T15:21:20.613

Answers

3

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

codelahoma

Posted 2013-02-01T14:21:56.900

Reputation: 146

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 – 2014-08-29T17:01:42.233

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 – 2017-04-20T16:45:58.333

@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 – 2017-05-13T15:43:38.687

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 – 2017-05-15T13:18:11.517

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 – 2017-09-01T01:58:19.273

-1

Set in your .vimrc

set shortmess=at

More tips and triks.

Andriy Tykhonov

Posted 2013-02-01T14:21:56.900

Reputation: 117

3This does not work for me. I suspect this only affects messages inside vim not on the commandline. – Eric Johnson – 2013-02-01T15:03:43.683

-1

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

set shortmess=filnxtToO

terdon

Posted 2013-02-01T14:21:56.900

Reputation: 45 216

3Sorry 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 – 2013-02-02T13:13:09.280