vim - vi enhanced version. text editor
Format: vim [options] [file ..]
Note: If the file exists, the file is opened and displayed content, if the file does not exist, create it first save after editing
[Options] Common options:
vim + [num]: direct access to the num-th line editing of documents
vim +: direct access to the last line
vim + / PATTERN: PATTERN mode to jump directly to the first match line
vim -m: open read-only file
vim -d file1 file2 ...: Open edit multiple files
vim of three modes:
Command Mode: default mode, move the cursor, cut / paste text, etc.
Input (edit) mode: change the text
Bottom row (Extended) mode: save, exit, find, etc.
Mode switching:
1, an input mode command to the formula
i: input at the current cursor:
I: the line of the current cursor row
a: after the cursor at the input
A: In the end of the current cursor line input
o: below the cursor line add a blank line input
O: above the line where the cursor is add a blank line input
2, the input mode to command mode:
Press ESC
3, command mode to line mode:
button
4, line mode to command mode
Press ESC twice
Command mode shortcut keys used
1, the cursor
Jump between characters:
h: Left l: Right j: the k: the
# [H | l | j | k]: Jump # characters
Key word Jump
w: Skip a word after word first
b: Skip to the previous word or the first word of the current
e: the current or next word endings
Current page jump:
H: The current top of the screen
L: The current bottom of the screen
zt: the line where the cursor is moved to the top of the screen
zz: The cursor is moved to the middle of the current line of the screen
zb: the line where the cursor is moved to the bottom of the screen
Mobile inline:
0: 0 Digital absolute beginning of the line
^: The first non-blank character
$: The absolute end of the line
Interline movement:
#G jump to the line #
#gg jump to the line #
G: The last line
1G: First row
gg: first line
Moving between sentences:
):
(
Moving between paragraphs:
{
}
Flipping operation:
Ctrl + f: turn to the end of the file one screen
Ctrl + b: a screen to turn the header file
Ctrl + d: a half turn to the end of the file screen
Ctrl + u: turn half screen to the header file
2, the editing operation
Character Editor
x or the DEL key: Delete the character at the cursor location
#x: Delete the cursor after the start of the # character
xp: exchange positions of characters and the character at the back of the cursor
~: Case conversion
J : Delete line breaks at the end of the current line
Replace command:
R & lt : replacement character at the cursor, an input character to be replaced, can be used in the case of misspelled words
R: REPLACE mode is switched to the
Delete command
d: Delete command
Command in conjunction with the cursor jumps
d $: Delete the cursor position until the end of the line all characters (including cursor character)
d ^: Delete the cursor position until the beginning of the line all characters (not including the cursor)
d0: Delete to beginning of the line
dw: Delete the first word after the first word
de: Delete the first word to the suffix behind
db: Delete the first word to the front of the first word
dd: delete a row
#dd: Delete the cursor at the following N lines
dG: Delete the document tail
dgg: Delete the first section of the document
c: change directly into insert mode after deletion
c $: Delete the cursor position until the end of the line all characters (including cursor character)
c ^: Delete the cursor position until the beginning of the line all characters (not including the cursor)
c0: to delete the beginning of the line
cc: delete a row
#cc: Delete the cursor at the following N lines
y: yank, copy
yy: copy 1 line
#yy: Copy the line #
p: paste, copy, or paste the contents yy dd delete content
Copy, or delete the entire line is
p: Paste the line under the cursor
P: Paste cursor over the line
Copy, or delete the entire line of non
p: Paste after the character cursor
P: Paste character in front of the cursor
Edit Undo:
u: undo
#u
U: Undo cursor falls on this line all changed after this trip
To resume the cancellation:
Ctrl + r, u and opposite meaning
Repeat the previous command:. ""
A check operation is repeated N times: "N."
Command Mode Special usage:
100iwang [ESC] Paste "wang" 100 times
<start position><command><end position>
Command:
y copy, d delete, gU variable capital, gu change lowercase
For example: 0y $ command means:
0-> first-line head
y-> copy from here
$ -> copy to the last character on the line
ye copied from the current position to the last character of a word present
di "cursor" between ", in this line delete" "between the content may be a plurality of symbol" '() [] {}, etc.
yi between cursor (), contents () between the copy
VI [cursor between [], contents of between [] is selected
dtx cursor delete characters met until after the first x character
ytx x Copy the characters first met until the cursor after the character
Line mode (extended mode):
1, range delimited
:start,end
DETAILED # # The first row, the second row represents e.g. 2
2, line 1 to the second
10, 19 lines 10-19
10, line 9 + 9 away from the line 10 back
It indicates the current line
$ The last line
$ -1 penultimate line
/ Pat1 /, / pat2 / pat1 is matched to the first row, the first row is matched to pat2
#, / Pat / # line from the beginning to the first match to be pat-line
% Full
Note: If no address identifier knot only cursor line check
Editing commands:
d delete
y Copy
w / path / to / somewhere: The line in the range specified file to save
r / path / to / somefile: somefile the contents of the file address inserted behind delimitation
For example, the file xxx xxx 10R inserted behind the tenth line
! Command command execution
r! # command to insert the results of command execution, such as r! hostname hostname execution result will be inserted into the document
2. Find
/ PATTERN: Find at the current cursor position to the end of the file
? PATTERN: Find the current cursor location to the end of the file
n: the order in the same direction
N: reverse direction command
3, * Find and Replace:
: Address delimitation s / search mode (regular) / replace content / GI
Things to look for: You can use patterns
To replace the contents: mode can not be used, may be used \ after 1, \ 2, etc. to the sub reference numbers; & references may also be used to find the entire contents of the foregoing
Modifiers:
g: global replace, one line appears on many occasions and replace
gc: global replacement, ask before each replacement
i: case-insensitive
&: For all references to the content matching the front portion of the alternative
Custom vim operating characteristics:
Profile: permanent
Global: / etc / vimrc
Personal: ~ / .vimrc
Extended mode: The current process effective vim
(1) Line No.
Show: set number, abbreviated as set nu
Cancel Display: set nonumber, abbreviated as set nonu
Case (2) ignore characters
Enable: set ic
Do not ignore: set noic
(3) auto-indentation
Enable: set ai
Disable: set noai
(4) smart indentation
Enable: smartindent abbreviated set si
Disable: set nosi
(5) Highlight Search
Enable: set hlsearch
Disable: set nohlsearch
(6) syntax highlighting
Enable: syntax on
Disable: syntax off
(7) display Tab and newline and $ ^ I show
Enable: set list
Disable: set nolist
(8) file format
Enable windows format: set fileformat = dos
Enable unix format: set fileformat = unix
Shorthand: set ff = dos | unix
(9) Set the text width
set textwidth=65 (vimonly)
set wrapmargin=15
(10) provided in the cursor line identification line
Enable: set cursorline, short cul
Disable: set no cursorline
(11) retain the copy format
Enable: set paste
Disable: set nopaste