- vi/vim concept
In CentOS, the commonly used text compilers are vi compiler and its upgraded version vim compiler. The vi editor is a standard editor under all Unix and Linux systems, and its power is not inferior to any latest text editor. vi is also the most basic text editor in Linux. After learning it, you will be able to move freely in the Linux world. - vim installation
Use yum to install the upgraded version of vi online. Before installation, make sure that the virtual machine can access the Internet and
ping www.baidu.com. During normal execution, execute the following command
yum -y install vim* - The three modes of vi/vim and the conversion relationship between each mode
basically vi can be divided into three states, namely the command line mode (the general mode in the figure below) (command mode), the insert mode (Insert mode) and Bottom line mode (last line mode)
1. Command line mode (command mode): control the movement of the screen cursor, delete characters, words or lines, move and copy a section and enter Insert mode, or go to last line mode.
2. Insert mode (Insert mode): only in Insert mode, can you do text input, press the "ESC" key to return to the command line mode.
3. Last line mode: save the file or exit vi, you can also set the editing environment, such as searching for character strings, listing line numbers, etc. But generally
we simplify vi into two modes when using it, That is, the last line mode (last line mode) is also included in the command mode command mode) - Mode switching operation steps
1. If you want to exit vi, you need to switch to the bottom line mode first;
2. In the insert mode, first press the ESC key, and then press the : key to switch to the bottom line mode;
3. If you want to save the current edit For the content, enter wq! after:, that is: wq!, so that the text is saved. Then exit the vi editor.
4. If you don’t want to save the currently edited content, enter q! after :, that is: q!, so you can quit the vi editor directly by giving up this edit.
tips:! Indicates mandatory execution, not required - Editing commands and shortcuts
1. Insert command: (General mode enters insert mode)
i Insert before the cursor
I Insert a at the beginning of the current line of the cursor Insert
a after the cursor Insert
A at the end of the current line of the cursor Insert
o Next line of the current line of the cursor Insert a new line
O Insert a new line above the current line of the cursor
2. Positioning command:
:set nu Display line number
: set nonu Cancel line number
: n to the nth line of the text
gg to the first line of the text
G to the text Last line
/ Find keywords and press to start from the current cursor position - Replace and cancel commands (in normal mode):
u undo, cancel the previous operation (ctrl+z under windows)
ctrl + r redo, return to before undo (ctrl+y under windows)
r replace the character where the cursor is located
R from the cursor Start replacing where you are, press the Esc key to end - Delete command:
x deletes the character where the cursor is located
nx deletes n characters after the cursor is located
dd deletes the line where the cursor is located.
ndd deletes n lines
dG deletes all content from the cursor position to the end line
D deletes the content from the cursor position to the end of the line
: 5,7d deletes the lines within the specified range (5,7) - Commonly used shortcut keys:
Shift+ zz save and exit, same as ":wq"
v enter character visual mode
V or Shift + v enter line visual mode
Ctrl + v enter block visual mode
ctrl+b: move the screen back one page
ctrl+f: move the screen forward by one page
"$" symbol: move the cursor to the end of the line
"^" symbol: move the cursor to the beginning of
the line yy: copy the line where the cursor is located to the buffer.
nyy: For example, "6yy" means to copy 6 lines of text from the line where the cursor is "downwards"
to replace: use "s/original character/new character/g" in the bottom line mode to represent all of the current line if you want to replace globally , s changes to %s
ctrl+z There will be a backup file when exiting abnormally, you need to delete the backup file to enter normally
After the swap file is generated, the solution is
ls -a /path
rm -rf .xxxx.swp Delete the swap file if there are multiple rm -rf xxx.sw*
tips: All copy commands related to "y" must cooperate with "p" to complete the copy and paste functions.
Getting started with linux-vi/vim text editor
Guess you like
Origin blog.csdn.net/weixin_44834205/article/details/126398134
Recommended
Ranking