Brief introduction
Vi:visual Interface, Text editor
Text encoding: ASCII, Unicode
Type of text editing:
Line Editor: SED
Full Screen Editor: Nano, VI
Vim-vi improved
Use
Vim: A patterned editor
Basic mode:
(1) Edit mode, Command mode
(2) Input mode
(3) Last-line mode: Built-in command line interface
Open File:
# vim [OPTION] ... FILE ...
+#: After opening the file, just leave the cursor at the beginning of line #
+/pattern: Immediately after opening the file, leave the cursor at the beginning of the first line that is matched to the PATTERN
Mode conversion:
Edit mode--Input mode
I:insert, enter at the cursor position
A:append, enter after cursor location
O: Opens a new line below the line where the current cursor is located
I: Input at the beginning of the line where the current cursor is located
A: Enter at the end of the line at the current cursor
O: Opens a new line above the line where the current cursor is located
Input mode--edit mode
Esc
Edit Mode--last-line mode
:
Last-line mode--edit mode
Esc
To close a file:
: Q exit
: q! Force exit, discard the modifications made
: Wq Save Exit
: X Save exit
: W/path/to/somewhere
ZZ: Save exit
Cursor Jump:
Jump between characters:
H: Left
L: Right
J: Next
K: Up
#COMMAND: Jumps the number of characters specified by #
Jump between words:
W: The first word of the next word
E: The ending of the current or next word
B: The first word of the current or previous word
#COMMAND: Specifies the number of words to jump by # at one time
Beginning line End Jump:
^: jumps to the first non-whitespace character at the beginning of a line
0: Jump to the beginning of the line
$: Jump to end of line
Move between rows:
#G: Jump To line specified by #
G: Last line
1G, GG: First line
Move between sentences:
)
(
Move between paragraphs:
}
{
Vim's edit command:
Character editing:
X: Delete the character at the cursor
#x: Delete the # characters at the beginning of the cursor
XP: Swap the position of the character where the cursor is located and the character after it
Replace command (R, replace)
R: the character at which the cursor is replaced
Delete command:
D: Delete command, can be combined with the cursor jump character, to achieve range deletion
d$: Delete to end of line
d^: Delete to the beginning of the line (first character)
D0: Delete to the beginning of the line (first column)
DW: Delete the first word to the next word
De: Delete the ending to the current word or the next word
DB: Delete the first word to the current or previous word
#COMMAND: Delete multiple
DD: Delete the line where the cursor is located
#dd: Multi-line deletion
Paste command (p, put, paste)
P: If the buffer is an entire row, paste the current cursor below the row, or paste it at the end of the current cursor.
P: If the buffer is an entire row, the current cursor is pasted above the row, otherwise, it is pasted to the front of the current cursor position.
Copy command (y, yank)
Y: Copy, work behaves similar to D command
y$: Copy to end of line
Y0: Copy to beginning of line (first column)
y^: Copy to beginning of line (first character)
Ye: Copy to the ending of the current word or the next word
YW: Copy to the ending of the current word or the next word
YB: The beginning of a word copied to the current or previous word
#COMMAND: Copy Multiple
YY: Copying rows
#yy: Copying Multiple lines
changing commands (c, change)
C: Modify
Edit mode--Input mode
C $: Delete to end of line and enter new content
c^: Delete to the beginning of the line (first string) and enter new content
C0: Delete to the beginning of the line (first column) and enter new content
CB: Delete the beginning of the current or previous word and enter a new content
CE: Delete the ending of the current word or the next word and enter new content
CW: Delete the ending of the current word or the next word and enter new content
#COMMAND: multiple deletions and inputs
CC: Delete and enter new content
#cc: Delete multiple rows and enter new content
Other editing operations
Visualization mode:
V: Selected by character
V: set by row
Note: Often combined with edit commands: D, C, y
To undo previous edits:
U (undo): Undo Previous action
#u: Undo a specified number of actions
Undo a previous Undo
Ctrl+r
Repeat the previous edit operation:
.
Turn screen operation:
CTRL+F: Flip a screen to the end of the file
CTRL+B: Flip a screen to the file header
Ctrl+d: Turn half screen at the end of the file
Ctrl+u: Turn half screen to file header
Vim comes with a practice tutorial: Vimtutor
Last-line mode in VIM:
Built-in command-line interface
(1) Address delimitation
: Start_pos,end_pos
#: The specific # line, for example, 2 means line 2nd
#,#: From the left # indicates the line start, to the right # indicates the end of the line
#,+#: The start of the line from the left #, plus the number of rows on the right # representation
.: When moving forward
$: Last line
., $-1
%: Full text, equivalent to 1,$
/pat1/,/pat2/:
Starts from the first line that is matched to the pat1 pattern, until the end of the line that was first matched to by the PAT2
#,/pat/
/pat/,$
How to use:
followed by an edit command: D, y
W/path/to/somewhere: Save a range of rows to a specified file
R/path/from/somefile: Inserts all content from the specified file at the specified location
(2) Find
/pattern: Looks at the end of the file from the current cursor location
? PATTERN: Finds the file header from the current cursor location
N: Same direction as command
N: Opposite direction with command;
(3) Find and replace
S: Complete the Find and replace operation in the last line mode
s/what to look for/replace with content/modifiers
What to look for: Available modes
Replace with: cannot use mode, but can use \1, \2, ... You can also use the "&" reference to find the entire contents of the previous lookup
Modifier:
I: Ignore case
G: global substitution; By default, each row replaces only the first occurrence of the
Find separators in substitutions/can be replaced with other characters, such as
[Email protected]@@
s###
Multi-file Mode:
Vim FILE1 FILE2 FILE3 ...
: Next Next
:p Rev A previous
: First One
: Last One
: Wall Save All
: Qall Quit all
Window-delimited mode:
Vim-o|-o FILE1 FILE2 ...
-O: Horizontal split
-O: Vertical split
Switch between windows: Ctrl+w, Arrow
Single File Window segmentation:
Ctrl+w,s:split, Horizontal split
Ctrl+w,v:vertical, Vertical split
Customizing the working characteristics of vim:
Configuration file: Permanently valid
Global:/ETC/VIMRC
Personal: ~/.VIMRC
Last line: The current VIM process is valid
(1) Line number
Display: Set number, abbreviated as set Nu
Cancel display: Set Nonumber, abbreviated to set Nonu
(2) Bracket matching
Match: Set Showmatch, abbreviated as set SM
Cancel: Set NOSM
(3) Auto Indent
Enable: Set AI
Disabled: Set Noai
(4) Highlight Search
Enabled: Set Hlsearch
Disabled: Set Nohlsearch
(5) syntax highlighting
Enabled: Syntax on
Disabled: Syntax off
(6) Case of ignoring characters
Enable: Set IC
Do not ignore: set Noic
Get help:
: Help
: Help Subject
This article is from the "Ricky Technology Blog" blog, make sure to keep this source http://r1cky.blog.51cto.com/10646564/1773850
Linux Text editor vim