Procedure
Step 1: To facilitate the step-by-step instructions provided in this tutorial, let’s generate two dummy files for illustrative purposes. You can utilize the Vim command to create both of these files effortlessly. For instance:
$ vim dum_file1.py
$ vim dum_file2.py
Enter the code provided below in both files and save them by pressing the “Esc” key followed by “:wq“. This command combination will ensure that your changes are saved, and the files are closed.
Step 2: In both examples, we are demonstrating how to calculate the factorial of a number in Python using two different approaches: recursion and a while loop.
Step 3: To open both files vertically in your default terminal or command prompt, you can use the command vimdiff
<file1> <file2>
. This command will launch vimdiff
with file1
and file2
displayed side by side.
$ vimdiff dum_file1.py dum_file2.py
Step 4: Go to the last line to find the fold in the code. Folds are indicated by lines starting with “+–” and represent hidden or collapsed text.
Step 5: To expand a folded section, use the Up and Down keys to move the cursor to the desired folded area, and then press the “zo” keys.
Step 6: Press the “zc” keys to close a folded section.
How to expand/collapse a diff sections in Vimdiff in Linux
Vimdiff is a powerful text editor Linux users love comparing and merging files. It’s based on another popular editor called Vim. With Vimdiff, you can easily see the differences between two files side by side.
Sometimes, when you’re working with big and complicated files, it can be hard to understand all the changes. That’s where Vimdiff’s expand and collapse features come in handy. They let you focus on specific changes or hide parts of the files to make things clearer. In this guide, we’ll show you how to use these features in Vimdiff, so you can easily navigate the differences.
Whether you’re already familiar with Vim or just starting, learning how to use these features will make you more productive and help you compare files more easily. So let’s get started and discover all the great things you can do with Vimdiff in Linux!
Contact Us