Text editors are specialized programs which allow you to create or edit a file by typing in the contents using the keyboard (and sometimes the mouse). Most text editors have many special features which allow text to be created more easily and quickly using functions such as copying, deleting, and moving blocks of text in the file. There are numerous text editors available on the lab machines--of which two of the most frequently used are described in the following sections.
The VIM text editor on the PCs is an improved version of the editor "vi", one of the standard text editors on UNIX systems. VIM has many of the features that you should expect a programmer's editor to have: Unlimited undo, syntax coloring, split windows, visual selection, a graphical user interface (with menus, mouse control, scrollbars, text selection, and the like), and much more. To edit a file using the GUI version of VIM, type:
gvim [file...]
VIM is a mode-oriented editor. Initially, when VIM starts, it is in command mode. In command mode, every key typed is interpreted as a command, such as a command to delete a character or to move the cursor.
From command mode, pressing i (or a, or another insert command) puts VIM into insert mode. In insert mode, each character typed is inserted into the file. Pressing the backspace key deletes the previous character. From insert mode, pressing the ESC key puts VIM back into command mode. It's also possible to use the cursor keys to move the cursor around in insert mode. If you do not know which mode VIM is in, simply press the ESC key to make sure VIM enters the command mode. To exit VIM (and save the current file), type :wq.
Following is a summary of the commands VIM accepts while in command mode.
Pressing one of the arrow keys moves the cursor one position in the direction of the arrow. Pressing the PgUp key moves backward in the file by a full screen; pressing the PgDn key moves forward in the file by a full screen.
| h | -- Move cursor LEFT |
| j | -- Move cursor DOWN |
| k | -- Move cursor UP |
| l | -- Move cursor RIGHT |
| b | -- Move cursor back one word |
| w | -- Move cursor forward one word |
| 0 | -- Move cursor to beginning of current line |
| $ | -- Move cursor to end of current line |
| Enter | -- Move cursor to beginning of next line |
| ^ | -- Move cursor to beginning of current line |
| H | -- Move cursor to top line of screen |
| M | -- Move cursor to middle line of screen |
| L | -- Move cursor to last line of screen |
| CTRL-d | -- Move down (forward) half a screen |
| CTRL-u | -- Move up (backward) half a screen |
| CTRL-f | -- Move forward a full screen |
| CTRL-b | -- Move backward a full screen |
| { | -- Move to previous paragraph |
| } | -- Move to next paragraph |
| 1G | -- Move to beginning of file |
| G | -- Move to end of file |
| xxG | -- Go to the xxth line of the file |
| i | -- Enter insert mode to insert text before cursor |
| I | -- Enter insert mode to insert text at beginning of line |
| a | -- Enter insert mode to append text after the cursor |
| A | -- Enter insert mode to append text at end of line |
| o | -- Open a line below the current line, and enter insert mode |
| O | -- Open a line above the current line, and enter insert mode |
| J | -- Join next line to current line |
| r | -- Replace one character with a single character |
| R | -- Replace string of text (overstrike) |
| x | -- Delete one character |
| dw | -- Delete one word forward |
| db | -- Delete one word backward |
| dd | -- Delete current line |
| 12dd | -- Delete 12 lines |
| D | -- Delete from cursor to end of line |