First, about vi
The program called by the command vi on Linux systems is actually vim, or “vi improved.”
On other Unix systems, for instance an AIX system, you may be using either vi or vim (and won’t be able to tell).
To find out about vi/vim, on the command line type:
Type :q to exit.
At the command line, type:
This gives you a nice tutorial you can review if you’re interested in using vi frequently.
The basics of working in vi
To open vi, just type:
If you want to edit an existing document, type:
You start in Command Mode. You can’t edit in this mode, just do things like save and quit. To get into Insert Mode, where you can edit text, issue the single-letter command:
Now you’re typing. Basic navigation is easiest with the arrows on your keyboard. Move around, type and delete just like you always would. But sooner or later you’ll have to leave Insert Mode. To do this, press the
key. You’re back in Command Mode.
Need help? Type:
To simply leave, type:
That’s a colon and the letter “q”. If you’ve changed text, vi will complain that you haven’t saved. To quit without saving:
The exclamation point forces the issue. Or you can choose to write your changes (i.e. save them):
If you opened vi without specifying a file name, you’ll need to supply a file name to save:
if you’re writing and quitting.
The SourceForge Beginner’s Guide to Vim: an excelent, extensive introduction with lots of examples
A basic vi reference sheet:
The Vi Cheat Sheet at http://www.lagmonster.org/docs/vi.html
For advanced reference details:
See the Advanced Vi Cheat Sheet at http://www.lagmonster.org/docs/vi2.html.
And for really detailed information:
Jerry Peek’s The Joy of Vim series:
Part One, at http://www.linux-mag.com/id/2996/ has particularly good info on vim’s help system, and windowing and tabs in vim
Part Two, at http://www.linux-mag.com/id/2991/
Part Three, at http://www.linux-mag.com/id/3028/
Version 7 of Vim offers many new features:
See William Nagel’s “Vimming to New Heights” at
If you find vi frustrating or just plain silly, you can use another text editor on UNM systems. (It’s not included in every Linux distribution, for instance the Fedora we’re using in this class.)
pico, unlike vi, allows you to begin typing immediately. You’ll see a menu along the bottom of the terminal, which makes life much nicer.
What’s the command to save a file?
What’s the command to leave pico?
Other terminal-based editors you may find on your system are mcedit (the Midnight Commander Editor) and nedit. Try:
If you have mcedit, you’ll see a screen with function-key operations listed across the bottom of the screen.
will give you a menu-based editor.
gedit, kedit, nedit
If you have a graphical environment available, the next step up in text editors is XWindows-based text editors like gedit, kedit, or nedit.
All of these are clean, simple editors along the line of Microsoft WordPad. You’ll find the menus and command buttons very familiar.
Best of all, gedit is easy to invoke from a command prompt:
In the Unix world, emacs is the grand old text editor. Some people have accused emacs fanatics of trying to create a complete operating system from their word processor.
emacs operates in modes: text mode, Perl mode, C mode, and so forth.
You can open emacs with the simple command:
From here on, nothing is simple. emacs requires that you, the user, know a number of keyboard functions.
|Some Common emacs Keyboard Functions|
|Ctl-a||Clear your terminal’s screen|
|Ctl-e||Reset your terminal to default settings|
|Ctl-h||Display a user’s information|
|Ctl-d||List all currently logged-in user|
|Ctl-k||List current users and their tasks|
|Esc-d||Show your own current logged-in name|
|Ctl-x + Ctl-c||Lists your UID and GIDs|
|Ctl-x + Ctl-s||Display today’s date|
|Ctl-x + Ctl-w||Display this month’s calendar|
|Ctl-x + u||Leave a sub-shell|
Your system may have xemacs installed. On a Red Hat-based system, you can check by commanding:
rpm -q xemacs
This is an XWindows-based version of emacs that can give you some “training wheels.”
Finally, Arachnophilia and other Unix-compatible editors
There’s one very important point to keep in mind:
Line endings in Unix are different from line endings in Windows.
Thus it’s very important which text editor you use in Windows when you’re scripting for Unix.
On the home page for this class you’ll find a link to the Arachnophilia download page. The current version is written in Java. I personally like an older version, written in Visual Basic.
Download either or both and try them out. Find the menu item that deals with line endings!
And remember, Arachnophilia ain’t the only game in town for crossing the Unix/Windows border….
Converting Windows Files
If you find you’ve uploaded (or been sent) a Windows-based text file, you always have a quick fix:
dos2unix file1 file2 …
Be sure to check out man dos2unix for some interesting options.
Unix Manuals: vi Reference: http://www.unix-manuals.com/refs/vi-ref/vi-ref.htm