Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Vi / vim command


May 24, 2021 Vim



"/*========================================*\
Common instruction collection
"\*========================================*/
System time
" :map <F7> a<C-R>=strftime("%c")<CR><esc>
" :s/__date__/\=strftime("%c")/

"/*---------------------------------------*\
The underlying command
"/*---------------------------------------*\
"Ctrl-q can be copied, pasted, and replaced with line operations
" ctrl+w+j ctrl+w+k (:bn :bp :bd)

" '. It moves the cursor to the last modified line
" `. It moves the cursor to the last modification point
" . Repeat the last command
" slt;C-O-Gt; : Jump back and forth along your jump record in turn (starting with the most recent one)
" slt;C-I-Gt; jump forward along your jump record in turn
"ju(mps): Lists your jump footprints
: History: Lists historical command records
: :his c: Command line command history
: :his s: Search command history
q/ : Search for a window in the history of commands
q: : The window of command line command history
"g ctrl-g calculates the file character
" ( , . .
gg, G (2G) file head
"gd dw gf ga (pre-conversion)
" gg-G full auto-indentation, sg single-line indentation

""ci" removes all characters from a pair of "" and goes into insertion mode
"?ci(remove all characters in a pair of () and enter insert mode."
Delete all the characters in a pair of . and enter insert mode
"The ci' deletes all the characters in a pair of ' and goes into insertion mode
"Cit removes all characters inside a pair of HTML/XML labels and enters insertion mode
""ci" ci'ci' removes all characters from a pair of quotation marks ('or 'or') and enters insertion mode
"
""vi" selects all the characters in a pair of . .
"vi (select a pair of () all characters."
"Choose a pair of all the characters in the
"Select all the characters in a pair of . .
"The vit selects all the characters inside a pair of HTML/XML labels
""vi' vi'vi' selects a pair of quotation mark characters ("or 'or') for all characters

" crl-t back ( ctags ) at the prototype of the function
" ctl-p auto-complement (edit status)
" : X encrypted save (to enter a password)
" ? / (N n)
f (F, t) find the character
" w(e) moves the cursor to the next word.
5fx means the 5th x character after looking for the cursor.
5w(e) move the cursor to the next five words.

b Move the cursor to the last word.
0 move the cursor to the beginning of the line.
" - Move the cursor to the beginning of the line.
" Move the cursor to the end of the line.
H moves the cursor to the first line of the screen.
M moves the cursor to the middle line of the screen.
" L Moves the cursor to the end line of the screen.

" c-f (i.e. ctrl key pressed with f key)
"c-b (i.e. the ctrl key is pressed with the b key) page turn
c-d (bottom page) c-u (top half) c-e (one-line scroll)
zz places the row where the cursor is in the center of the screen
zt lets the row where the cursor is located on the top row of the screen
zb places the cursor on the bottom row of the screen


" In vi y means copy, d means delete, p means paste. Where copy and delete is the move command with the cursor
yw means copying the content from the current cursor to the end of the word where the cursor is located.
dw means deleting the content from the current cursor to the end of the word where the cursor is located.
y0 means copying the content from the current cursor to the beginning of the line where the cursor is located.
d0 means deleting content from the current cursor to the beginning of the line where the cursor is located.
y$ (Y) means copying content from the current cursor to the end of the line where the cursor is located.
d$(D) means deleting content from the current cursor to the end of the line where the cursor is located.
yfa represents the content between copying the first a character from the current cursor to the cursor.
dfa means deleting content between the first a character from the current cursor to the cursor.
" s(S),a(A),x(X),D
" yy represents the line where the copy cursor is located.
" dd means deleting the line where the cursor is located.

5yy means 5 lines below the copy cursor.
5dd means 5 lines below the removal cursor.
y2fa means copying content between the second a character from the current cursor to the cursor.
: 12,24y means copying between lines 12 and 24.
: 12, y means copying the content between line 12 and the line where the cursor is located.
" : 24y represents the content between the line where the copy cursor is located and the 24th line. Remove similar.
TAB is a tab, taken out separately to make a section because this thing is really useful.
Enter this command and move a tab to the left on the line where the cursor is located.
Enter this command and move a tab to the right on the line where the cursor is located.
Enter this command and move one tab to the right 5 lines after the cursor.
" :5>>(>>>) :>>(>>>)5
This command moves 12 to 14 lines of data one tab to the right.
This command moves 12 to 14 lines of data two tabs to the right.
" : set shiftwidth s4 sets auto-indentation of 4 spaces, of course, to set auto-indentation first.
" : set sts=4 i.e. set softtabstop to 4. Enter tab and jump 4 grids.
The actual tab of :set tabstop=4 is 4 spaces, not the default 8.
" : set expandtab After entering the tab, vim fills the tab with the appropriate spaces.
" :g/^/exec 's/^/'.strpart(line('.').' ', 0, 4) Insert the line number at the top of the line
The set ai setting automatically indents
"5ia-lt;esc-gt; repeat insert 5 a-characters

"/*---------------------------------------*\
Replace command
"/*---------------------------------------*\
Replacement text 2009-02-34 ----; 2009-02-34 00:00:00
" :%s/\(\d\{4\}-\d\{2\}-\d\{2\}\)/\1 00:00:00/g

":%s/heaser/add header to the head of each line
:%s/$/ender/Addender at the end of each line

: s/aa/bb/g replaces aa with bb from all strings containing aa that appear on the line where the cursor is located
"://bb/g replaces all aa that appears on the line where the cursor is located with bb, replacing only the word aa."
:%s/aa/bb/g Replaces aa from all strings that contain aa that appear in the document with bb
: 12,23s/aa/bb/g replaces aa with bb from all strings containing aa that appear from lines 12 to 23
":12,23s/'/' will add the character from the beginning of the line 12 to 23
: %s/fred/joe/igc A common replacement command, the modifier igc and perl mean the same thing
s/dick/joe/igc replaces these eligible rows

" : g/ s . .
":%s/r//g removes the DOS way of carriage return
" :%s / s// Remove the end-of-line blanks (%s/s*$//g)
":g!/'dd/d deletes lines that do not contain the string 'dd'
" : v / .
: v/./., /./-1join compressed empty lines (multi-line empty lines merged into one line)
" : g / . . . . .
" : g//pu , double the number of empty lines in the text (pu s put), which used to have an empty line between the two lines, and now becomes two
" : g/ s/m0 Flip article by line (m s move)
" :g/fred/,/joe/d not line based (very powerfull)
" : . | . |
: g/fred/t$ copy line, from fred to end of file (EOF)

:% norm jdd interlasted deletion, translation: % indicates that all rows are operated, norm indicates that the instructions are followed by the normal pattern, j is the next line, and dd is the delete line

":'a,'bg/fred/s/dick/joe/igc ('a,'b specifies a range: mark a to mark b)
g// indicates with a regular expression that the row in which the operation is performed must be free to match, and g// is a global display command

The /joe/e cursor stays at the last letter of the matching word
The /joe/e1 cursor stays at the next letter that matches the last letter of the word
The /joe/s cursor stays at the first letter of the matching word
" /'joe.'fred.'bill/standard regular expression
" /
"/forum" (.) s pent multi-line match
There can be _s blanks in the middle of the /fred?i/joe/i, including line breaks
/fred|joe matches FRED or JOE
"/-lt;fred?gt;/i matches fred, fred must be a separate word, not a subsetch
" /?lt;d\d\d\gt; matching 4 numbers.'lt;d\d{4}.'gt;

column, replacing all str1 in the third column
" :%s:\(\(\w\+\s\+\)\{2}\)str1:\1str2:
Exchange the first and last columns (4 columns in total)
" :%s:\(\w\+\)\(.*\s\+\)\(\w\+\)$:\3\2\1:

The global display command is a regular expression of : g-plus
Translation: :g/?pattern'/'cmd' is the global find match, and then the command is executed on these lines.
" : /
" :
" : / .|

"/*---------------------------------------*\
" Multi-document operations (basic)
"/*---------------------------------------*\
" With :ls! All current buffer can be displayed
: bn jumps to the next buffer
:: bp jumps to the last buffer
: wn save the current file and jump to the next one
: wp the current file of the deposit and jump to the last one
: bd Take this file off the buffer list
:b 3 jumps to the third buffer
:: b main jumps to a name that contains the buffer of the main

"/*---------------------------------------*\
Column replication
"/*---------------------------------------*\
Translation: smh.com.au
" : % s
":%s s
":%s s
A reverse reference, or memory
" : s /
" :%s/
"Non-greedy match,"
":%s/./new.pdf /: Just delete the first pdf
Across possible multiple lines
" :%s/lt;!--.-?--gt;/: And delete multiple lines of comments (?? W hy say "again"?
" : help /
: s/fred/-lt;c-r-gt;a/g: Replace the fred into the contents of the register a, ha ha
Complex commands written on a line
" :%s/\f\+\.gif\>/\r&\r/g | v /\.gif$/d | %s/gif/jpg/
It's about using | Pipes

"/*---------------------------------------*\
Case conversion
"/*---------------------------------------*\
" g to : line flip
vEU : Capital (broad)
vE - : Word Flip (broad word)
Change the case of the letters under the cursor
3 to change the case of the next 3 letters
"The g-w word flips
U changes all letters in visual mode to capital letters
gUU changes the letters of the current line to capitals
u Change all letters in visual mode to lowercase
The guu changes the letters of the current line to lowercase
gUw changes the words under the cursor to capitals.
Guw changes the words under the cursor to small below.


File browsing
: Ex : Open the directory browser, note that the initials E are capital
: Sex: Opens the directory browser in a split window
: : Shows the current buffer situation
: cd:: Enter the parent directory
" :pwd
: :args : Shows the files that are currently open
:lcd %:p:h: change to the directory where the current file is located
The lcd is a file name that tightly changes the working path of the current window, and % is a file name that represents the current file.

Plus :p to full name (that is, with path), plus :h analysis to remove the path

Here's a quick check of the vim commands: Vi / vim command