logo

How to Exit vi or vim on Linux 📂Programing

How to Exit vi or vim on Linux

Overview

vi or vim is a text editor renowned for its longevity in Linux systems. While it is admittedly less user-friendly compared to gedit, its prevalence stems from the nature of Linux, where handling files via CLI, often in server environments, is common. Alongside emacs, it remains popular with many users.

The issue, much like with scientific calculators, is that its operation can be unintuitive, starting with the challenge of simply exiting the program. This post exclusively explains how to exit vi, aiming for quick and concise information transfer.

Guide

alt text

While vi is open, pressing ESC will create a colon : at the bottommost line, transitioning into the command mode.

Exit

:q

By entering the command q, you can exit. q is derived from quit.

Exit and Save

:wq

By entering the command wq, you can exit. w stands for write.

Force Exit

alt text

Depending on the situation, issuing an exit command with q may result in a warning with a red highlight reading ‘No write since last change’. In this case, you can override this with the force exit command q! or the force save and exit command wq!.

alt text