16
vimdiff file1 file2 

besides differences shows also same lines from both files. Is it possible to hide them? How to do it?

1
  • 1
    Also answered at unix.stackexchange.com/a/352204: You can do this once off by setting options on the vimdiff command: vimdiff -c 'set diffopt=filler,context:0' file1 file2 Commented Oct 7, 2022 at 14:19

3 Answers 3

20

As Vim is a text editor (not a specialized diff viewer), the full contents of both files are kept (so you can do edits and persist them). Vim usually just "hides" multiple identical lines by folding them away; they are still present, just not visible.

You can influence how many identical lines are kept around changes (default: 6 lines above and below) via the context value of the 'diffopt' option. So, to completely fold all identical lines:

:set diffopt+=context:0 
Sign up to request clarification or add additional context in comments.

1 Comment

:set diffopt+=context:{n} Use a context of {n} lines between a change and a fold that contains unchanged lines. When omitted a context of six lines is used. When using zero the context is actually one, since folds require a line in between, also for a deleted line.
0

It is still showing common lines if common line is going in sequence with different. one after another

2 Comments

Please provide additional details in your answer. As it's currently written, it's hard to understand your solution.
This does not really answer the question. If you have a different question, you can ask it by clicking Ask Question. To get notified when this question gets new answers, you can follow this question. Once you have enough reputation, you can also add a bounty to draw more attention to this question.
0

The solution suggested by Ingo Karkat worked perfectly in Linux. Thanks for sharing it. However, it's not working on Mac.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.