当前位置:网站首页>VIM Introduction Manual, (vs Code)

VIM Introduction Manual, (vs Code)

2020-11-08 21:27:00 RioTian

If you want to be in VScode Use in Vim You need to follow the plug-in first

install vim plug-in unit

VS Code Enter the shortcut key in the shift + ctrl + x, Or open it directly Extended installation navigation
Search for vim, choice Vim

, Click on install install
After installation, you can use vscode Under the vim The model
recommend : close vim Extended useCtrlKeys, Keep some VS Code Some of its own common shortcut keys , stay settings.json Add configuration inside "vim.useCtrlKeys": false,

—————————— Text begins ——————————

vim introduction

stay vs code When you open a file in , The file status is default to vim Under the Normal Pattern
Input i, from Normal Mode switch to Insert Pattern , Now you can input text normally
single click ESC Can return Normal Pattern

stay Normal The following operations can be performed in mode

command ( Key ) effect
i Get into Insert Pattern
ESC Insert Mode back Normal Pattern
:q Exit file editing (vs code I can't use it )
:w Save the modified file (vs code I can't use it )
:wq preservation + Launch documents (vs code I can't use it )

vim location

vim Cursor positioning command

Cursor up and down, left and right

command effect Pattern
h Move the cursor one space to the left Normal
l Move the cursor one space to the right Normal
j Move the cursor down one line Normal
k Move the cursor up one line Normal
Up, down, left and right Switch cursor up and down, left and right Normal & Insert

notes : banlk The character means Space , tab, Line break , Return, etc

In line cursor positioning

command effect Pattern
0 To the beginning of the current line Normal
home To the beginning of the current line Normal & Insert
^ The first one in the current line is not blank Character position Normal
$ To the end of the current line Normal
g_ At the end of the current row, there is a No blank Character position Normal
gg To the first line Normal
nG n Number the lines , To the first n That's ok Normal
G To the last row Normal

Vocabulary positioning

1、 Default mode , A word consists of letters , Numbers and underscores

command effect Pattern
w w( A lowercase letter ), To the beginning of the next word Normal
e e( A lowercase letter ), To the end of the next word Normal

2、 If the word uses blank Character separation , Use uppercase E or W Separate

3、 Match words

command effect Pattern
* Move to the next word that matches the current cursor ( It's loaded at the moment VS Code Vim Component does not work ) Normal
# Move to the previous word that matches the current cursor Normal

Parentheses matching

command effect Pattern
% Locate the other half of the bracket that the cursor is in ,( Position the cursor on a bracket before use ) Normal

vim Insert

vim Insert command , After the cursor is positioned , Before the command is inserted , Switch to after the command is executed Insert Pattern

command effect Pattern
a Insert... After the cursor , After the cursor is positioned, enter i The command is inserted in front of the cursor by default Normal
o A lowercase letter o Insert a new line after the current line , It's equivalent to the carriage return effect Normal
O Capitalization O Insert a new line before the current line Normal

vim lookup

vim It is achieved by regular matching
stay Normal In mode , First enter /, Enter search mode
Enter the words you want to search for , At this time in vs code All matches are highlighted in
single click enter( enter ) Post key , Click on n Key, the cursor can locate the matching items one by one

vim Replace

The following substitutions are in VS Code Not available in , have access to Its own Ctrl + H Replacement
grammar : vim The replacement syntax of is : :[addr]s/ The character to be replaced / Replace character /[option]

: ( English colon )

Indicates the start of the replace command

1、.( decimal point ) Press the line before
2、$: Represents the last line of the file
3、%: Represents the entire current file
4、n( Line number ): It means the first one n That's ok
5、n1,n2: Express The first n1 Go to the first place n2 That's ok
6、n, $: Express The first n Line to the last line of the document
7、., $: Express From the current line to the last line of the document
8、., n: Represents the current line to the document No n That's ok

s Replace operation

Letter s Represents a replacement operation

[option] Operation type

[option] Indicates the type of operation
1、g: Represents a global replacement , Replace all matches within the search scope
2、c: To confirm the replacement , You need to Input y Confirm one by one
3、p: Indicates that the alternative result is displayed , Press enter Replace after
4、option When omitted, only the first matching string in each line is replaced

Example

:.s/from/to/ Put the first in the current line from, Replace with to. If the current line has more than one from, Then only the first one of them will be replaced .
:%s/from/to/g Put all the from Replace with to
:1,5s/from/to/c Put the section of the document 1 To the first 5 That's ok , The first one in each line from Replace with to , And it needs to be confirmed
:6,$s/from/to/gc From 6 From the beginning of the line to the last line , Will all from From to to, And it needs to be confirmed
:.,7s/from/to/p From current line to 7 That's ok , Put one in each line from Replace with to, Display the replacement result before replacement , Press enter to take effect

vim Copy / Paste / Delete

vim Copy and paste command

1、 Paste

command effect Pattern
p A lowercase letter p, Insert copy item after cursor Normal
P Capitalization P, Insert the copy before the cursor Normal
np(nP) Duplicate n Time Normal

2、 Copy

command effect Pattern
y Copy the current line and the line after it , There are two lines Normal
yy Copy current line Normal
nyy n For greater than the number , Copy n That's ok , The first line is the line where the cursor is located Normal
ye Copy from the cursor position , To meet the first empty end ( Do not include spaces ) Normal
yw Copy from the cursor position , To meet the first empty end ( Including Spaces ) Normal
y$ Copy from the cursor position , At the end of the current line , Including Spaces Normal
y0 Copy from the cursor position , To the beginning of the current line , Including Spaces Normal
ynl Start at cursor position , Copy right n Characters Normal
ynB Start at cursor position , Copy left n Word Normal

How to copy an area , More accurate selection of copy area ?
stay Normal In mode , Position the cursor to the beginning or end of the target copy area ,
Enter the command v( A lowercase letter ) Enter attempt mode
Move the cursor , Where the cursor passes is selected ,( It's the same as mouse selection )
When the region selection is finished , Input y command , Replication success
If input Capitalization V command , In this case, you can only select the area in the action unit

How to achieve cross file copy / Paste ?
In the file A Copy the content in the file B Use in ,
Use command +y, Add the copied content to the system's clipboard , For use by other programs ( This order is in debian It's not easy to use , It's only useful if you copy all of them , Right click to copy the part ,)
Use command +p, You can cut the contents of the system palette , Paste to current file ( This command doesn't work well )
stay Insert In mode (VS Code in Normal Patterns can also ), Using shortcut keys shift+insert You can cut the contents of the system palette , Paste to current file , ( Recommended )

3、 Delete

command effect Pattern
dd Cut the current line Normal
ndd shear n That's ok , The first line of current behavior Normal
dw Cut from the cursor position , To meet the first empty end ( Including Spaces ) Normal
de Cut from the cursor position , To meet the first empty end ( Do not include spaces ) Normal
d$ Cut from the start of the cursor , At the end of the current line , Including Spaces Normal
d0 Cut from the start of the cursor , To the beginning of the current line , Including Spaces Normal
dl Delete cursor character Normal
dh Delete the character before the cursor position Normal
dnl Start at cursor position , Cut right n Characters Normal
dnh Before clipping the cursor n Characters ( Excluding the character where the cursor is located ) Normal
dH Cuts everything before the current cursor Normal
dL Cuts everything after the current cursor ( Including the character where the cursor is ) Normal

How to delete an area of Hu , Delete area more accurately
Same as the copy above , Just put Copy command y Switch to The delete command d that will do

revoke / Cancel, undo, modify

Cancel modification order and Cancel undo modify order

command effect Pattern
u Undo the previous modification Normal
ctrl+r Restore the undone changes Normal

Add

1、 Repeat the previous order Normal Input... In mode .( decimal point ), n. Repeat the previous command n Time

2、 Operate on the contents in brackets ( Position the cursor to the left bracket )

  • ci’、ci”、ci(、ci[、ci{、ci< Change the text content in these paired punctuation marks separately
  • di’、di”、di( or dib、di[、di{ or diB、di< Delete the text content in these paired punctuation marks respectively
  • yi’、yi”、yi(、yi[、yi{、yi< Copy the text content of these paired punctuation marks separately
  • vi’、vi”、vi(、vi[、vi{、vi< Select the text content in these paired punctuation marks respectively

3、 Future generations ( Copy / Delete )

Normal In mode , First, select all the documents : ggVG/ggvG => (gg Let the cursor move to the first line , v/V Get into Vision Pattern , G Move to last line )
Input d Delete the selection , Input y Copy the selection

4、 Code indentation

Normal In mode , Get into Vision Pattern , Select the object code block ,
Shortcut key shift+> Indent right
Shortcut key shift+< Indent left

—————————— End of text ——————————

about vi/vim: You don't need a mouse , No need to use a keypad , It is an editor that can complete many complex functions of text editing just by using the big keyboard . Otherwise ,Visual Studio And there won't be vim Plugin .

版权声明
本文为[RioTian]所创,转载请带上原文链接,感谢