--vim, the king of Linux text editing
Vim: full-screen, patterned text editor
Vi:visual interface
Vim:vi Improved (vi enhanced version)
I. VIM [options] [file..]
Vim file to open or create a new file
If the file exists, the file is opened and the content is displayed
If the file does not exist, create it when you save it for the first time after editing
Vim +# file to open and leave light in line #
Vim + File open files, and let the light at the end of the file vim + file Open file, and let the light in the end of the file line
Vim +/pattern file opens the document with the cursor at the beginning of the first line that is matched to the pattern
VIM–B file binary mode Open Text
Vim–d file1 file2 ... Compare multiple
Vim-m file Open as read-only
Vim–e file opens, directly into the extended command mode
Second, keystroke behavior is dependent on the "mode" of vim
Three main modes of VIM:
Command mode (default): Move cursor, cut/paste text
Input (Edit) mode: Modify text
Extended Command mode: Save, exit, etc.
Third, vim mode conversion:
1, Command mode---Input mode
I: Switch to input mode before the current cursor character
A: After the current cursor character, switch to input mode
o: Insert a new row below the current cursor and switch to input mode
I: Switch to input mode at the beginning of the line where the cursor is currently located
A: Switch to input mode at the end of the line where the cursor is currently located
O: Insert a new row above the current cursor and switch to input mode
2, Command mode---extended mode:--colon
Create a command prompt at the bottom of the screen on the left
3, edit mode---Command mode ESA button
4, extended mode---command mode ESA key
5, edit mode cannot be converted directly to Extended mode
6, locking and unlocking ctrl+s,ctrl+q
Iv. closing files
1, Command mode:
ZZ Save and exit
ZQ Do not save exit
2, Extended mode:
: W Save
: Q exit
: Wq Save and exit
: x save and exit equivalent to: WQ
: q! Do not save exit
: w! Forcibly saved
V. Common commands in extended command mode:
R filename reads content from other files into the current file
W filename Save the current file as a new file
addr1,addr2w filename Save Line # of the current file to # line as a new file
!command start other commands directly, after execution, press ENTER to return to the Vim interface
R!command directly launches other commands and inserts the execution results into the current position
#d Delete # # #
#, #d Delete line # to # # line
1G jump to the first line of the file
G jump to the last line of the file
Six, the operation of the command mode:
1. Move the cursor:
K: Upper J: Lower H: Left L: Right
# (KJHL) jump up or down #
2, in-line 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
3, jump between sentences: (---previous sentence)--Next sentence
4, jump between paragraphs {--last paragraph}--next paragraph
5, file line jump [[--First row]]--last line
6, 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
7, character editing:
X: Delete the character at the cursor;
#x: Delete the consecutive # characters at the beginning of the cursor
XP: Swap the position of the character where the cursor is located and the character after it
~: Convert Case
8, replace command (R, replace)
R: the character at which the cursor is replaced
R: Switch to replace replacement mode
9, Delete command:
Dd,d: Delete the line where the cursor is located
#dd: Delete contiguous multiline
d$: Delete the cursor at the end of the line (leaving a blank line)
d^: Deletes the cursor at the beginning of a non-empty line
D0: Deletes the cursor to the absolute beginning of the row
10, after deleting the character (leaving a blank line) into the input mode:
Cc,c: Copy the line after the cursor to enter mode
#cc: After deleting consecutive rows, switch to input mode
C $: Delete the cursor at the end of the line and switch to input mode
c^: Delete the cursor at the beginning of the non-empty line and switch to input mode
C0: Removes the cursor to the input mode after the absolute beginning of the line
11, copy command:
Yy,y: Copy the line where the cursor is located
#yy: Copying contiguous lines
y$: Copy to end of line
y^: Copy cursor to non-empty header
Y0: Copy cursor to absolute beginning
12, Paste command:
P (lowercase): If the deleted or copied content is a whole line, paste to the bottom of the line where the cursor is located
If the deleted or copied content is a non-full row, paste to the back of the character where the cursor is located
P (UPPERCASE): If the deleted or copied content is a whole row, paste it above the line where the cursor is located
If the deleted or copied content is a non-full row, paste to the front of the character where the cursor is located
#i "Input": Automatically copy "input" and paste # times
14. Undo Changes
U Undo Recent Changes
#u撤销之前多次更改
U undo Cursor falls on the current line after all changes to this row
Press Ctrl+r to redo the final undo change
. Repeat previous action
N. Repeat the previous action n times
Vii. operation in extended mode:
1, Address delimitation
#: Specific # line
#,#: Starting with line #, ending with # line
#,+#: Beginning with line #, continuation # line
.: When moving forward
$: Last line
., $-1 current line to penultimate line
%: 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 is first matched to the PAT2
#,/pat/start at line # until the end of the first row that the PAT matches to
/pat/,$ starts from the first line that is matched to the PAT1 pattern until the end of the file.
2, move between rows:
#G: Jump To Line #
G: Jump to the last line
1G, GG: Jump to the first line
3, 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 of command
4, Find and replace
S: Complete the Find and replace operation in extended mode
Format: s/prttern/string/modifier
s///or [email protected]@@ 或者 s###
PATTERN: Regular expressions can be used
STRING: Cannot use pattern, but can use \1, \2, (latter reference)
You can use "&" to refer to the entire content found in the previous lookup
Modifier:
I: Ignore case
G: global substitution; By default, each row replaces only the first occurrence of the
GC: Global interaction substitution, asking before each replacement
5, Visualization mode
Allow selection of text blocks
V Character-oriented
V Line-oriented
CTRL-V Block-oriented
Visualization keys can be used in conjunction with the move key:
KJHL,),}, direction arrows
Highlighted text can be deleted, copied, changed, filtered, found and replaced
Eight, vim multi-file mode
Vim FILE1 FILE2 ...
: Next Next
:p Rev Previous
: First One
: Last One
: Wall Save All files
: Qa,:qall Quit all
: Wqa,:wqall Save and exit all
Nine, VIM Multi-window mode
1, Single File multi-window
Ctrl+w,s:split, Horizontal split
Ctrl+w,v:vertical, Vertical split
2, multi-file Multi-window
Vim-o|-o FILE1 FILE2 ...
-O: Horizontal split
-O: Vertical split
3, switch between windows:
Ctrl+w Press two times to automatically jump to the next window
CTRL+W,KJHL Direction key
4, Cancel multiple windows
Ctrl+w,q: Canceling adjacent windows
Ctrl+w,o: Cancel All windows
: Wqall Save and exit all files
Ten, Vim Register
A-Z 26-Letter name register and 1 unnamed registers, often with different clipboard contents
The letter-named registers can be shared between different sessions
Example: 3 "tyy means copying 3 rows to the T register
"TP means to paste the contents of T register into the current position
Unspecified, no named registers will be used
There are 10 numbers named registers, denoted by 0-9, 0 holds the most recently copied content, and 1 stores the most recently deleted content. When new text changes and deletions, 1 dumps to 2, 2 dumps to 3, and so on.
The digital naming register cannot be shared between different sessions
Xi. Vim Edit binary file
Open file in binary mode vim–b binaryfile
In extended command mode, use the XXD command to convert to a readable hexadecimal format:%!xxd
Edit Hex File
In extended command mode, use the XXD command to convert back to binary:%!xxd–r
Save exit
12, Vim work characteristic customization
Extended mode: current VIM process valid
Change profile: Permanently valid
global:/ETC/VIMRC
Personal: ~/ . VIMRC (can be set up without this file)
1, line number
set nu:set number display line numbers
set nonu:set Nonumber suppress
2, auto indent
set ai: Enable
set noai: Disable
3, search highlighting
Set Hlsearch: Enable
set nohlsearch: Disable
4, syntax highlighting
syntax on: Enabled
Syntax off: Disables
5, ignoring the case of characters
set IC: Ignore
set noic: Do not ignore
6, parentheses match
set sm:set showmatch Enable
set nosm:set noshowmatch disabled
7, file format
set fileformat=unix settings file format for UNIX format
set fileformat=dos set file format to DOS format
8, Set text width (vim only)
default width 80 characters
:set textwidth=65 set left width
:set wrapmargin= 15 Set right width
9, set tab width
set ts (tabstop) =#
This article is from the "Love Firewall" blog, be sure to keep this source http://183530300.blog.51cto.com/894387/1836182
--vim, the king of Linux text editing