Using vimdiff

  • by

vimdiff works on two, three or four files, opens each file in a separate window and highlights the differences between the files. The files can be edited using the vim commands. vimdiff is a useful tool for finding the differences between different versions of a file and for resolving conflicts between file versions.

vimdiff showing three versions of Hello World program

vimdiff can be started as,

$ vimdiff [options] file1 file2 [file3 [file4]]

vimdiff is actually running vim in the diff mode and the command is equivalent to,

$ vim -d [options] file1 file2 [file3 [file4]]

The -o option opens files in horizontal windows. The -O option opens files in vertical windows, which is the default. The vertical windows put files side by side and the lines are aligned, which makes it easy to use.

Navigating between windows

Each window has a file opened under vim. So all the vim commands are available for editing text in each window. As you edit a file in one of the windows, the output highlighting the differences is updated.

Under vim, the four basic commands for moving cursor left, down, up and right are h, j, k and l respectively. So, it is not surprising that the commands for moving cursor from one window to another are,

CTRL w h: Go to window on the left
CTRL w j: Go to window below
CTRL w k: Go to window above
CTRL w l: Go to window on the right

Quiting vimdiff

You can save modified files in each window with the :w command and quit an individual buffer window with the :q command. This will take some time for multiple windows. The command :qa quits all file windows if no files have been modified. Also, :qa! command force quits all buffer windows and any changes made in any of the files are discarded. If you wish to save any files that might have been modified and quit all the file windows, the command is :xa. So, basically, one has to add an a after the corresponding vim commands.

vimdiff is a tool for merging conflicting branches in the popular Git version control system.

See also

Subscribe
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments

You may like these, also

  • POSIX message queues in LinuxPOSIX message queues in Linux 1.0 POSIX Message queues POSIX interprocess comunication (IPC) was introduced in the POSIX.1b standard (IEEE Std 1003.1b-1993) for real time…
  • POSIX Shared Memory in LinuxPOSIX Shared Memory in Linux 1.0 Shared Memory Shared memory is the fastest method of interprocess communication (IPC) under Linux and other Unix-like systems. The…
  • POSIX Semaphores in LinuxPOSIX Semaphores in Linux 1.0 Semaphores Semaphores are used for process and thread synchronization. Semaphores are clubbed with message queues and shared memory under…
  • fork and exec system calls in Linuxfork and exec system calls in Linux 1.0 fork and exec system calls Suppose we wish to write a "shell program" which would execute another program. Now,…
  • Connecting two computers with Ethernet LAN cableConnecting two computers with Ethernet LAN cable Quite often, we wish to connect two computers back to back using an Ethernet LAN cable. It may be because…
  • D-Bus TutorialD-Bus Tutorial 1.0 D-Bus D-Bus is a mechanism for interprocess communication under Linux and other Unix-like systems. D-Bus has a layered architecture.…
  • Socket programming using the select system callSocket programming using the select system call 1.0 Client-Server Paradigm The Client-Server paradigm divides the software architecture of a system in two parts, the server and its…
  • System V message queues in LinuxSystem V message queues in Linux 1.0 Message queues Message queues are one of the interprocess communication mechanisms available under Linux. Message queues, shared memory and…
  • POSIX Threads Synchronization in CPOSIX Threads Synchronization in C 1.0 POSIX Threads Synchronization POSIX Threads provide multiple flows of execution within a process. The threads have their own stacks…
  • System V Shared Memory in LinuxSystem V Shared Memory in Linux 1.0 Shared Memory Shared memory is one of the three interprocess communication (IPC) mechanisms available under Linux and other Unix-like…