Introduction to Vim:
Vim is a powerful text editor available on various operating systems, widely used in Unix-based systems. This guide aims to help beginners understand the basics of Vim, which is essential for tasks like editing configuration files on Linux systems.
Installing Vim:
-
Linux: Use package managers like
yumorapt. - Windows: Download from the official Vim page.
- macOS: Use Brew or download from the official Vim page.
Basic Tasks in Vim:
-
Create or Open a File:
- Open a terminal and type
vim filenameto create or open a file.
- Open a terminal and type
-
Vim Modes:
- Vim starts in Command mode. Switch to Insert mode by pressing
ito type text. Return to Command mode by pressingESC.
- Vim starts in Command mode. Switch to Insert mode by pressing
-
Edit a File:
- In Insert mode, type your text. To save changes, switch back to Command mode (
ESC).
- In Insert mode, type your text. To save changes, switch back to Command mode (
-
Save a File:
- Use
:wto save your changes in Command mode.
- Use
-
Exit Vim:
- Type
:qto quit Vim. Use:wqto save and quit simultaneously. To exit without saving, use:q!.
- Type
Additional Features:
-
Display Line Numbers:
- Use
:set numberto display and:set nonumberto hide line numbers.
- Use
-
File Navigation:
- Use
ggto jump to the top,Gto jump to the bottom, and{line_number}Gto go to a specific line.
- Use
-
Search a File:
- Use
/keywordto search andn/Nto navigate through results. Use:nohlto turn off highlighting.
- Use
Vim's extensive functionality makes it a preferred tool for developers and administrators. Practice these basic tasks to become proficient and explore more advanced features to enhance your productivity.
For more information, visit the full tutorial on CompTIA's blog.
Top comments (1)
Pasting using right click, when you are in command mode, pastes the text but skips the 1st letter of the copied text.