VIM enables programming small operation 6 to fly

Time:2020-5-27

VIM is a powerful editor. Students who have done Linux C development should be very familiar with it. Java developers often use VIM to modify and deploy configuration files in Linux. In this paper, the common operations in VIM are sorted out for your reference

Enter VIM

1. Linux command line / git bash command line and other terminal tools can be directly inputvi filenameEnter:
VIM enables programming small operation 6 to fly
VIM enables programming small operation 6 to fly

2. After installing the ideavim plug-in, the idea editing area will enter the VIM operation area

VIM three modes

Input mode

In input mode, users can input text data
-In instruction mode, input instructions (` a, I, O, s, etc.) enter the input mode

Command mode

In the command mode, you can delete, modify and other editing actions
-In input mode & last line mode, press ESC key to enter instruction mode

Last line mode

In the last line mode, it mainly performs some auxiliary functions of text editing, such as string search, substitution, file saving, etc
-In last line mode, press ESC to enter instruction mode

Common instructions in instruction mode

Enter input mode

Importance Instruction set function
*** a Enter after current cursor
* A Enter at the end of the current line
*** i Enter before current cursor
* I Enter at the beginning of the current line
*** o Add a new line under the current line and enter in the new line
* O Add a new line above the current line and enter it in the new line

After input, press ESC to exit the input mode

Cursor move

Importance Instruction set function
*** h Move one character to the left
*** l Move one character to the right
*** j Move one character down
*** k Move one character up
* b Move one word left to the beginning
* w Move one word right to the end
* 0 Move to the beginning of the current line
* $ Move to end of current line
  + Move to the beginning of the next line
  Move to the beginning of the next line
  H Move to the first line of the window
  M Move to the middle row of the window
  L Move to the last line of the window
  G Move to the last line of the file
  nG Move to line n of the document
  n+ Move n rows down
  n- Move n lines up
  gg Back to the beginning
  Shift+g Back to the end

Window Moving

Importance Instruction set function
*** Ctrl + f One page under Windows
*** Ctrl + b Windows up one page
  Ctrl + d Bottom half of window
  Ctrl + u Half page up of window
* Ctrl + e Scroll down one line
* Ctrl + y Scroll up a line in the window

Delete operation

Importance Instruction set function
*** x Delete cursor character
  X Delete the word before cursor
* dw Removes a word backward from the current position of the cursor
  db Removes a word forward from the current position of the cursor
* d0 Delete from the beginning of the line to the current cursor position
* d$ Delete from cursor current position to end of line
*** dd Delete cursor row
  D Same as D$

Modify operation

Importance Instruction set function
*** s Modify the character of the cursor. Press ESC to finish the modification
  S Modify the whole line. Press ESC to finish the modification
* r Replace the character of the current cursor
* R Enter the replacement state until you press ESC
* cw Modify a word (from cursor position to end)
  cb Modify a word (from the beginning of the word to the cursor position)
* cc Modify the contents of the whole line, and press ESC to finish, the same as S
* c0 Modify the contents from the beginning of the line to the cursor position
* c$ Modify cursor position to end of line
* ~ Cursor character case switch

Instruction repetition

In instruction mode, a number n can be added before the instruction, and the instruction will be executed repeatedly n times

Importance Instruction set function
*** nx Delete n characters
*** ndd Delete n rows
*** ns Modify n characters

Cancel / redo the previous action (undo / redo)

Importance Instruction set function
*** u The result of undoing the previous instruction
*** . Repeat previous instruction

Find string

Importance Instruction set function
*** /String Finds the string backward from the current cursor
*** ? string Finds the string forward from the current cursor
*** n Finds the next string backward from the current cursor
*** N Finds the next string forward from the current cursor

View editing

Importance Instruction set function
*** Ctrl + g Displays the file name being edited, the number of lines where the current cursor is located, the total number of files, and whether the file has been modified

parenthesis matching

Importance Instruction set function
*** % Locate the matching “(“, “)”, “{“, “}”

Common operations in last line mode

Save and exit

Importance Instruction set function
*** :w Save without exiting
*** :wq Save and exit
*** 😡 Same as: WQ
*** :q Exit. If the current file is not saved, do not exit
*** :q! Exit without saving
*** :w file.txt Save content to file file.txt Note: the edited file is still the original file
* w! file.txt Force content to file file.txt Medium, such as file file.txt Presence: W file.txt Execution will be prohibited

Environment settings

Importance Instruction set function
* :set Display the set environment status
* :set all Show all environment settings options
* :set nu set number
* :set nonu set nonu
* :set ts=n Set the length of the tab key to n

Execute command

The following is an example of a specific number. The number indicates the number of lines. The cursor line can be replaced by “.” and the last line of the file can be replaced by “$”

Importance Instruction set function
* :10,20d Delete lines 10 through 20
* :10d Delete line 10
* :%d Delete all
*** :10,20co30 Copy lines 10 through 20 after line 30
* :10,20mo30 Move lines 10 through 20 after line 30
*** :1,$s/old/new Replace old in line 1 to last with new
*** :1,$s/^/new Insert new before the contents of line 1 to the last line
* :10 Move cursor to line 10

Switch to shell state

Importance Instruction set function
*** :sh Switch to the shell state, and enter exit on the shell command line to return VIM

Another VIM jump chart is attached for reference

VIM enables programming small operation 6 to fly

Recommended Today

Application case of tsutsuga: big data judicial query platform

1. Preface When the public security organs, procuratorial organs and law enforcement organs need to inquire about the bank deposits of enterprises, institutions, institutions and organizations or consult the accounting vouchers, account books, statements and other archives related to the case, the banks shall actively cooperate. When inquiring or consulting, the people’s court shall issue […]