How to use vim command in a Linux virtual machine?

You can use Vim commands in a Linux virtual machine by following these steps:

  1. Open the terminal or command line interface.
  2. Enter the vim command followed by the path and filename of the file you want to edit. For example, vim /path/to/file.txt.
  3. Press the Enter key to open the file and enter Vim editing mode.
  4. In Vim editing mode, you can use the following commonly used commands:
  5. i: Enter insert mode, you can insert text at the cursor position.
  6. Press Esc to exit insert mode and return to command mode.
  7. :w: Save the file without exiting Vim.
  8. :wq: Save the file and exit Vim.
  9. :q!: Abandon all modifications and force quit Vim.
  10. x: Delete the character at the current cursor position.
  11. dd: Delete the current line where the cursor is located.
  12. yy: Copy the current line at the cursor position.
  13. P: Paste the copied content below the cursor.
  14. Search for the keyword “keyword” in the document.
  15. :set nu: shows line numbers.
  16. :set nonu – Remove line numbers from display.
  17. After finishing editing, press the Esc key to return to command mode, then type :q to exit Vim.

These are just some common Vim commands; Vim has a wide range of functions and commands, so you can learn more commands as needed to enhance editing efficiency.

bannerAds