VS Code of Vim | operation without modifying the VSC default shortcut | often combined with logic

While VS Code’s built-in keyboard shortcuts are powerful enough, there’s one problem: Using the d-pad is a bit of an anti-human act, with both hands on the keyboard, you don’t need to move your wrist if you’re only typing letters; To hit the arrow keys, move your wrist or forearm. The Vim plugin focuses most of the tapping on the letter area, making it faster and more comfortable. In this article I will recommend my usual Vim operations.

directory

  • Vim plug-in installation
  • Vim basis
  • Vim composition logic is commonly used in VS Code

Vim plug-in installation

As shown above, download the Vim plug-in. Note that it is highly recommended not to use Vim’s built-in Ctrl keyboard combination, as it overwrites VS Code’s own shortcuts as well as those of other plug-ins.

As shown above, you can search for the useCtrlKeys configuration in Settings and deselect it.

Note that you can still scroll up and down the page using Ctrl + U and Ctrl + D, and the number of lines to scroll is half a page by default.

Vim basis

What I want to introduce here is the foundation of Vim foundation, but beginners without Vim foundation can also go to B site to search for Vim related tutorials to consolidate (I may record videos later).

As shown above:

  • In Vim, the default mode is Normal. In this case, tapping letters is typing commands, not editing text. The inputiEnter insert mode, which makes the tap letter the input letter
  • In INSERT mode, exit keyEscapeGo back to Normal mode
  • In normal mode,hjkl, respectively,On the lower left to the right

Above:

  • In normal mode,Shift + a(Hereafter, this is written asA) moves to the end of the line and changes to INSERT mode;IIs before
  • In normal mode,oYes Insert a row and jump

Above:

  • In normal mode,wIt’s moving a word forward,bMove a word backwards

Above:

  • In normal mode,dIs on clipping mode, so,dwCut out a word;ddCut a row
  • In normal mode,yIt’s copy, andpIs the paste

Above:

  • In normal mode,sDelete the current cursor point and switch to INSERT mode.xDelete and do not convert

Above:

  • In normal mode,15ggIs to jump to15line

Above:

  • In normal mode, the Visual mode is enabled

Vim composition logic is commonly used in VS Code

Vim enthusiasts often say that Vim is logic, not memorizing keyboard shortcuts (I’m not a Vim fan yet, but some of my friends in the Linux community say this).

My understanding of Vim’s “logic” is roughly as follows:

  • Case is the opposite logic
  • VS Code some Ctrl and scroll
  • i(meansIn parentheses

The explanation is as follows.

Case is the opposite logic

int foo_xyz = 1;
       ^
Copy the code

We know that if we want to delete _xyz when the cursor is at _, we need to first find the nearest z and then delete everything within that range. In vim, type DFZ for expression, and fz means find Z.

So, what is looking forward? The answer is a capital F, as shown above.

As above, it is easy to insert a row down with O, whereas an up row is inserted with O.

VS Code some Ctrl and scroll

As above, using Shift + [] jumps lines in “code blocks”.

As above, Ctrl + [] adjusts the indentation. This is combined with visual mode.

As above, [[jumps to the top line of the file, while]] is the bottom line.

As above, H is to the top of the screen, L is to the bottom of the screen, and M is to the center of the screen; Zz means “place the cursor in the center of the screen without moving the cursor (scroll the screen),” zt means place the cursor at the top, and zb means at the bottom.

I (means in parentheses

print(f"what {s}?")
Copy the code

As above, when we want to empty the parentheses of the print() function, we tell Vim “logically”. Move the cursor inside the brackets and type ci(or ci), where I (is “in brackets”.

As above, not only c operations, not only (), but also “”, [], etc.

In addition, there is a lot of logic that can be combined, for example: j is jump down one line, so 10j is jump down 10 lines. Also, the/find feature works in VS Code as well. However, I prefer vs Code’s CTRL + F search. What else can vs Code do with its own key combination? We’ll do that next time.

About vim, there must be other wonderful use, welcome to leave a message your common efficient operation ~