Vim yes Linux/Unix A powerful text editor under the platform , It can complete the creation of text 、 Editing and viewing functions . Because in linux Under the platform , So all operations are done by command .


And vi The difference between ?

vim yes vi Editor enhancements vi(vi improved), It can achieve more code editing functions , For example, highlight the code with different colors , And fully compatible vi All operations .

vim Three models of : Command mode 、 Insertion mode 、 Bottom line mode

The differences between the three models are as follows :


The relationship between the three models is as follows :


Common operations in command mode

  • i:  Insert... Before the character of the current cursor

  • a:  Insert... After the character of the current cursor

  • o:  Insert a new line under the cursor

  • I: At the beginning of the current cursor line , Change to edit mode

  • A: At the end of the current cursor line , Switch to edit mode

  • O: Above the line of the current cursor , Create a new line

Cursor movement

The up and down or so (kjhl)


  • yy: Copy the current row

  • nyy: Copy below the current line n That's ok

The delete command

  • x: Delete the single character at the cursor

  • nx: Delete the total... At the cursor and back n Characters

  • dd: Deletes the line where the cursor is located

Search for replacement

  • /string: Search for the specified string

  • :%/s/old/new/g: Replaces the specified string with full text


  • u: Undo the previous edit operation

  • Ctrl+f: Flip down one screen

  • Ctrl+b: Turn up one screen

  • Ctrl+d: Turn down half screen

  • Ctrl+u: Turn up half screen

Bottom line mode operation

Save and exit

  • :q sign out

  • :wq Save and exit

  • :q! Forced exit without saving

  • ZZ Shortcut key , Save the changes and exit


  • :set nu set nu

  • set nonu Cancel the line Numbers

A simple new file to exit the demo


For memory purposes , There's one on the Internet vi/vim Keyboard diagram , You can save and learn .