The 10 most important commands in the VIM text editor for beginners

In this blog article, our focus is on the most important commands for beginners to work effectively with the VIM editor. The VIM or “vi” is a super effective tool for working in the Linux terminal and is almost a must to handle.

0. ESC key

The ESC key is super important and lets you switch from “insert mode” to command mode. Always make sure that when you want to execute a command, you have pressed ESC beforehand.

1. Insert mode

The insert mode allows you to insert and edit text. Enter the command “i” to enter insert mode. You can now enter text. To exit insert mode and return to command mode, press the ESC key.

2. Save

To save your changes in VIM, enter the command “:w” followed by Enter. This will save the file.

3. Exit

To exit the VIM editor, enter the command “:q” followed by Enter. If you have made changes and want to save them, use the command “:wq” instead of “:q“. This command saves the file and exits VIM. If you do not want to save changes, use “:q!” instead.

4. Undo

To undo a change, enter the command “u” followed by Enter. This will undo the last action you performed.

5. Copy and Paste

To copy text in VIM, first mark the desired text in command mode by moving the cursor to the beginning of the text, pressing the “v” key, and then navigating to the end of the text. Once the text is marked, press the “y” and “p” keys (in command mode) one after the other. This will copy the marked text and paste it at the current cursor position.

6. Search and Replace

To search for text in VIM, enter the command “/YOUR_SEARCH” and press ENTER. VIM will search for the entered search term and highlight the first occurrence. To replace this occurrence, enter the command “:%s/OLD_TEXT/NEW_TEXT/g” followed by Enter. “old_text” will be replaced by “new_text”, and “g” stands for global (replace all occurrences).

7. Delete Line

To delete a line in VIM, position the cursor in the line to be deleted. Enter the command “dd“. This will delete the current line and move the following lines up.

8. Encrypt File

The command “😡” in VIM allows you to encrypt a file with a password. Open the file you want to encrypt in VIM. Make sure you are in command mode, then enter “:x” followed by Enter. You will be prompted to enter a password. Enter a strong password and confirm it. Note that no characters will be displayed during password entry. Once the password is accepted, the file will be encrypted and saved.

9. Jump to a Specific Line

To jump to a specific line in VIM, you can use the command “numberG“. For example, if you want to jump to line 420, use “420G“.

10. Jump to the End

To get to the end of the document, enter the command “G” followed by Enter. This will move the cursor to the end of the file. Additionally, with the command “gg” you can go to the beginning of your file.

Conclusion

So there you have it, the ten most important commands for VIM. They are a good starting point for beginners to become familiar with the VIM editor. Over time, you will find that VIM offers a variety of functions and commands that can increase your productivity when editing text files. I hope I could help you with this short blog article.