Ishida Tech Solutions, Ltd.
The personal and professional home of Brad Ishida

My Favorite vi Editor Tips - June 21, 2008

Nothing quite compares to the vi editor when performing fast edits of files on a Unix command line. Tip “#0″ would be to know your modes. Command mode (press ESC key) interprets your keystrokes as commands (for example, “j” moves down). Insert mode (press I key) lets you actually type stuff into your file. Line mode (press “:” key) lets you do cool stuff like search and replace. Here are my favorite tips.



  1. In Command mode, CTRL+g shows you current line information.
  2. In Command mode, forward slash “/search_term” searches down. Question mark “?search_term” searches up.
  3. In Command mode, “Number” followed by capital G takes you directly to the line number (23G takes you to line 23).
  4. Need to delete pesky ^M characters from a Windows text file? In Line mode you can do “:%s/^M//g” (to type the ^M you need to hold down CTRL and then press V then press M)
  5. Need to quickly comment out the next bunch of lines in a Perl script? In Line mode, this will comment out the next 5 lines starting with the current line. “:.,+5 s/^/# /g”
  6. Need to uncomment those same lines? “.,+5 s/^# //g”
  7. In Line mode “:set ic” will make searches case insensitive. “:set noic” will change them back to case sensitive.
  8. In Command mode, capital “G” takes you directly to the end of the file. “$” takes you to the end of the current line.
  9. In Line mode, use “c” with a search and replace to make vi ask you to confirm each replacement (example: “:%s/Breed/Bread/gc”).
  10. In Line mode, you can delete all empty lines with “:g/^$/ d”
  11. To search for characters such as the Microsoft Word curly quotes or any non-standard character that displays something like “\xe2\xe2\xe3″, you can use CTRL+x to type them (example: CTRL+x followed by “e” followed by “2″ will print “\xe2″)
Filed under: Learn by Doing — admin @ 11:50 pm

No Comments

No comments yet.

RSS feed for comments on this post.

Sorry, the comment form is closed at this time.

© Copyright 2008-2011 Brad Ishida