One (regular expression)
A regular expression (REGEXP) is a pattern written by a class of special characters and text characters, where some characters (metacharacters) do not represent the literal meaning of a character, but are a function of control or wildcard.
Divided into two categories: basic Regular Expression: BRE extended Regular expression: ERE
Meta-character classification: character matching, number of matches, position anchoring, grouping.
Character matching: · Represents a single character of a match
. Escape, meaning the character of (·)
"" means to match any single character within the specified range, "" in the original meaning, without escaping
"Bracket character" means any single character that matches a specified range
": Alnum:" Letters and Numbers ": Alpha:" represents any English uppercase and lowercase characters
": Lower:" Lowercase letter ": Upper:" Uppercase
": Blank:" White space character ": space:" Horizontal and vertical whitespace characters (larger than blank range)
":p unct:" Punctuation
Number of matches: used to indicate the number of occurrences of the preceding character after the number of characters to be specified.
- Indicates the number of occurrences of the preceding character repetition, including 0 times
* Any character of any length
\? Match the preceding character 0 or 1 times
+ Match the preceding character at least 1 times
{n} matches the preceding word n times, is specified m times
{n,m} matches the preceding character at least n times, up to M times
{, n} matches the preceding character up to n times
{N,} matches the preceding character up to n times
Position anchoring: The position where the position appears.
^ Beginning of the line anchor, for the leftmost mode
$ line End anchor for the right side of the pattern
\> ending anchor for the right-most side of the word pattern
\< the first anchor for the leftmost word pattern
\b The boundaries of a word
Group: () binds one or more characters together and processes them as a whole.
Second, VIM's basic command operation
VIM's text editor
+# after opening the file, leave the cursor at the beginning of #
-D to compare multiple files
-M read-only way to open files to avoid mis-operation
-E enters ex mode (edit mode)
Three main modes
Command mode: Default mode
Insert mode: Edit mode
Extended Command mode: Ex mode
To get the command mode into insert mode, press ESC to exit some actions:
Press I cursor does not understand
Press I to move to the beginning of the line
Press the A cursor to move backward by one character
Press the A cursor to move to the end of our line
Press O to toggle the new line at the cursor
Press O to toggle the new line on the cursor upstream
Press in command mode: Enter ex mode.
In ex mode:
Wq Save exit Q exit
Q! Forced exit, modified not counted
W space and file will be able to transfer the content of vim to the file
R space and file can read the contents of the file into vim
Some common uses in command mode are:
Beating between characters: H left L right J down K
Preceded by a number #, beating with other keys
Beats between words: W jumps to the beginning of the next word
E jumps to the ending of the next word
B Jump to the beginning of the previous word
can also match # to beat
Current page tick: H jumps to the top of the current page
M jumps to the middle of the current page
L bounce to the bottom of the current page
Jump at the end of a line: ^ jumps to the first non-whitespace character of the beginning
0 jump to the beginning of the line
$ jump to end of line
Move between rows: G jumps directly to the last line of the entire file
GG jumps directly to the first line of the entire file
Some shortcut keys: Ctrl +f flipping a page to the end of a file
Ctrl+b a page to the file header
Ctrl+d half page to the end of the file
Ctrl+u half page to file header
Character editing in command mode: x Delete (cut) the character at the cursor
#x preceded by a number that deletes several characters
Xp swap the position of the character at the cursor with the trailing character
J Delete line breaks after the current line
~ Convert case
Replace command: R replaces the character at which the cursor is located
R switches to replace mode, bulk substitution characters
Delete command: D delete character, can be combined with the cursor jump character to achieve range deletion
d$ Delete to end of line
d^ Delete to the beginning of a non-whitespace character
D0 Delete to the beginning of the line, not including the cursor
DD Delete cursor line (with number bulk delete)
D deletes from the current cursor to the end of the line
Copy command: (can be pasted by p after copy)
Y copy
y$ Copy to end of line
Y0 copying to the beginning of the line
y^ copy to non-whitespace character header
YY the copy cursor is in the row
Multi-line replication #yy with numbers
Y copy Entire row
Change the command: C to switch to insert mode, with D for the corresponding operation
100i Wang [esc] Paste Wang 100 times copy Wang 100 times
Extended Command mode: (ex) mode
Address delimitation:
: # Enter a number, skip to the first few lines
#,#: From the first line to the first line, and then with the corresponding command
· Indicates when to move forward
$ represents the last line
% indicates full file content
S to complete the find and replace operation in extended mode
Format: s/What to look for/replace with content/modifiers
Modifier: I ignore case
G Modified global substitution (the default is to replace only the first change of each line)
GC Global replacement when asked before each
Command mode: (lowercase) u undo #u Undo Multiple changes
(uppercase) U undo all changes after the cursor falls on this line
Press Ctrl-r to redo the last undo change (Rewind)
· Redo Previous Action
N. Redo the previous operation N Times
Vim Registers
There are 26 named registers (which can be done in different windows)
The name is expressed in a B c .... z.
Format: Registers are placed between numbers and commands
such as: "Ayy means that the current cursor line is copied to the a register
"AP means to paste the contents of a register
VIM "F1 F2" processing multiple files at once
Just go in. Default in First file
: Next Next
: Prev Before a
: Qall Quit all
: Wqall Save to exit all
VIM uses multiple windows
Vim-o up and down sub-screen
Vim-o left and right split screen
Switch back and forth between Windows Ctrl+w
Wqall after completion
Add line numbers in vim
Show set Nu
Cancel Set Nonu
To keep the line number permanently valid, you must save the configuration file: (with VIM)
Global:/ETC/VIMRC Personal: ~/.VIMRC
Set text width in vim
Enable set TextWidth =65
Disable Set Wrapmargin =15
Set the identifier line where the cursor is located in vim
Enable set Cursorline (CUL)
Disable Set No cul
For more detailed usage please check: VIM Help
For regular expressions, VIM's basic command operation