#StudyDiary# Three operating modes of the Linux system text editing tool vim

888u

Last update at :2024-02-21,Edit by888u

vim has three operating modes, namely command mode (Command mode), input mode (Insert mode) and bottom line command mode (Last line mode) .

Shortcut keys for switching between three modes:

​ model shortcut key
Command mode ESC
Input mode i or a
Bottom line command mode :
  • Command mode controls cursor movement and input commands in command mode, and can copy, paste, delete and search text. After using the command vim filename to enter the editor view, the default mode is the command mode. At this time, tapping letters on the keyboard will be recognized as a command. For example, tapping d twice on the keyboard will delete the line where the cursor is.

    The following are commonly used shortcut operations in command mode:

operate shortcut key
Move cursor left h
Move cursor right l (lowercase L)
Move cursor up k
Move cursor down j
Move cursor to next word w
Move the cursor to the previous word b
Move the cursor to the nth row nG
Move the cursor to the first row gg
Move the cursor to the last row G
Quickly return to the last cursor position Ctrl o
Delete current character x
Delete previous character X
Delete entire line dd
Delete a word dw or daw
Delete to end of line d$ or D
Delete to beginning of line d^
Delete to end of document dG
Delete to the beginning of the document d1G
Delete n lines ndd
Delete n consecutive characters nx
Change the letter at the cursor position to uppercase or lowercase ~
Copy the entire line where the cursor is located yy (3yy means copying 3 lines)
Paste after the cursor (bottom) p
Paste in front of the cursor (top) P
Cut dd
Swap uplink and downlink ddp
Replace the entire row, that is, delete the row where the cursor is and enter insert mode cc
Undo one or n operations u{n}
Undo all modifications to the current row U
Resume the undo operation Ctrl r
The entire line will be indented to the right >>
The entire line will be returned to the left <<
If the file has not been modified, it will not be saved and exited; if the file has been modified, it will be saved and exited ZZ
  • Input mode: Press i or a in command mode to enter input mode. In input mode, you can normally use keyboard keys to insert and delete text.
  • Underline command mode: Press the : key in the command mode to enter the underline command mode. In the underline command mode, you can enter single or multiple character commands. The following are commonly used shortcut operations in bottom line command mode:
operate Order
Save :w
Exit :q
Save and exit :wq (:wq! means force save and exit)
Save the file as a different file name :w new_filename
Show line number :set nu
Cancel line number :set nonu
Center this row of content :ce
Allow this line of text to the right :ri
Move the content of this line to the left :le
Look for a string named word under the cursor :/word
Look for a string named word above the cursor :?word
Repeat the action of the previous search :n
Find the word1 string from the first line to the last line and replace the string with word2 :1,$s/word1/word2/g or :%s/word1/word2/g

Usage examples

In this example, vim will be used to write a Tang poem in a text file.

1. Create a new file and enter vim command mode.

vim quiet night thoughts.txt

2. Press i to enter the input mode and enter the poem title of "Silent Night Thoughts".

3. Press the ECS key to return to the command mode, and enter the bottom line command: ce to center the poem title.

4. Press the o key to change the line and enter the input mode, enter the first line of the poem.

5. Press the ECS key to return to command mode, and enter the bottom line command: ce to center the first line of poetry.

6. Press the o key to change the line and enter the input mode, and enter the second line of poetry.

7. Press the ECS key to return to command mode, and enter the bottom line command: ce to center the second line of poetry.

8. Execute the bottom line command in command mode: wq to leave vim.

Recommended site searches: Hong Kong virtual host space, ftp space, domain name registration information inquiry, foreign website space, registration-free, la domain name, free homepage space, virtual host Ministry of Industry and Information Technology website registration overseas host,

#StudyDiary# Three operating modes of the Linux system text editing tool vim

All copyrights belong to 888u unless special state
取消
微信二维码
微信二维码
支付宝二维码