vi Command: Tutorial & Examples

Edit text files with the vi editor

Vi (short for "vi editor") is a text editor for Linux and other Unix-based operating systems. It is a command-line based editor, meaning that it is operated entirely through the terminal and does not have a graphical user interface.

Vi has two main modes: command mode and insert mode. In command mode, the user can navigate the document and perform various editing commands, such as deleting text or copying and pasting. In insert mode, the user can enter and edit text.

Some basic commands in command mode include:

  • h, j, k, l: move the cursor left, down, up, or right
  • i: enter insert mode
  • x: delete the character under the cursor
  • dd: delete the current line
  • :q: exit the editor (:q! to exit without saving changes)

Vi is a powerful and flexible text editor, but it has a steep learning curve and can take some time to master. There are other text editors available for Linux such as nano, vim, emacs, so the most important thing for you to remember might be how to exit vi: :q!