Because it's a text-based operating system that has historically been used for software development and computation, Unix did not traditionally provide the kind of full-featured, "what you see is what you get" text editing that exists on personal computers, although now such editors are available. In fact, WYSIWYG text editors are of limited utility for programmers because they often introduce invisible markup characters into documents.
It's worth learning to use the plain-text editors that are provided for Unix. They have a fairly steep learning curve, but they are the right tools for the job if you're writing programs or looking at plain-text data. If you download sequence data from a web server and open and work with it in a plain-text editor, the file you write out should be readable by a sequence-analysis program. If you opened the same file and worked with it in a WYSIWYG editor, then wrote it out in the file format used by that editor, it would be unreadable by other programs.
The vi editor is a standard feature of most Unix systems. It's a full-screen editor; it allows you to see as many lines of the file that you are editing as will fit into the terminal screen or window in which you run it. The cursor can be moved through the file using keyed instructions, but it can't be moved with the mouse. The bottom line on the screen is called the status line. Error messages from vi appear in the status line.
In Section 5.6, we discuss the use of regular expressions for searching and replacement as a feature of the plain-text editor vi. The ability to use vi with the regular-expression language makes vi a powerful tool for file manipulation.
A few nice features have been added to vi in vim (vi improved). It's worth asking your system
administrator to install vim if it's not already on your system, if only for the multiple undo feature that it introduces. We can't cover all the features of vim here, but we will present a few commands that will get you up and running.[3]
[3]
See the Bibliography for pointers to complete references on vi.
vim has three modes ; in each, input from the keyboard is interpreted differently: Command
This is the main mode; you are automatically in command mode when you start working. Keystrokes are interpreted as vim's short commands, most of which consist of one or two letters. You can always return to the command mode by hitting the Escape key once (or sometimes twice).
Input
This mode is reached by issuing any command that requires input. Status line
This mode is for issuing longer, more complex commands. To reach status line mode, simply type a semicolon (;) in command mode. A semicolon appears at the left side of the status line, and anything you type appears in the status line. When you finish typing your command and hit the Enter key, the command is executed, and you return to command mode.
Here are some of the most useful vim command-mode commands: h, j, k, l
Moves the cursor around in your file character-by-character or line-by-line. It's sort of like a pre-joystick video game: "h" moves you to the left, "l" to the right, "j" moves you down a line, and "k" up a line. On most systems, the arrow keys on your keyboard will also work to move you around within vim.
w, b
Moves the cursor forward ("w") or back ("b") by one word in the text. Words are delimited by whitespace.
), (
Moves the cursor forward ")" or back "(" by one sentence in the text. Sentences are recognized as sequences of words terminated by an end -of-sentence character (. ? !).
a, A, i, I, o, O
Initiates the insertion of text. "a" and "A" insert text after the cursor and at the end of the current line, respectively. "i" and "I" insert text before the cursor and at the beginning of the current line. "o" and "O" open a blank line below or above the current line, respectively, and begin inserting text on the new line.
x, X
Deletes the text under the cursor or before the cursor, respectively. Preceded by an integer number, they delete that number of characters after or preceding the cursor.
Substitutes for the character under the cursor or for the current line, respectively, by deleting the character either under the cursor or the line and initiating insertion of text in place of the deleted character. Preceded by an integer number, "s" replaces that number of characters with the new text, and "S" replaces the specified number of lines.
Here are some of the most useful vim status line mode commands: :wq
Saves changes to the file and quits the editing session. ":w" can be used by itself or with the name of the file to write to. ":q!" exits the session without saving changes.
r]
Followed by a filename, inserts the entire text of the named file. :g/pattern/s//replacement/g
Searches for and replaces pattern with replacement throughout the buffer. If the trailing "g" is left off, only the first occurrence of the pattern in any line is replaced.
:number
Moves the cursor to the specified line number.