VIM (Vi) Editor

The vi editor: This is an old-fashioned text-file editor in the Unix world. It uses the full screen (or full window), but it does not use a mouse. It is useful because it should always be available and should always work. vi is enormously complicated -- whole books cover just this editor. (Your second text, A Practical Guide to Linux, by Sobell has his Chapter 8 on Linux: 44 pages.) It is notoriously confusing for beginners, but you can get by very well with just the 18 commands given in the next section. These 18 commands are all that you will be responsible for knowing on exams. For common editing tasks, a mouse-based editor is often more appropriate. Very intricate editing might better be done with a shell script or with a language like Perl. Unix commands below are in bold green.
Here is a copy of my .vimrc file.

Other examples:
Bash Snippets:
To know where to put _vimrc file for windows run these various commands: To use ctrl+v and ctrl+c use following in _vimrc: Helpful VIM Routines
Vi basics:
Basics of vi that you must know
To enter the vi editor, type vi on the command line followed by a file name to create or open:

    % vi file.c

Produces a clear screen if it's a new file, with ~ running down the left side.

You can get by with a very short list of commands (18 of them):

    i, I: -insert or insert at start of line, and enter input mode
    a, A: -append or append at end of line, and enter input mode
    Esc: -leave input mode, enter command mode
    x, dd: -delete a char, delete a line (in command mode only)
    h, l, j, k: -move left, right, up, down (in command mode only)
    ZZ: -save changes, exit vi (in command mode only)
    :w, :w filename: -write, write to "filename", no exit (in command mode)
    :q, :q!: -quit and don't save, quit and don't save even if changes (in command mode)
    /sometext: -search for "sometext" (in command mode)
    :23: -go to line 23 (in command mode)

If in doubt, press "Esc". Then type ":q!" (to exit vi without saving changes), and start over.

Remember, in input mode (after an i, I, a, or A command), all key strokes except Esc become a character in the file.

Carrying on: Below are useful commands to make editing more convenient. Try to relate these to the word processing techniques you use in the gui world with a mouse.

"Command mode"

cursor movements:

deleting (or cutting to the clipboard):

other basic commands:

any command can take numeric argument before the name of "object", i.e. formatting a file
gg=G - This reformatts the document according to its extension, i.e. this would reformat a .c properly or according to your settings

command line (sometimes called "ex mode"):

in ex mode "set" command can be executed to customize editing environment, i.e.:

in ex mode any ex command can be performed on the range of lines, i.e.:

Intermediate commands in ex mode:

file commands in ex mode:

"Input Mode" - editing your code...

Created By Dr. Neal Wager, Cathy Key and Mike Maltrud: The University of Texas at San Antonio