Recently engaged in redis configuration files, but vim technology is poor, very angry.

The article directories

    • Vim keys table
    • Command mode
    • Baseline command mode
      • Open, save, and close the file
      • Insert text or lines
      • To remove or restore characters or lines
      • search
      • Jumps to the specified row
      • Set the line Numbers
      • Copy and paste
      • replace
    • Block operation
    • The input mode
    • A brief view of a

Vim keys table

Command mode

The user enters the command mode just after starting vi/vim. Keystrokes in this state are recognized by Vim as commands rather than input characters.

Here are some common commands:

I switches to input mode to enter characters. X Deletes the character at the current cursor position. : Switches to bottom line command mode to enter commands on the bottom line.Copy the code

To edit text: Start Vim and enter command mode. Press I to switch to input mode.

Baseline command mode

Command mode has only the most basic commands, so you still rely on bottom-line command mode to enter more commands. Press (colon) in command mode to enter baseline command mode. Press ESC to exit baseline command mode at any time

In baseline command mode, the basic commands are:

Q exits the program w saves the fileCopy the code

Open, save, and close the file

vi filename       // Open the filename file
:w       // Save the file
:w vpser.net // Save to the vpser.net file
:q          Exit the editor. If the file has been modified, use the following command:! q// Exit the editor without saving
:wq         Exit the editor and save the file
Copy the code

Insert text or lines

a      // Add text to the right of the current cursor position
i       // Add text to the left of the current cursor position
A     // Add text at the end of the current line
I      // Add text at the beginning of the current line (non-null character at the beginning of the line)
O     // Create a new line above the current line
o     // Create a new line below the current line
R    // Replace (overwrite) the current cursor position and subsequent text
J    // Merge the cursor line and the next line (still in command mode)
Copy the code

To remove or restore characters or lines

x         // Delete the current character
nx         // Delete n characters starting with the cursor
dd      // Delete the current row
ndd   // Drop the current row down to line n
u       // Undo the previous step
U      // Undo all operations on the current row
Copy the code

search

/vpser     // Search the vpser string under the cursor? vpser// Search the cursor for the vpser string
n           // Search down for the previous search action
N         // Search up for the previous search action
Copy the code

Jumps to the specified row

n+        // Jump down n lines
n-         // Jump up n lines
nG        // Skip to line n
G           // Skip to the bottom of the file
Copy the code

Set the line Numbers

:set  nu     // Display the line number
:set nonu    // Cancel the display of line numbers
Copy the code

Copy and paste

yy    // Copy the current line to the cache, or "ayy copy, "a is the buffer, a can also be replaced by any letter from A to Z, can do multiple copy tasks.
nyy   // Copy the current line n rows down to the buffer. You can also use "anyy copy, "where a is the buffer and a can be replaced with any letter from a to Z. Multiple copies can be done.
yw    // Copy the characters from the cursor to the end of the word.
nyw   // Copy n words starting with the cursor.
y^      // Copy the content from the cursor to the beginning of the line. VPS detective
y$      // Copy the content from the cursor to the end of the line.
p        // Paste the clipboard content behind the cursor. If the preceding custom buffer is used, use "AP" to paste the content.
P        // Paste the clipboard content before the cursor. If the preceding custom buffer is used, use "aP "to paste the content.
Copy the code

replace

:s/old/new      // Replace the first occurrence of old in the line with new
:s/old/new/g         // Replace all old lines with new
:n,m s/old/new/g     // Replace all old lines from n to m with new
:%s/old/new/g      // Replace all old in the current file with new
Copy the code

Block operation

Ctrl+v, move the cursor to select the object, uppercase I, such as # or //, esc twice

Autoindent: Ctrl+ V, move the cursor to select a line, = Left and right Indent: Ctrl+ V, move the cursor to select a line, </> Multiple lines comment: Ctrl+ V, select multiple lines, uppercase I, type #, ESC double multiple lines uncomment: Ctrl+ V, select multiple lines to delete portions of dCopy the code

The input mode

Press I in command mode to enter input mode.

In input mode, the following keys can be used:

Shift, ENTER ENTER, newline BACK SPACE, backspace, delete the character in front of the cursor DEL, delete the character behind the cursor Arrow, move the cursor in the text HOME/END, Move the cursor to the start/end of the line Page Up/Page Down, flip the Page Up/ Down Insert, switch the cursor to Input/replace mode, change the cursor to vertical/underscore ESC, exit the input mode, and switch to command modeCopy the code

A brief view of a