This is the 14th day of my participation in Gwen Challenge

1. File opening and closing

  1. Open the file
    • Vim: Open a file
    • Vim +number: Opens a file and locates the number line
    // Place the cursor on the second line of the file vi +2 profile.logCopy the code
    • Vim +: Open the file and navigate to the last line
    • Vim +/pattern: Pattern is a character that positions the cursor where that character first appears
    // Open the profile.log file and position the cursor on the line where after first appears vim +/after profile.logCopy the code
  2. Close the file
End mode: :q exit not touched file :wq save and exit moved, do not regret :q! Do not save and exit moved, regret :w Save :w! Save :wq --> :xshift+Z+Z: Save and exit without colon, edit modeCopy the code

Two, three modes

  1. Edit mode: the key is no longer its own function, each key has a specific function, such as I is to open the input mode
  2. Input mode: meaning of key itself
  3. Last line mode: accepts user command input
  4. Edit –> Enter:
    • I: Enters the input mode before the character where the cursor is.
    • A: Enter the input mode after the character where the cursor is.
    • O: Create a new line below the current cursor and enter the input mode.
    • O: Create a line above the current cursor and enter the input mode.
    • I: At the beginning of the line where the cursor is, the input mode is changed
    • A: Switch to input mode at the end of the current cursor line
  5. Enter –> Edit:
    • esc
  6. Edit –> Last line:
    • :
  7. Last line –> Edit:
    • ESC, ESC

Edit mode

  1. Move the cursor
    1. character
      • H: left
      • J: the
      • K:
      • L: right
    2. The word
      • W: Move to the beginning of the next word
      • E: Move to the end of the current or next word
      • B: Jump to the beginning of the current or previous word
    3. inline
      • 0: jumps to the head of the absolute line
      • ^ : First non-whitespace character at the beginning of a line
      • $: Absolute end of line
    4. row
      • G: The end of the article
      • Gg: The beginning of the article
      • 3G: the third row
    5. Turn over the screen
      • CTRL + f: down
      • CTRL + b: upward
  2. Delete & Replace
    • X: Deletes the cursor position character
    • 3x: Deletes the first three characters of the cursor
    • R: the character to replace the cursor position
    • Dd: Deletes an entire line
    • Dw: Deletes the word where the cursor is
    • D $: Deletes the content after the cursor
  3. Copy and paste & cut
    • Yy: Copy an entire line of content
    • Yw: Copy a word
    • P (lowercase) : Pastes the copied or cut content below the current line
    • P (uppercase) : copy above the current line
    • shearFirst:ddordwDelete and use againyyorywcopying
  4. undo
    • U: removed
    • CTRL + R: Undo the undo operation
    • : Repeat the command in the previous step

Fourth, last line mode

  1. Set up the
    • Set nu: Displays the line number
    • Set nonu: does not display the line number
    • Set only: This edit is set to read-only (cannot change the text content)
  2. To find the
    • /patternWhere is the cursor located
      • n: Turn the page down
      • N: Turn the page up
  3. Execute the command
    • :! Ls /usr: Enter the colon and exclamation mark, run the following command, and press Enter to return to the VIm file screen
    • For example, if you forget the address of a directory, you can view it directly without exiting Vim
    // Display the contents of usr directory :! ls /usrCopy the code
  4. Find and replace
    • Range S/STR1 /str2/ parameters
      • parameter
        • g: Replace all the words in a line (only the first word would have been replaced)
        • i: Ignore case
      • The scope of
        • n: the line Numbers
        • .: Indicates the current cursor position
        • +n: Offset n lines
        • $: at the end of the line
        • %Full text:
    #1 Replace after with before, case insensitive, entire line:).$s/after/before/gi
    
    #2 Full text replacement
    :%s/after/before/gi
    
    #3 row 1 to row 2
    :1,.s/after/before
    Copy the code
  5. Mixed operation
    • A comma is just a separator and has no other meaning
#1. Delete current line to last line:).$d

#2. Delete the first line to the penultimate line
:2,$-2d

#3. Copy lines 3 through 6:3,6y (copy) p (paste)Copy the code