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:
If you are in Insert mode, the display looks like this:
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.
| Command | Function |
|---|---|
| i | Open Insert mode |
| a | Open insert mode and start writing after the cursor (if the file already has content) |
| A | Open Insert mode and move the cursor to the very end of the text |
| o | Open insert mode and add a new line (if there is already content in the file) |
| ESC | Exit Insert mode and open Command mode |
| u | Undo the last change |
| U | Undo all changes on all lines |
| dd | Delete one line of text |
| 3dd | Delete 3 lines of text |
| D | Delete the line behind the cursor |
| C | Delete the content of the line after the cursor and Insert new text. |
| dw | Delete character |
| 4dw | Delete 4 characters |
| ~ | Change character case, from lowercase to uppercase and vice versa |
| r | Replace character |
| Shift+Arrow | Move the cursor to the side of the word |
| k | Move the cursor up |
| j | Move the cursor down |
| l | Move the cursor to the right |
| h | Move the cursor to the left |
Commands to Open and Exit the Vi/VIM Editor
| Command | Output |
|---|---|
| Shift + zz | Close and save the file |
| :w | Save the file without closing the editor |
| :q! | Close the editor without saving the file |
| :wq! | Save the file and close the editor |
| :wq | Save 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.
COMMENTS
Loading...