Just the basics you need to get started.
Also for those who are trapped in classic vim situation, where you don't know how to quit!
Vim is a powerful, keyboard-driven command-line text editor (an improved version of the classic Unix “vi”) used for efficiently editing code and plain-text files.
Things you need
- Linux Mint or Ubuntu
- Vim 8.2 or above
- Alacritty terminal (Why? Just for feel!)
Install
sudo apt update && sudo apt install vim
Open a file in Vim
Suppose you are inside a folder called hello and it has a file hello.txt.
You open the file in Vim:
vim hello.txt
Modes of Vim
In vim we have modes.
When you open a file the default mode is Normal mode.
Normal mode -> Esc key
Insert mode -> i
Command mode -> Esc key then :
What the heck are modes?
- When you press 'i', you can type in the editor, thats Insert mode.
- When you press 'Esc' key, you go back into Normal mode where you can view the file without typing.
- When you press ':' inside normal mode, that is Command mode.
For beginners, insert mode is for you to type.
Later you will learn the powers of normal mode where you can use Vim's shortcuts to edit the file super hyper fastly!
Command mode, for now, is for saving the changes you made and to quit and get out of Vim.
Quit, Save, and others
First, press 'Esc' to ensure you are in Normal mode.
Then:
- To just quit:
Type
:qthen pressEnter - To just save:
Type
:wthen pressEnter - To save and quit at once:
Type
:wqthen pressEnter - To quit without saving:
Type
:q!then pressEnter
Example
1) Open the hello.txt file:
vim hello.txt
2) Type some text:
- Press
i - Then type this text:
hello world!
3) Save the changes:
- Press
Escto come out of insert mode - Type
:wand pressEnterto save the changes
4) Quit:
- Type
:qand pressEnterto quit
Classic 'Unable To Quit Vim' Situation
If you are someone who just want to quit, then:
- Press
Escthen type:q!then pressEnter
Thats it! 🥶
Top comments (0)