vim editing mode, vim command mode

vim edit mode

The interface entered by using vim filename is a general mode. Although we can view, copy, cut, and paste in this mode, we cannot edit new content. How can we write things directly? This requires entering the editing mode. There are many buttons to enter the editing mode from the general mode, but there are differences between different buttons to enter the editing mode.

  • i inserts before the current character of the cursor
  • I insert at the beginning of the line where the cursor is located
  • a is inserted after the current character
  • A inserts at the end of the line where the cursor is located
  • o Insert a new line after the current line
  • O inserts a line above the current line

vim command mode

The vim tool also has a command mode. Entering ":, /" in the general mode can enter the command mode. In the command mode, we can search for a certain string, or save, replace, exit, display the line number, high operations such as highlighting.

  • /word Find a string word after the cursor, press n to continue searching backwards
  • ? word Find a string word before the cursor, press the n key to continue the search
  • : n1,n2s/word1/word2/g Find word1 between lines n1 and n2 and replace it with word2, without g, only replace the first word1 in each line
  • : 1,$s/word1/word2/g Replace all word1 in the document with word2, without g, only the first word1 of each line will be replaced
  • When the content to be replaced or the content to be replaced contains "/", the system will not recognize the command. You can use "# or @" to replace the / in the grammar. For example, to replace wo/rd1 with wo/rd2, you can use: 1,$s#wo/rd1#wo/rd2#g

Additional Features of Command Mode

  • :w save text
  • :q quit vim
  • :w! Forces the text to be saved, when using the root user, the save can be done even if the text is read-only
  • :q! Force quit, all changes will not take effect
  • :wq save and exit (using this command will also update the file's Mtime if no text has been changed)
  • :x save and exit (using this command does not update the file's Mtime if no text has been changed)
  • :set nu display line number
  • :set nonu do not display line numbers

Guess you like

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