1. Vim is introduced

    1. Vi and Vim are not installed in the same package

      1. rpm -qf vim

      2. rpm -qf    vi

    2. Vim is a syntax-enhanced version of VI, fully compatible with VI

  2. Vim editor operation mode

    1. Vim uses four modes

      1. Normal (Nomsl mode, commonly known as command mode)

      2. Command line mode

      3. Insert mode

      4. Visual mode (Visual block mode)

    2. Vim/directory/file

      The file ———— is in normal mode for the first time

      Press I to appear Insert———— Insert mode

      Press Esc and enter the colon ———— command line mode

    3. Enter the edit mode

      1. Press a I o and then a I O

      2. Edit mode operation

        I insert before the current character

        Insert line I at the beginning

        A Insert after the current cursor

        Insert the end of line A

        O Downlink insertion

        O Uplink Insertion

        X deletes one character backwards

        X deletes one character forward

        U to cancel

        CTRL + R restores

        R replace

        Edit mode to command mode by pressing ESC

    4. Normal mode operation

      1. Cursor position h j K L

      2. The 0 and home keys switch to the beginning of the line

      3. $and end indicate switching to the end of the line

      4. Gg Quickly locate to the beginning of the line

      5. G is positioned at the end of the line

      Use /in to find in and right highlight it

      Turn off highlighting: NOh

      /^ d Finds content starting with d

      /bash$Finds the end of bash

      Vim +7 /etc/passwd open the file and skip to line 7

    5. Text editing in normal mode

      1. Yy replicates the whole row and N rows Nyy

      2. Dd deletes row 2dd deletes row 2

      3. P paste

      4. X Deletes the character of the cursor position

      5. D Deletes the character after the cursor

      6. U to cancel

      7. CTRL + R restores

      8. R replace

    6. Enter visual block mode

      1. Visual mode is used for multi-line comments when programming or modifying server configurations

      2. Bulk changes

        1. CTRL +V to enter column editing mode

        2. Select up or down the cursor

        3. Press capital I

        4. Insert comment symbol or needed symbol (#)

        5. Add after pressing ESC to comment it all out

    7. Command line mode operation

      Save: w

      : W! Mandatory saving

      : q exit

      : q! Exit without saving

      : wq Save the changes and exit

      : wq! Forced save exit

      : x Save and exit

      ZZ Save and exit (in normal mode)

      : e! recovery

    8. Customize viM usage environment

      1. Temporarily set

        1. : set nu Sets the line number

        2. : set nonu Unsets the line number

        3. : noh Unhighlights

      2. A permanent set

        1. Vim /etc/vimrc Setting affects all users in the system

        2. ~ /. Vimrc Creates a vimrc file in the user home directory

          Echo ‘set nu’ > ~/. Vimrc

          vim /root/.vimrc

    9. Open multiple files at once

      CTRL + WW toggle between documents

      1. Open up and down

        1. vim -o /etc/passwd /etc/hosts
      2. Left and right open

        1. vim -O /etc/passwd /etc/hosts
      3. View the content differences of multiple files

        1. vimdiff /etc/passwd mima.txt
    10. Other editors for Linux

    1. Nano editor 2. Emacs editor 3Copy the code