https://www.rona.ca/en/vim-cleaner-0684002

How Do I Exit Vim? An Introduction to Vim

Karl Castillo
3 min readFeb 20, 2019

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 Mode
  • v — Go into Visual Mode
  • u — Undo most recent edit to the file
  • w — Go forward to the start of a word
  • b — Go backward to the start of a word
  • 0 — Go to the beginning of the line
  • $ — Go to the end of the line
  • dd — Delete current line

Command Mode Commands

  • q — Quit
  • q! — Quit while discarding any edits to the file
  • w — Save
  • wq — Save and Quit
  • x — Save and Quit

Visual Mode Commands

  • > — Shift text right
  • < — Shift text left
  • y — Copy text (yank)
  • d — Delete text
  • ~ — Toggle case

Searching

  • /pattern — Search forwards
  • ?pattern — Search backwards
  • n— Next search result
  • N — 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!

--

--

Karl Castillo

Front-End Developer at Machobear Studios from Vancouver, BC. Lover of mentorship, design, powerlifting, dragonboat and San Antonio Spurs.