Showing posts with label Difference. Show all posts
Showing posts with label Difference. Show all posts

25 December 2025

How to compare differences of files in Vim?

In Vim, you can compare (diff) the file you already have open with another file in a few common ways. Here are the most practical ones.


1️⃣ From inside Vim (recommended)

If you already have file A open and want to compare it with file B:

:vert diffsplit path/to/other_file
  • Opens the other file in a vertical split

  • Vim automatically enters diff mode

  • Differences are highlighted

Horizontal split (if you prefer):

:diffsplit path/to/other_file

2️⃣ If both files are already open in Vim

If you opened two files normally (no diff yet):

:diffthis

Run this command in each window you want to compare.

To turn diff mode off later:

:diffoff

3️⃣ Start Vim in diff mode (for future reference)

From the terminal:

vim -d file1 file2

or

vimdiff file1 file2

4️⃣ Useful diff navigation commands

While in diff mode:

CommandWhat it does
]cJump to next difference
[cJump to previous difference
:diffgetGet change from the other file
:diffputPut change to the other file
dodiff obtain (same as diffget)
dpdiff put

5️⃣ Exit diff mode cleanly

:diffoff!

or close one of the windows:

:q

๐Ÿ’ก Tip (since you use Linux a lot)

Vertical diff is often easier on wide terminals:

:vert diffsplit other_file

If you want, I can also show:

  • how to compare 3 files

  • how to diff against the current buffer on disk

  • how to use Vim diff with Git

Just tell me ๐Ÿ‘

How to compare 3 files, please.

 

 

In Vim, comparing 3 files is very doable. Here are the clean, correct ways, from simplest to more advanced.


✅ Method 1: Start Vim with 3 files in diff mode (best & simplest)

From the terminal:

vimdiff file1 file2 file3

or

vim -d file1 file2 file3

Result:

  • All 3 files open side-by-side

  • Vim automatically enters diff mode

  • Differences highlighted across all three


✅ Method 2: Add a 3rd file while already diffing 2 files

If you already have file1 open and diffed with file2:

:vert diffsplit file3

Vim will:

  • Open file3 in a new split

  • Automatically include it in the diff

๐Ÿ’ก For horizontal split instead:

:diffsplit file3

✅ Method 3: Files already open → manually enable diff

If all three files are open in different windows but not diffed yet:

  1. Go to each window and run:

    :diffthis
    
  2. Repeat for all three windows

To exit later:

:diffoff

๐Ÿงญ Navigating differences (very important with 3 files)

CommandDescription
]c / [cNext / previous diff
doTake change from another file
dpPut change into another file
:diffget LOCALGet change from current window
:diffget REMOTEGet change from another window

๐Ÿ‘‰ With 3 files, Vim labels them as:

  • LOCAL

  • BASE

  • REMOTE

You can be explicit:

:diffget BASE
:diffget LOCAL
:diffget REMOTE

๐Ÿง  Common real-world example (Git-style 3-way diff)

vimdiff mine theirs base

Typical meaning:

  • BASE = original

  • LOCAL = your version

  • REMOTE = incoming version


๐Ÿงน Exit diff mode

:diffoff!

or close windows normally:

:q

⭐ Pro tips

  • Use vertical splits on wide screens:

    set diffopt+=vertical
    
  • Synchronize scrolling:

    :set scrollbind
    

If you want, I can also explain:

  • 3-way merge conflict resolution

  • diff against Git commits

  • color customization for diffs

Just say the word ๐Ÿ‘

08 June 2021

checkout, reset, restore, revert, and switch. What do they really do?

 checkout, reset, restore, revert, and switch. What do they really do?

Written by torek, etc.


https://stackoverflow.com/questions/58003030/what-is-the-git-restore-command-and-what-is-the-difference-between-git-restor


The whole page is useful, especially from 'To add to VonC's answer, and bring into the picture all the relevant commands, in alphabetical order, I will cover:'

I also like -

$git restore -s@ -SW -- <file> 

above the aforesaid section.



13 April 2015

How to take a photo with huge difference of brightness?

Use Photomatix Pro.

ๅค„็†้€‰“ๆ›ๅ…‰่žๅˆ”。ๆ–นๅผ้€‰“่žๅˆ/่‡ชๅŠจ”ๆˆ–่€…“่žๅˆ/2ๅผ ๅ›พๅƒ”。ๆ•ˆๆžœๆœ€ๅฅฝ。