Whatever sins this text editor may have, being slow is not one of them. Vim is a light and powerful text editor widely used among programmers and other technical professionals who work with text regularly.
Why Vim
Vim is known for its speed and low resource consumption, making it suitable for use on older systems or in remote environments. It's often preferred by developers who work on servers or in terminal-only environments. It gives them seamless integration with the command line. It also makes you feel like a tech-savvy.
Installing Vim
On Linux
sudo apt install vim
On macOS
brew install vim
On Windows
Go to the Vim website: https://www.vim.org/download.php
Under "PC: MS-DOS and MS-Windows," click on the "gvim82.exe" link (the version number may vary).
Run the downloaded installer, and follow the on-screen instructions to install Vim.
On Android - Termux
pkg install vim
Opening Vim
- After installing Vim, type
vim
on the terminal or PowerShell, to open the text editor.
- Also use the command:
vim <FILENMAE>
to open an existing file or create a new one if it doesn't exist.
Modes in Vim
There are three essential modes in Vim, they are:
Normal: Default; for navigation and simple editing
Command Line: For operations like saving, exiting, searching etc.
Insert: For explicitly inserting and modifying text
Normal mode
Use the Esc
key to return to the normal mode, even if you are already in the normal mode. The mode is mainly for navigation; you can use the arrow buttons to move the cursor up ↑, down ↓, left ← and right → of your file. It is from the Normal Mode, you can enter the Insert Mode and the Command Line Mode.
Command Line Mode
To enter the Command Line Mode, press the column character :
and the Vim editor will be ready to accept your command.
Now let's have a drum roll 🥁 because we are about to finally exit Vim
HOW TO EXIT VIM
Press the keys
:q!
and hit<ENTER>
to exit.Yeah that's all. We made it out, FAST. You can now exit Vim.
Let's proceed.
Insert Mode
To enter the Insert Mode, just hit the letter i
on your keyboard. And voila, you're in. You will always see -- INSERT -- at the bottom left of your screen whenever you are in insert mode. This means you can now edit the file, by typing in your text.
Basic Commands
Here are some basic commands to get you rolling with Vim:
Saving and Quitting
:w
(write) - to save file:q
(quit) - to exit and confirm if not saved:wq
(write and quit) - to save file and exit vim:q!
(quite forcefully) - to exit Vim whether the file is saved or not
Search and Replace Text
/text
- to search fortext
in the document, going forward.n
- to move the cursor to the next instance of the text from the last search. This will wrap to the beginning of the document.N
- to move the cursor to the previous instance of the text from the last search.:%s/text/replacement text/g
- to search through the entire document fortext
and replace it withreplacement text
.
Copy, Paste, Undo, Redo
v
(visual mode) - to highlight one character at a time. Use the arrow keys to move the cursor and select text.y
(yank) - to copy text into Vim's copy buffer.p
(paste) - to paste copied text after the cursor.u
(undo) - to undo the last operation.Ctrl+r
(redo) - to redo the last undo.
Moving the cursor
use
↑↓←→
up, down, left, and right arrow keys to move arounduse
HOME
key to go to the beginning of a lineuse
Ctrl+HOME
to go to the beginning of the fileuse
END
key to go to the end of a lineuse
Ctrl+END
to go to the end of a file
Next Step
This is how far I can go with you on this journey. At least, you now know how to exit (with :q!
or :wq
), whenever you get stuck.
let Documentation, Google, and ChatGPT be thy guide.
You have to continue the remaining part of the journey on your own.
I wish you the best of luck 🍀