Vim- “God like compiler”

The Vim compiler is known as the “god of the compiler”, because it allows you to program with both hands on the keyboard, rather than switching between the keyboard and mouse, which improves your development efficiency and makes your work more focused. Of course, the reason why you can keep your hands on the keyboard is that there are so many shortcut keys. At the beginning, we are all the same, and we think we can remember the shortcut keys too much, but after we use it skillfully, it really feels like flying. Here are the basic operations and shortcuts for the Vim compiler:

  1. Enter Vim editing mode:

    Type vim 1.txt on the console to create a 1.txt text. TXT file, which is in command line mode by default. Press the “I “key on the keyboard to enter the “Insert” editing mode, and the text will be inserted at the cursor position. Press the “A” key on the keyboard to enter the “Add” mode, and the cursor will hover at the end of the text.

  2. Switch command line mode and edit mode:

    By default, text is opened to enter the command line mode. If you want to enter the editing mode, press “I” or “A” on the keyboard, as described above and will not be described here. To return to the command line mode from editing mode, press ESC. To exit 1. TXT, enter :q in the command line mode. To save the edited text, enter :wq to save and exit.

  3. Terminal command line

    To view the contents of 1. TXT on the terminal console, enter cat 1. TXT. In this way, the contents of 1. TXT are printed to the terminal console.

  4. Vim copy, paste and delete

    Copy command: yy/yw

    Yy: copy a string.

    Yw: copy a string (stop copying if it encounters a space).

    Paste command: p

    P: Paste the copied string on a newline.

    Delete dd/dw

    Dd: deletes a string.

    Dw: deletes a string (stops when it encounters Spaces).

    Note: Copy, paste and delete commands are executed in command line mode, not in edit mode!

  5. Vim cursor move

    Bottom left, top right: H/J/K/L

    Skip to the file header: gg (the cursor stops before the first letter of the first word in the file)

    Skip to the end of the file: G (the cursor stops before the first letter of the last word in the file)

    Move to the top of the line: ^

    Move to the end of the line: $

    Move by word: forward W / 2W / 3W… Back b / 2 b / 3 b…

    Note: The Vim cursor movement command is executed in command line mode, not in edit mode!

  6. Vim find and replace

    Search keyword: / keyword (if there are multiple keywords in the whole text, for example: search for “UU”, there are three “UU” in the whole text, find the first keyword and want to quickly jump to the second keyword, the shortcut key is “N”, if you want to jump back to the last keyword, the shortcut key is “Shift + N”)

    Find and replace:

    Replace the keyword in the entire text: :%s/ keyword/replacement /gc (% : represents the entire text; S: stands for “search”. Keyword/replacement word: can be a string or regular expression; G: indicates that the search continues after the first keyword is found. C: User confirmation is required for each replacement.)

    Replace keywords in a range: :21,23s/ keyword/replacement /gc

    To display the line number: :set number, your VIM compiler will display the text line number

  7. Vim window more

    In writing C language code to refer to the interface defined in the header file, if it is a single window to write it will be very troublesome, so Vim to achieve multiple Windows to view at any time, improve efficiency.

    Split window: :split/vsplit (split :split the screen horizontally in half; Vsplit: cut the screen in half lengthwise)

    CTRL + WW/CTRL + W [HJKL] (CTRL + WW: Jump from the first window to the next window; CTRL + W [HJKL] : If there are more than two Windows, you can control the jump by HJKL.

    (Horizontal split screen) Zoom in on a window: CTRL + W Release CTRL + CTRL – (This combination makes the window where the cursor is at the maximum, leaving only one line of display area in the other window)

    (vertical split screen) amplify a window: shift + CTRL + w | (this combination keys will make the window of the cursor to the largest)

    Average window area: CTRL + W Release CTRL = (This combination will make all Windows the same size and split the screen equally)

    Close the window: :close (close the window where the cursor is)