How to use vim command in a Linux virtual machine?
You can use Vim commands in a Linux virtual machine by following these steps:
- Open the terminal or command line interface.
- Enter the vim command followed by the path and filename of the file you want to edit. For example, vim /path/to/file.txt.
- Press the Enter key to open the file and enter Vim editing mode.
- In Vim editing mode, you can use the following commonly used commands:
- i: Enter insert mode, you can insert text at the cursor position.
- Press Esc to exit insert mode and return to command mode.
- :w: Save the file without exiting Vim.
- :wq: Save the file and exit Vim.
- :q!: Abandon all modifications and force quit Vim.
- x: Delete the character at the current cursor position.
- dd: Delete the current line where the cursor is located.
- yy: Copy the current line at the cursor position.
- P: Paste the copied content below the cursor.
- Search for the keyword “keyword” in the document.
- :set nu: shows line numbers.
- :set nonu – Remove line numbers from display.
- 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.