Basic use Vim

Three modes

  • Press ESC to enter command mode
  • Enter command mode Shift +; line mode to enter
  • Insert command mode command input, such as (i, a, o) enters the input mode

enter

  • vim filename
  • vim directly edit a file, if the file already exists, then open the file, if there is no file, it will create a new file
  • In Linux, the file extension is just a label, any file can be opened with vim, py file is, you can open files edited with vim

drop out

  • wq: line mode, wq save and exit
  • q: line mode, q to exit
  • q !: line mode, q! Forced to exit without saving

Move the cursor

  • gg: to file the first line
  • G: The last line of the file
  • ^: Non-space of the line
  • 0: beginning of the line (the number 0)
  • $: End of line

Input Mode

  • i: from the cursor location insertion start
  • I: First insert the current line
  • a: the start position of the cursor from the rear input
  • A: inserting the end of the current row
  • o: a new row below the cursor line and the input mode
  • O: the top row is inserted in the current

Copy and Paste

  • yy: Copy whole line
  • * Yy: * Copy the contents of the line
  • yw: Copy the contents of the current cursor to end of word
  • p: Paste

Undo

  • In command mode: u
  • u: Undo
  • ctrl + r: Undo cancel (undo the last u)

delete

  • Cut the paste can not be used as a deleted
  • dd: Cut cursor line
  • * Dd: * a shear line cursor
  • dw: Cut a word
  • x: Cut the character where the cursor

Block operation

  • v: block selection
  • ctrl + v: blockwise

Seek

  • Enter the command mode: / search forward
  • Enter the command mode:?, Search backwards
  • n: look down
  • N: Find up

Alternatively (line mode)

  • : S / s1 / s2 in the current line is the first s2 s1
  • : S / s1 / s2 / g in the current line is all s1 s2
  • :% S / s1 / s2 / g to replace text of all the s1 s2




Guess you like

Origin www.cnblogs.com/jiyu-hlzy/p/12063694.html