mavrinac.com :: vi for notepad gurus



vi for Notepad Gurus

Although Microsoft Notepad is clearly the superior text editor among its peers, occasionally we're forced to use a lesser editor like vi because we're stuck on one of those crusty old UNIX machines. Here's how to cope with the lack of features in vi and get it to work like your trusty Notepad.

The Basics

The vi editor has some pretty strange ideas about how to edit a file. You can't just go on ahead and type. You need to move the cursor around with the arrow keys (or H, J, K and L on even older and crustier UNIX machines), and then hit i or a to insert or append text. You can also hit I or A, which inserts at the beginning or appends to the end of a line (how confusing is that? sheesh). Then, when you're done entering text, you have to hit ESC to go back to the normal mode.

Deleting characters is no picnic either. You can delete characters you've just typed using backspace if you're still in insert mode, but if you already hit ESC, tough luck. You have to use x on each character now. You can also delete the rest of the line using D.

You can just hit Enter to go to the next line, but if you're not already in insert mode, you can hit O or o to insert or append a line and start typing on it. If you want to delete a newline (i.e., join the next line to the end of the current line), you have to type J on the current line.

Remember: if in doubt, hit ESC. If that doesn't work, and vi has made a mess of your file because it wouldn't listen to your correct commands, hit :q! and everything will go back to the way it was.

The File Menu

  • New: Type vi at the shell.
  • Open: Type vi <filename> at the shell.
  • Save: Type :w.
  • Save As: Type :w <filename>.
  • Page Setup: Type man troff at the shell. ;)
  • Print: Type lpr <filename> at the shell.
  • Exit: Type :wq to save and exit, or :q! to exit without saving.

The Edit Menu

  • Undo: Type u.
  • Cut: To cut a line, type dd on the line. To cut multiple lines, type <lines>dd.
  • Copy: To copy a line, type yy on the line. To copy multiple lines, type <lines>yy.
  • Paste: To paste after the cursor (whatever was copied or cut as above), type p.
  • Delete: To delete a character, type x on the character. To delete a line or lines, cut them as above.
  • Find: Type /<query>.
  • Find Next: Type /.
  • Replace: To replace on the current line, type :s/<old>/<new>/g. Any regular expression can be used for <old>.
  • Go To: Type :<line>.
  • Select All: Type :0 and put a very large number for 'lines' in Cut or Copy?
  • Time/Date: Type date >> <filename> at the shell.

The Format Menu

  • Word Wrap: Use :set wrap and :set nowrap.
  • Font: Set the terminal font?

The View Menu

  • Status Bar: There's already a 'status bar' on the bottom line of vi.

The Help Menu

  • Help Topics: Either type :help in vi, or man vi at the shell.
  • About Notepad: Well, about vi, anyhow. Type vi --version at the shell.

Some Other Goofy vi Features

The vi editor has some extraneous features no one uses that were intentionally left out of Notepad to make it more efficient (as if Microsoft needs to make its products even more efficient!), but I'll discuss a few here anyway just for kicks.

  • Type >> to indent the current line.
  • Type <lines>>> to indent multiple lines.
  • Type . to repeat the previous command.
  • Type r<char> on a character to replace it with a new character.
  • Type ~ on a character to change its case.
  • Type CTRL-W in insert mode to delete the last word typed.

There are plenty more where these came from. For a good chuckle, check out the vi Reference written by Maarten Litmaath and maintained by James Hu.

Last modified Wednesday, January 20, 2010 (20:07 UTC)

Post to Delicious Digg It Stumble It Post to Facebook



Recommended Book

Good Omens

Good Omens
by
Terry Pratchett
and
Neil Gaiman


Recommended Movie

The Adventures of Baron Munchausen

The Adventures of Baron Munchausen
1988


Recommended Album

Source

Source
by
Sync24