Detailed explanation of vi command in Linux system

The vi command is a commonly used text editor in the Linux system, which provides a wealth of functions and shortcut key operations. The following is a detailed explanation of the use of vi commands:

  1. open a file:

    • Enter the following command in Terminal to open the file:

      vi 文件名

      Replace "filename" with the actual file path.

  2. Mode switching:

    • Command mode: The default mode after opening vi, which is used to execute editor commands, such as saving files, exiting editing, etc.
    • Insert mode: used to enter and edit text content. Press the "i" key in command mode to enter insert mode.
    • Visual mode: used to select text blocks for copy, paste, delete and other operations. Press the "v" key in command mode to enter visual mode.
  3. Common commands:

    • Save the file and exit:

      • Type ":wq" in command mode and press Enter.
    • Exit without saving the file:

      • Enter ":q!" in command mode and press the Enter key.
    • Insert text:

      • Enter text in insert mode.
    • Delete characters:

      • Press the "x" key while in command mode.
    • Copy and paste:

      • Enter visual mode and select a block of text.
      • Press the "y" key to copy the selected text block.
      • Move the cursor to the target position.
      • Press the "p" key to paste the copied text.
    • Find text:

      • Press the "/" key in the command mode, enter the content you want to find, and press the Enter key.
      • Press the "n" key to continue looking for the next match.
  4. Shortcut key operation:

    • Shortcut keys in command mode:

      • "u": Undo the last operation.
      • "yy": Copy the current line.
      • "dd": delete the current line.
      • "p": Paste the text from the clipboard.
      • "G": Jump to the end of the file.
    • Shortcut keys in insert mode:

      • "Ctrl + c": exit insert mode and return to command mode.
  5. Other functions:

    • Undo and Redo: In command mode, enter "u" to undo the last operation, and enter "Ctrl + r" to redo the undone operation.
    • Line number display: Enter ":set nu" in command mode to display the line number, and enter ":set nonu" to hide the line number.

The above is a detailed explanation of some common operations and functions of the vi command. vi is a powerful text editor, mastering its basic operations and shortcut keys is very helpful for text editing in the Linux system.

Hope the above explanation can help you better understand and use vi commands. If you have other questions, please refer to the relevant documentation or seek support from the Linux community.

Guess you like

Origin blog.csdn.net/tiansyun/article/details/132287791