preface

I’m not sure how much more efficient using keyboard code alone will be than using a keyboard and mouse, but the process will definitely make you feel better. Although the process is tiring and you need to memorize so many combinations of keys, you will thank yourself for your efforts once you are proficient.

This article concludes with Vscode + Vim + iTerm code, which other editors can search for themselves.

1. Use of Vim

Since it’s a pure keyboard, you need to use buttons instead of mouse movements and jumps.

1.1. Move shortcut keys

Here are some basic buttons:

  1. Up, down, left and right:k,j,h,l
  2. Up, down, left, right, we want to move fast?
    1. wMove quickly to the beginning of the next word (WAlso a quick word jump, but with a space separator)
    2. eMove quickly to the end of the word or the next word where the cursor is (EIt’s the same thing asW)
    3. bMove quickly to the prefix of the word or the word before it (BIt’s the same thing asW)
    4. The $moves quickly to the end of the line
    5. 0Quickly move to top of line (including space)
    6. ^A character that moves quickly to the beginning of a line without space
    7. F + Any characterQuickly jump to any character specified on the line (search forward)
    8. T + Any characterQuickly jump to the preceding character of any character specified on the line (forward search)
    9. F+ Any characterQuickly jump to any character specified on the line (search backwards)
    10. T+ Any characterQuickly jump to the previous character of any character specified on the line (search backwards)
    11. SpaceMove letter by letter
    12. Shift+*You can quickly scroll down to find the word that the cursor is focused on
    13. Shift+#You can quickly look up the word that the cursor is focused on
  3. Knowing fast movement on the line, now want fast movement inside the file?
    1. Ctrl+fQuickly turn to the next page (the word for f should be forward)
    2. Ctrl+bQuickly turn to the previous page (the word for B should be back)
    3. Ctrl+dScroll down half a page quickly
    4. Ctrl+uFlip up half a page quickly
    5. GGet to the end of the article quickly
    6. ggFast to the beginning of the article
    7. HQuickly to the first line of the screen (equivalent to the word Head)
    8. MFast to the Middle line of the screen (equivalent to the word Middle)
    9. LFast to the last line of the screen (equivalent to the word Low)
    10. EnterCursor down
  4. What about fast movement within files, but code movement within projects?
    1. Ctrl+]Quick jump to the definition
    2. Ctrl+oGo back to where I jumped before
  5. If I want to read the code, is there a better way?
    1. Ctrl+eYou can roll down row by row
    2. Ctrl+yYou can roll it up line by line
    3. ztYou can place the cursor directly on the first line (tShould betop)
    4. zzYou can place the cursor directly in the middle of the screen
    5. zbYou can set the cursor line directly to the end of the screen (bShould bebottom)
  6. What if I’m looking for a word? In Normal mode/At first, type in the word you’re looking for, then press Enter, vim will help you locate the word that matches, and thennandNisFind the next oneandFind the last oneThe meaning of.

1.2. Quick editing in Normal mode

  1. x/XYou can delete words backwards or forwards
  2. ddCut current row
  3. dwCut from the cursor to the beginning of the next word (including Spaces). This key combination combines the results of each key, so it’s easy to remember
  4. deCut from the cursor to the beginning of the next word (without Spaces)
  5. And so on,dThe clipping key can also be combined$,0,l,G,B,H,M,LSuch as button cooperation, no further details
  6. yyCopy the current row
  7. yanddAlso, can cooperate with various keys, such as want to copy the cursor after the 4 words, cany4lWill do.
  8. pPaste the clipboard thing on the line next to the cursor,PInstead, paste on the top line.
  9. JCombine the cursor row with the data on the next row
  10. Ctrl+rRestores the action that was undone in the previous step
  11. .Repeat the last edit you made
  12. rReplaces the character where the cursor is located
  13. RReplaces multiple characters starting at the cursor
  14. xpExchange words quickly

1.3. Edit Mode

  1. iEnter the edit mode at the cursor position
  2. aEnter edit mode with the character following the cursor position
  3. oEnter edit mode on the line following the cursor
  4. OEnter edit mode on the line above the cursor
  5. AEnter edit mode at the end of the line where the cursor is
  6. IEnter edit mode at the beginning of the line where the cursor is located
  7. cAfter you cut the line where the cursor is, you enter edit mode, leaving the cursor in the current line
  8. sCut the word that the cursor focuses on and enter edit mode
  9. ~Changes the case of the character at the cursor position
  10. guChange the character at the cursor position to lowercase
  11. GuUppercase the character at the cursor position

1.4 Virtual model

  1. withvCommand to enter the Characterwise visual Mode (Characterwise Visual Mode). Text selection is in characters.
  2. withVCommand to enter the Linewise visual mode. Text selection is in units of action.
  3. withCtrl-VEnter Blockwise Visual Mode. You can select text within a rectangle.
  4. visSelect a sentence
  5. vipSelect a paragraph

. More tie-ins can be combined freely

1.5. File preservation

In Normal mode, the operations for saving files are as follows:

  1. :w: Saves the edited file without exiting the Vim editor. This command writes the data in the memory buffer to the file specified when VIm is started.
  2. :w!: Forcibly write files, that is, forcibly overwrite original files. If the access permission of the original file does not allow writing to the file, for example, the original file is read-only, you can use this command to forcibly write to the file. However, this command usage applies only if the user is the owner of the file, and the superuser is exempt from this restriction.
  3. :wq: Save the file and exit the Vim editor.
  4. :wq!: Forcibly save the file content and exit the vim editor
  5. ZZ: When using ZZ, if the file has been edited, write the data in the memory buffer to the file specified when vim is started, and then exit the vim editor. Otherwise you just quit Vim. Note that the ZZ command does not need to be preceded by a colon “:” or press Enter.
  6. :q: You can use this command when you want to exit vim without any editing
  7. :q!: Forces the vim editor to exit, abandoning the editing process

1.6. Advanced Operations

1. Quickly select the word where the cursor is and copy (cut)

Viwy => Enter the virtual line mode, select the word, and then copy the word

* In virtual row mode, 'a' and 'I' are no longer append and insert as we thought before. Let's start with the concept of 'text-object', which can refer to a word, a whole sentence of Text, a pair of Text in parentheses, or even Text inside an HTML or XML tag. 'A' will select an object including whitespace, while 'I' will select only the interior of the object without whitespace. *Copy the code

2. Quickly replace multiple identical words

In addition to using %s, there is another quick way to do this: Search for the word you want to replace in Normal Mode first: /+ Select the word you want to replace and press Enter to place the cursor under your word. Then CGN is called Insert Mode, and the selected word that the cursor focuses on is deleted. You can edit the word to the new word, then Esc to return to Normal Mode and use. You can replace all the words selected in the previous search one by one. Ci (‘/”/(/[/{/<): ci(‘/”/(/[/{/<): ci(‘/”/(/[/{/<)): ci(‘/”/(/[/{/<)): ci(‘/”/(/[/{/<)): Di operation are similar, but not into edit mode 3. Yi (“/” / / / / {/ <) : yi operation is directly copied 4. Vi (‘ / / “(/ [/ {/ <) : vi operation is selected, the subsequent operations to see their input commands

**Note** ** We can see this rule: the 'CI /di/yi/vi' button can be combined with various position operation related keys (such as' W '/' e '/' B 'etc.), to achieve the purpose of rapid editing. So Vim is not completely random **Copy the code

4. Quick comments on lines of code

The cursor jumps to the line of code you want to comment, andCtrl+VEnter virtual block selection mode and select the lines of code you want to commentjOr whatever) and press againITo enter the column insertion state, type//After the pressEsc, you can see that the selected lines are commented out. In fact, this function is equivalent to VSCODE multi-cursor editing mode, a super useful operation

This operation can also be extended to multiple cursor operations anywhere on A line of code. The most common operation is probably the end of the line: 'Ctrl+V' => 'j' => '$' =>' A '=>' Esc 'Copy the code

5. Copy the text to the named buffer, which can be used directly.

Valid buffer names are 26 letters from a to Z. The operation commands are as follows: 1. “ayy: copy the current line to buffer A. 2. “a5YY: copy 5 lines to buffer A. 3.” AP: paste the contents of buffer A

You can use ':reg' to see what is stored in the register currently used by VIm * what if I want to copy it to the global buffer? Vim provides a register called '+' to store the system clipboard, so the operation command is: press 'V' to enter visual mode, select the text you want to copy, then press '+ Y' to copy the text to the system clipboard, you can use your text elsewhere in the system!Copy the code

6. Paste the deleted text

If you delete some text by mistake, you can restore the text of the last 9 operations. Because they are all stored in numbered buffers, the last deleted content is stored in buffer 1 and the penultimate deleted content in buffer 2... To resume the delete operation, type '", then specify the buffer number, and then use the drop command. For example: '2p' is the last to last paste deleted textCopy the code

7. Record actions

If an operation is repeatable, you can use vim’s advanced feature: recording. Use q + a to z in Normal mode (a to z to choose one letter to store your recording movement, similar to the above registers), then you can start your repeatable action, after operation all actions on the q, can stop the recording, and then use the @ + before you save the register letters before repeating the set.

2. Common shortcuts of Vscode

The following shortcuts are based on the Mac keyboard

2.1. Main command box

F1 or Command+Shift+P: Opens the Command panel. In the input box that opens, you can enter any command, for example:

Clicking Backspace takes you to Command+P mode

To enter Command+Shift+P mode, type > under Command+P

In the Command+P window you can also:

○ File name redirects to the corresponding file ○ '? 'Lists the currently available actions ○'! Display Errors or Warnings. Either 'Command+Shift+M' ○ ':' jump to the number of lines' or 'Command+G' : 'jump to ○' @ 'jump to symbol'. Alternatively, 'Command+Shift+O' can go directly to ○ '@' and jump to a symbol to find an attribute or function, or 'Command+Shift+O' and enter: ○ '#' to find a symbol by name, or 'Command+T'Copy the code

2.2. Common shortcut keys

2.2.1 Editor and terminal window management

Open multiple VS codes at the same time (view multiple projects)

  1. Command+Shift+NOpen a new window
  2. Command+Shift+WClose Windows open multiple editors simultaneously (view multiple files)
  3. Command+NThe new file
  4. Ctrl+TabSwitching between files
  5. Command+\Split a new editor (up to 3)
  6. Command+1,Command+2,Command+3Left, middle and right shortcuts for three editors
  7. Switching between editors:Shift + Command + [(])

2.2.2 Shortcut keys in the work area

  1. Workspace show and hide:Command + B
  2. Switching between workspace and edit area:Command + shift + E
  3. File selection for Workspace File Explorer:H/J/K/LRepresents folder collapse (If it is not a folder, it will jump to the folder where the file belongs so that the entire folder can be collapsed later), Focus on next file, focus on previous file, expand folder (If it is not a folder, the file will be opened in the edit area)
  4. After opening the file, it needs to be fixed in the open state:Command + K + Enter
  5. Open the Debug panel:Command + Shift + D
  6. Quick focus on VScode’s command box:Ctrl + Z.This command needs to be configured in the keyboard mapping area and can be searchedworkbench.action.terminal.focus“, and then set your own shortcut keys

2.2.3 Shortcut keys of terminal area

  1. Ctrl + ‘opens terminal
  2. Command + |Split the end area vertically
  3. Want to switch between terminal areas after terminal area segmentation:Command + Alt + arrow key
  4. Add multiple terminals: ‘Ctrl + Shift +’
  5. Switching between multiple terminals:Command + shift + JIs to focus on the next terminal,Ctrl + shift + KIs to focus on the last terminal,Both commands are configuredworkbench.action.terminal.focusNextandworkbench.action.terminal.focusPreviousTo configure the

3. Shortcut keys commonly used by iTerm terminals

  1. Create a new TabCommand + t
  2. Split a Tab verticallyCommand + d
  3. Split a Tab horizontallyCommand + shift + d
  4. Split-screen switching within the same TabCommand + [
  5. Switching between tabsThe Command + digital
  6. View clipboard historyCommand + shift + h
  7. Previous commandCtrl + p
  8. The command to searchCtrl + r
  9. Clear the current command lineCtrl + u
  10. Jump to the beginning of the lineCtrl + a
  11. Jump to the end of the lineCtrl + e
  12. Letter by letter forward or backwardCtrl + f/b
  13. Word level fast forward and backwardAlt + f/b
    1. The configuration result is as follows:
  14. Deletes the character of the current cursorCtrl + d
  15. Deletes the character before the cursorCtrl + h
  16. Delete the word before the cursorCtrl + w
  17. Delete to the end of the textCtrl + k
  18. Swap text at the cursorCtrl + t

The last

This summary of shortcuts will be updated at…. You can follow my blog, Dummy’s blog