Press ESC to return to command mode, enter: W to save, or enter: wq! Save the file and exit.
Here is the Save command:
: W saves the file but does not exit VI.
: W file saves the modification to file and does not exit VI.
: w! Forced to save, do not introduce VI.
Expand:
Use of Vi/vim
Basically Vi/vim is divided into three modes, namely command mode, input mode and bottom line command mode. The three modes of action are:
Command mode:
The user has just started Vi/vim and entered command mode.
In this state, the keystrokes are recognized by VIM as commands rather than as input characters. For example, we press I at this time and do not enter a character, I is treated as a command.
Here are a few common commands:
I switch to input mode to enter characters.
x deletes the character at which the current cursor is located.
: Switch to Baseline command mode to enter commands at the bottom of the line
How Linux vi saves the edited file