vi related

vi has three modes:

  Command mode: Any input on the keyboard is regarded as an "edit command";

  Input mode: Any input on the keyboard is regarded as text content;

  Last line mode: Any input on the keyboard is regarded as a "text management command"

Command mode (just opened) ==> (i, a, o) input mode (reverse Esc)

Command mode == "(shift+:) last line (reverse Esc*2)

Last line mode:

  set nu : display line numbers

  wq/x: save and exit; q!: do not save and exit

Command mode:

  ZZ (uppercase): save and exit

  i/a : one character before/after the cursor;

  I/A: start/end of line;

  O/o: Enter the previous/next line; ==>Esc shortcut to return to command mode

Movement of the cursor in command mode:

  kjhl: up, down, left and right;

  o : start of line (absolute);

  shift+6(^) : first (the first character of a line)

  shift+4($) : tail (last character of a line)

  gg/G : head/tail of the file

  10G: 10 lines

  w : next word

Modify the configuration of vi/vim: vim ~/.vimrc The current user's configuration file set nu to set the display line number; set ts=4 to set the tab key to four spaces

          vim /etc/vimrc Modify the configuration of all users

delete command:

  x: cursor letter; do: all before the cursor in a line; dw: whole word; 2(n)x: the beginning of the cursor character and the following, a total of 2(n) characters; dd: delete the entire line; 2(n) dd: delete the current line and the following 2 (n) lines in total

Undo: u; Undo: ctrl+r

Repeat the last command: .

>/<: Equivalent to tab/shift+tab; ==> Press v (to gain focus) in command mode, and then use hjkl to select more content

yy: copy; p: paste; 2(n) yy: same as above dd; yw: copy word

In last line mode:

  14,18y: Copy lines 14 to 18;

  ., 18y: Copy the cursor line to line 18;

  ., $y: copy the cursor line to the last line

Command mode:

  /keywords: find keywords == "n next, N previous

In last line mode:

  %s/after/before/gi: replace after with before, g means global, i ignores case, and gi can be omitted;

  !: execute any command without exiting vim

View text: cat (small file), more (important, space == "next version, q==" to exit), less (similar to more), tail (important, end with ctrl+c, tail -20==" tail 20 lines, the default is 10 lines), head (head 10 lines, head -20)

        find pass*: Find files starting with pass in the current directory;

        find /etc/pass*: find under etc

        grep 'root' /etc/passwd : find out if 'root' is contained in passwd

         '^root' : start the line with the word root

         'bash$': ends with bash

Pipe (|): head -9 /etc/profile | tail -1 ==> Execute the command on the right side of the pipe in the result on the left side of the pipe 

 

  

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325026348&siteId=291194637