Forgot your password?
typodupeerror
User Journal

Journal: vi Reference

Journal by PDF

vi is a simple screen-oriented text editor from UNIX. Many clones of vi exist throughout the software world. It is difficult to learn how to use vi because it behaves differently from most other text editors. However, once you learn how to use vi, it is an extremely efficient text editor, and so you'll have vi x.txt ingrained in your frequently-used-commands muscle memory.

Here is how I typically use vi:

  • To create a new file or read an existing file, vi x.txt, where x.txt is the filename to edit.
  • vi starts out in command mode. With an existing file, use the arrow keys, Page Up/Page Down, HJKL, or ^f ^b ^d ^u to navigate. Or use the old ex commands -- for example, :123 where 123 is the line number to jump to. Search for strings using / and then a regex. Press enter to find next occurrence.
  • To start typing text, pressing i or Insert switches to insert mode. Type away and press Esc when done to switch back to command mode. Backspace works unless terminal settings are haywire. Backspace at the beginning of a line probably doesn't do anything... it's the vi way. Delete may not work properly, if at all. You may need to experiment with it. Otherwise, switch to command mode and press x to do a forward delete.
  • To yank out an entire line, press dd.
  • Cut and paste with mouse. Or, see how to do it properly and also more good esoteric vi commands with this vi cheat sheet.
  • To quit: :q! to save without changes, otherwise most vi implementations support ZZ to keep changes. Fallback: :wq or :w. If you back up everything all the time, :q! is merely a convenience.

FORTUNE'S FUN FACTS TO KNOW AND TELL: #44 Zebras are colored with dark stripes on a light background.

Working...