Rookie articles##Vim understanding and usage##

                                                  ########Three modes of vim##########

  1. Command mode

      The command mode is the mode that vim enters by default after opening the file. No characters can be inserted in this mode, but the working mode of vim can be set
      : set Specify information
      : set nu Add line mark
      : set nonu Cancel line mark
      : set cursorline Add line
     : set mouse=a add mouse

   ##Note: The working method of setting vim directly in vim is a temporary setting, that is to say, when vim is closed, the setting is invalid

                    If you want to set it permanently, you need to write "/etc/vimrc". Enter the set command in the last line, then exit and save, it can be used permanently

 1. How to manage characters in command mode

 Press "x" to delete the character under the cursor
 Press "u" undo to redo
 Press "ctrl+r" redo to undo and redo
 Press "y" to
    copy
    "yw" ##copy a word
    "yl" ##copy a letter
    "yy" ##copy A whole line
    "y5y" ##Copy 5 lines and
  press "c" to
    cut
    "cw" ##Cut a word
    "cl" ##Cut a letter
    "cc" ##Cut a whole line
    "c5c" ## Cut 5 lines
    Note: "When you use C to cut, you will enter insert mode, if you want to paste, you need to exit insert mode, press <ESC> and then press P"

  Press "d" to
    delete
    "dw" ##Delete a word
    "dl" ##Delete a letter
    "dd" ##Delete a whole line
    "d5d" ## delete 5 lines

  Press "p" to paste

  2. Visual operation of vim

   #1. The basic operation of the visual mode
    cannot be operated with the mouse to select the area in vim.
        If you want to operate a certain area, you need to enter the visual mode. In the command mode, "ctrl + v" can enter the visual mode.

Press "Up|Down|Left|Right" to move the cursor to the selection area, and press the corresponding operation key to operate the selection area

 

  #2. Batch add characters in visual mode

       1. Put the cursor on the first row of the column where the character you want to add is located
       2. Move the cursor to select the column where the added character is located
       3. "I" enters the insert mode
       4. Write the character to be inserted

       5. Press "ESC" to exit the insert mode, and the characters are added in batches successfully

  # 3. Vim character replacement

        %s/original characters/new characters/g #Full text replace
        1,5s/original characters/new characters/g #Replace characters from 1 to 5 lines

        g #Replace all the keywords that appear, if you don't add "g", only the first one that doesn't appear on the line will be replaced

# 4. Vim total character search and cursor movement

(1).Character search
       /keyword
       n ​​##downward matching keyword
       N ##upward matching key sub

  (2) Movement of the cursor

             :Number ##The cursor moves to the specified line quickly
             gg ##The cursor moves to the first line of the file
             G ##The cursor moves to the last line of the file
     # 5.vim edits multiple files at the same time
          : sp filename
          ctrl + w up#Cursor Enter the upper file window

          ctrl + w down #The cursor enters the file window below

2. Insert mode
"i" #Insert the character
"I" at the position of the cursor #Insert the character
"o" at the beginning of the line where the cursor is located #Insert the character "O" in the next line of the line
where the cursor is placed Line new line insert
"s" #delete the character where the cursor is and insert the character
"S" #delete the line where the cursor is and insert the character
"a" #the next character of the character where the cursor is, insert
"A" #insert the character at the end of the line where the cursor is
3. Exit mode
: q #When vim enters the file and does not do any operation on the file content, you can press "q" to exit
: q! #When vim enters the file, there is an operation on the file content but do not want to save and exit
: wq # Normal save and exit
: wq! #Forcibly save and exit, only valid for root users or file owners





     








 








       

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325406535&siteId=291194637