How Do I Exit Vim? An Introduction to Vim
The purpose of this article is to supplement a short talk that I did for my company to teach my colleagues the basics of Vim.
Seeing Vim memes, in the recent years, is like beating. It’s not really funny anymore but is still very relatable for anyone who uses or have used Vim. A common meme that people throw around is not being able to exit Vim. Vim’s welcome screen does state the instructions to exit.
Vim Modes
Vim has 4 different modes — Normal, Command, Visual and Insert.
- Normal is the initial mode that Vim opens with. In this mode, you’re able run commands to move around the file (eg. go to the end of the file or line). You can get into this mode by pressing
esc
. - Command is when you have the
:
on the bottom left of your terminal. In this mode, you’re able to run commands like quit or write. You can get into this mode by typing:
while in Normal mode. - Visual is a way for you to be able to highlight certain parts of your file starting from where you cursor currently is. You can do many things while in this mode like copy/yank or delete the highlighted text.
- Insert, as the name suggests, is the mode where you actually type text into your file.
These modes will be referenced below for where each command can be used.
Normal Mode Commands
i
— Go into Insert Modev
— Go into Visual Modeu
— Undo most recent edit to the filew
— Go forward to the start of a wordb
— Go backward to the start of a word0
— Go to the beginning of the line$
— Go to the end of the linedd
— Delete current line
Command Mode Commands
q
— Quitq!
— Quit while discarding any edits to the filew
— Savewq
— Save and Quitx
— Save and Quit
Visual Mode Commands
>
— Shift text right<
— Shift text lefty
— Copy text (yank)d
— Delete text~
— Toggle case
Searching
/pattern
— Search forwards?pattern
— Search backwardsn
— Next search resultN
— Previous search result
NOTE: Next and previous search result depends on which search command you initially used.
Example: Using ?pattern
starts a backward search so n
will find the next result backwards.
%s/search_pattern/replace_with
— Search and replace%s/search_pattern/replace_with/c
— Search and replace with a confirmation before every replace
Vim Resources
I’m a developer currently working in Vancouver, Canada. I mainly work as a front-end developer and I still dabble in the back-end of things. Feel free to visit my website and follow me here as well as my different social media accounts!