How to Exit the Vi/VIM Editor, List of Vi/VIM Commands

Have you ever been frustrated by how to exit the Vi/VIM editor when using a Linux VPS?

You might have used the Vi/VIM editor to edit a file before, often, or even by accident. If it was by accident, it is usually because you were trying to follow a tutorial online that used Vi/VIM. So, how do you exit it?

As additional information, VIM stands forViIMproved, where this editor is newer and has more complete advanced features compared to Vi. Additionally, VIM is used more often or is more popular than Vi.

When using Vi or VIM, you can use two usage modes, command mode and insert mode. What distinguishes these two modes is that when you use Insert mode, there will be textInsert in the bottom left corner of your editor.

For an example of when you are in command mode, the display looks like this:

Cara Keluar Dari Vi/VIM Editor, Daftar Command Vi/VIM

If you are in Insert mode, the display looks like this:

Cara Keluar Dari Vi/VIM Editor, Daftar Command Vi/VIM

How to Use the Vi/VIM Editor

To use the Vi/VIM editor, you can use the following command in your CLI, and you will automatically enter command mode in the Vi/VIM Editor.

vi <nama_file>atauvim <nama_file>

To enterInsert mode, you can press the i orokey. Then, to return to command mode when you are in insert mode, you can press theESC key on your keyboard.

List of Vi/VIM Commands

Before trying to use commands, there is one thing you need to know, which is that these commands areCase Sensitive, meaning that using uppercase or lowercase letters will affect your command.

Additionally, to use commands, make sure you are in command mode and ensure you press the right key or use the correct command, or you will lose your editing progress.

Common Vi/VIM Commands

Some of the Vi/VIM codes below may be updated, so it is recommended to try them out first using a dummy file if you want to use a specific command.

CommandFunction
iOpen Insert mode
aOpen insert mode and start writing after the cursor (if the file already has content)
AOpen Insert mode and move the cursor to the very end of the text
oOpen insert mode and add a new line (if there is already content in the file)
ESCExit Insert mode and open Command mode
uUndo the last change
UUndo all changes on all lines
ddDelete one line of text
3ddDelete 3 lines of text
DDelete the line behind the cursor
CDelete the content of the line after the cursor and Insert new text.
dwDelete character
4dwDelete 4 characters
~Change character case, from lowercase to uppercase and vice versa
rReplace character
Shift+ArrowMove the cursor to the side of the word
kMove the cursor up
jMove the cursor down
lMove the cursor to the right
hMove the cursor to the left

Commands to Open and Exit the Vi/VIM Editor

CommandOutput
Shift + zzClose and save the file
:wSave the file without closing the editor
:q!Close the editor without saving the file
:wq!Save the file and close the editor
:wqSave the file and close the editor

Those are some commands you can use when using the Vi/VIM editor. Hopefully, this helps you in editing files.

Written by

Muhammad Khoirun Nasikin

I enjoy tinkering with WordPress, hosting, VPS, web development, and various small experiments related to websites. I have over 3 years of experience in the web hosting industry.

COMMENTS

Loading...