Your First Vim Session
To launch Vim, open your terminal and type: vim

This will start Vim in Normal mode.
To insert text, switch to Insert mode by pressing i
.

Type some text and practice moving your cursor with the arrow keys to get comfortable.
When you’re ready to save your work, return to Normal mode by pressing Esc
.

If you're new to Vim, you might be puzzled by the concept of modes.
Simply put, to insert text, you enter Insert mode; when you're done, exit back to Normal mode.
To execute commands, start by typing :
. To save your file and exit, use the command :wq <filename>
.

For example,
:wq myfile.txt
creates a file named myfile.txt.
To open the file later, type vim myfile.txt
in the terminal, press i
to add more text, and if you wish to close the file without saving, return to Normal mode (press Esc
) and type :q!
.
This covers the basics for your first Vim session.
A Quick Example
If you're familiar with using Git and squashing commits, here’s a quick exercise to demonstrate Vim’s efficiency, even if you don’t fully grasp the context yet. Just follow these steps:
Exercise: Modifying Git Commit Messages
Suppose you have the following list of Git commits:Open Vim and enter Insert mode by pressing i
. Copy and paste the text snippet provided.
pick a1b2c3d Update README
pick e4f5g6h Add new feature
pick i7j8k9l Improve performance
pick m1n2o3p Fix bug
pick q4r5s6t Refactor code
pick u7v8w9x Enhance tests
Your Task: Change the word “pick” to “edit” for the last three lines.
Solution:
1. Open Vim and press i to enter Insert mode. Copy the text above and paste it into Vim using your terminal’s paste shortcut.
2. Once you’ve pasted the text, press Esc to return to Normal mode. Position your cursor at the start of the fourth line using the arrow keys.
3. Press Ctrl-v (This will the mode to visual mode ), then press the right arrow three times to select the word “pick” on the fourth line.
4. Press the down arrow two times to select the word “pick” on the fifth and sixth lines.
5. With the selection active, press c to change the text.
6. All selected “pick” words will be deleted, and your cursor will be on the fourth line, now in Insert mode. Type edit to replace the word.
7. Press Esc to finish the task.
Keep practicing, and you'll soon understand how it all works!🤩