vi / vim command instructions

1, Command Overview

vi / vim command is a text editor. Edit multiple files, separated by a space.

vi editor supports editing mode and command mode, you can complete editing text edit mode, you can complete the operation command file command mode, use the vi editor to correct you must be familiar with the switch between the two modes. By default, automatically enter the command mode after opening the vi editor. Switching from the command mode to the edit mode using the "esc" key to switch from the command mode to the edit mode using the "A", "a", "O", "o", "I", "i" key.
vi editor provides a wealth of built-in commands, and some built-in commands using keyboard combinations to complete, and some built-in commands you need a colon ":" at the beginning input.

2, the command syntax

vi [options] [file] 

3, command options

vi / vim divided into three modes, namely, mode command (Command mode), the input mode (Insert mode) and line mode (Last line mode)

+ <Line number>: Position the cursor to the specified line number of the line
+: open a file, the cursor to the last row of the first row
+ / word: open a file, the first line only target word is matched to the first row
-b: open the file in binary mode for editing binary files and executable files;
-C <command>: after completing the editing of a task file, execute the instruction given;
-d: diff file open mode when editing multiple files, display file differences section;
the -l: use lisp mode, open the "lisp" and "showmatch";
-m: cancel function to write the file, reset the "write" option;
-M: Close editing ;
-n: not practical cache function;
-o <file number>: Specifies the number of open files simultaneously specified;
-R & lt: opens the file in read-only mode;
-s: quiet mode, any error messages unrealistic instruction.

1) Command Mode

Flip command:
the Ctrl + U: upturned half page;
the Ctrl + D: folded downwards night;
the Ctrl + F: a folded downwards;
the Ctrl + B: an upturned;

Characters by moving the cursor:
H: the cursor to the left by one character
l: the cursor one character to the right (lowercase L)
K: the cursor up one character
j: the cursor down one character
nh / l / j / k: the Cursor left, right, up and down movement n characters

Moving a cursor in English units:
W: Move to the next word of the first word
e: skip this next word or suffix
b: Skip current or previous word of the first word
nw / e / b: n mobile word

Jump inline:
0 (number 0): Move the cursor to the beginning of the current line
^: The first line of the first non-blank character
$: Move the cursor to the end of the current line
n spaces (n represents a number): to the current cursor right movement row n characters

Jump between the lines:
nG (n represents a number): Move the cursor to the first non-blank character of the n-th row of the article, if the line is empty, the beginning of the line
gg: Move the cursor to the first line of the non-document null characters, if the line is empty, then the first line
G: the cursor moves to the first non-blank character in the last line of the article
n + ENTER: a first non-blank character cursor line is moved down from the current line n, if empty rows, the first row

Delete a single character:
x or X: delete a character, the cursor is deleted after x, and before the X cursor is deleted;
NX (n represents a number): to delete characters backwards n
nX (n represents a number): Delete the n-th forward character

Delete command:
dd: delete whole line cursor line;
D: Delete all characters from the cursor to the end of the line the cursor;
NDD: delete the current line and the line n-1;
DNG: Delete cursor line to the n All data lines
dG: delete all the data where the cursor to the last row of
dnj (n represents a number): delete cursor line down the row n + 1
dw: delete the cursor back to the characters between the next word
de: delete this word character after the cursor (cursor contains characters)
db: remove this word character before the cursor (contain character under the cursor)

Copy Command:
YY: copy cursor entire line, or the Y
NYY: copy down cursor line comprises n-1 line
y ^ or y0: copy cursor line to the first line
y $: copy cursor line end of the line
yw: copy a word
y2w: copy the two words
ynG: copy all of the data cursor line to the n-th row
yG: copy the cursor to the last row of all the data
y1G: copy the file to the first
ynj (n represents a number): copy cursor line to a lower row n + 1

Paste command:
P: Paste cursor to (the)
P: cursor attached to a front (upper)

Replace command:
NR characters: n characters after the cursor is replaced by a single character you want to replace
R: replace mode, needs to be replaced directly input characters at the cursor

Undo:
u: time before undone editing operation
nu: Direct revokes the last editing operation n times
continuously u command to undo previous edits n operation
Ctrl + r: Undo Undo the last operation

Editing operation was repeated once before:
.: Operation in edit mode time point before repeating the command mode

Visualization modes:
V: according to the selected character
V: Select rows
Esc: Cancel twice Visualization

Other commands:
J: The cursor line data and next line are combined into one row (intermediate space) to
+: Move the cursor to the first non-blank character in the next line
: - move the cursor to the first non-empty row character
H: move the cursor to the first non-blank character of the current line that the top of the screen, if the line is empty, then the first line
M: a first non-blank character cursor is moved to the middle of the line current screen of most, if empty rows, the first row
L: move the cursor to the first non-blank character of the current line that most of the bottom of the screen, if the line is empty, the beginning of the line
after the current command mode to save the changes made to the file: ZZ exit vi;

 

2) Input mode

i, I: i is the current text input is inserted at the cursor, I is the line where the cursor is inserted into the first non-blank character input character
a, A: a is a text character is inserted at the input of the current cursor , a is the next character the cursor is located at the last character of the input text is inserted
o, O: o is the beginning of the next line character is inserted into the line cursor, O is the line where the cursor on the first line by line beginning insert characters
r, R: r to replace a character that the cursor, R is a straight replacement text under the cursor until you exit the
Esc: exit and return to command mode

3) line mode

/ word: Find word string after the cursor
word:? string lookup word before the cursor
: s / word1 / word2 / g : to find the current cursor line word1, and replaced word2
: N1, N2S / word1 / word2 / G : Find lines between the first row n1 and n2 word1, and replaced word2
:% S / word1 / word2 / G: Find the entire article word1, word2 and replaced
: W: to save the edited data to the hard disk file
: w [filename]: to save the edited data in the hard disk to another file
: r [filename]: when editing data, the data is read into another file, put the contents of the file filename is added to the cursor line line
: wq or: x: save and exit
: q: quit for unmodified files
: q !: forced to quit without saving exit apply to the modified file
: set number: show line numbers
: set nonumber: cancel line number
: n1, n2 W [filename]: the contents of n1 to n2 lines to save the file called filename
: F: display the current file name, line number and the line where the cursor display scale;
: line number: cursor jumps to a specific line of the first line;
: $: the cursor jumps to the beginning of the last line;
: E file name: Open and edit the file with the specified name;
: the n-: If you open multiple files at the same time, continue to edit the next file;

Edit multiple files:
vim FILE1 FILE2 FILE3
the Next: Switch to the next file
prev: switch to previous file
last: Switch to the last file
first: Switching to the first file
q quit current file
qa all out

Show ignored or sensitive characters:
: the SET ic
: the SET noic
ic = ignorecase

Setting automatic indentation:
: AI SET
: SET noai
AI = autoindent

The found text is highlighted or Cancel:
: the SET hlsearch
: the SET nohlsearch

Syntax highlighting:
: syntax ON
: syntax OFF
Note: The properties currently in effect, if you want to modify the configuration file to be permanent

Configuration file:
/ etc / vimrc for all users
~ / .vimrc for the current user

 

Guess you like

Origin www.cnblogs.com/liuzgg/p/11813865.html