Copied to clipboard

vi

vi is a powerful text editor that can be used in the command line. Its features include file editing, searching and replacing, text formatting, etc.

Example

  • Open a file: vi filename
  • Save modifications: in command mode, enter :w or :wq
  • Quit without saving modifications: in command mode, enter :q!
  • Search for text: in command mode, enter /text, press Enter to jump to the first matching text, use n and N to jump to the next or previous match
  • Replace text: in command mode, enter :s/old/new/g, where old is the text to be replaced, new is the new text, g means global replacement
  • Copy and paste: in command mode, move the cursor to the text to be copied, enter yy to copy the current line, enter y+n+y to copy n lines, then move the cursor to the location to be pasted, enter p to paste
  • Undo operation: in command mode, enter u
  • Quit vi: in command mode, enter :q, if there are modifications, it will prompt to save, otherwise it will quit directly