Vi text editor

How to work with the Vi console text editor.

Vi is a console text editor for Unix-like operating systems. It's available on VPS and dedicated servers.

Several versions exist: vi, elvis, vile, and vim. At least one of them is available on virtually every Unix and Linux system. Vi supports syntax highlighting, code formatting, powerful search and replace, macros, and more.

Vi Vi text editor

Modes

Unlike most conventional editors, Vi has a modal interface — the same keys perform different actions depending on the active mode.

Vi has two main modes:

  • Command mode — active by default. Keyboard keys execute navigation and editing commands.
  • Insert mode — the keyboard is used for typing text. Press i or a to enter insert mode, and Esc or Ctrl+C to return to command mode.

In command mode, simple commands can be combined for more complex operations. For example, 2dw deletes two words.

Common commands

Navigation:

  • h, j, k, l — move the cursor left, down, up, right
  • :33 — jump to line 33

Editing:

  • i — enter insert mode before the current character
  • a — enter insert mode after the current character
  • x — delete the character under the cursor
  • dd — cut the current line
  • yy — copy the current line
  • p — paste
  • J — join the current line with the next
  • u — undo the last action
  • . — repeat the last action

Search and replace:

  • /str — search forward for str (regular expressions supported)
  • ?str — search backward for str
  • n — repeat the search in the same direction
  • N — repeat the search in the opposite direction
  • :[range]s/old/new/[g] — replace old with new in the specified line range. The g flag replaces all occurrences in a line, not just the first. Example: :32,64s/old/new/g

File and exit:

  • :w — save the file
  • :wq — save and exit
  • :q — exit
  • :q! — exit without saving
  • :e! — reload the current file (discard all unsaved changes)
  • :r — insert the contents of another file into the document

To open the built-in manual, run:

man vi

Press q to exit the manual.

Help

If you have any questions or need assistance, please contact us through the ticket system — we're always here to help!

Need help?Our engineers will help you free of charge with any question in minutesContact us