17. vimdiff - muneeb-mbytes/linux_course GitHub Wiki

vimdiff - can edit two or three versions of a file with Vim.

syntax vimdiff file1 file2 [file3]

syntax gvimdiff file1 file2 [file3]
or
syntax vim -d file1 file2

Vimdiff starts Vim on two (or three) files. file three is optional.

When you compare them manually, you might make a mistake, and it's easy to miss minute changes. Apart from that, finding changes in large files can be exhausting.

Each file gets its own window. The differences between the files are highlighted. This is a nice way to inspect changes and to move changes from one version to another version of the same file. and same as the gvim window also.

in each window the 'diff' option will be set, which causes the differences to be highlighted.

In Figure we comparing the two files using Vimdiff command.

Untitled Diagram drawio (3)

                           **Figure 1 : Usage of vimdiff command**

There are 2 types of split window

  1. Horizonal split window
  2. Verifical split window
  • diffsplit file_name
    #This command is use to compare the file by split the screen (horizontally).
    #syntax : diffsplit filename1 filename2
    (which we want to compare)

Getting the comparing of two files via split the screen horizontal .

Untitled Diagram drawio

                        ** Figure.2. Usage of diffsplit command**
  • vimdiff filename filename

#This command is use compare the two file via split the screen vertically .
#syntax : vimdiff filename1 filename2

Getting the comparing of two file by split the screen vertically.

Untitled Diagram drawio (2)

                         **Figure : 3 Usage of vimdiff (Vertically) command**

Switch between two windows

1.#ctrl+w
#This command is use to switch the cursor from one window to other window.
#syntax : ctrl+w
#Clearing the screen.
clear


To learn alias and unalias command: https://github.com/muneeb-mbytes/linux_course/wiki/18.-alias-and-unalias