Exercises
·Unix Introduction
·BLAST
·PERL
·Genbank
·BLAST, GCG
·GCG
·Seqlab
·Synthesis
·MSA
·Paup
·Phylogeny
·Examine


·An editor primer
·A GCG cheatsheet
·Flat2fasta homework
·Dynamic Programming homework
·High scoring words homework
·GCG homework
·Seqlab homework
·Mystery sequence homework
·Paup homework
Prerequisites
Prerequisites:
  • Some familiarity with Unix
Introduction

This is a short tutorial designed to give a quick grounding in the use of a text based editor. This will be split into two sections:
Emacs and Vi. This tutorial assumes the user is working within the confines of a terminal.

Emacs

Emacs is perhaps the most customizable text composer in existence. Customizing emacs is beyond the scope of this discussion, but a quick Google search will return a lot of information. Below is the emacs starting screen.

As it says, the starting screen is essentially scratch paper, not intended for saving. In fact, I use the scratch screen as a general purpose calculator. (Furthermore, this series of documents was written in emacs, so there actually are people who use this esoteric stuff for simple tasks.)

Emacs does not make use of the computer's windowing system. As a result one does not have immediate use of the mouse cursor to help perform tasks. Thus one _must_ spend a few moments to memorize the key combinations required to complete tasks like saving a file, quitting, opening a new file, etc. There are a couple of guidelines when attempting to remember these commands:

  • Most (all?) file related commands start with Control-x (C-x-)
  • Using Meta-x (Which may be the alt key and x _or_ the escape key followed by x) provides a way to find other commands.
  • Control-h starts the help system
  • Control-h followed by k allows one to type a key combination and find out what it does.
  • Copying and pasting works differently.

If you wish to use emacs, spend a moment memorizing these:
  • C-x C-s (Control x followed by Control s): Save the current file.
  • C-x C-w: Write the current file with a new filename. (Save As)
  • C-x C-c: Cancel emacs. (quit)
  • C-x C-f: Find a file. (Used to both open an existing file and a new file.)
  • C-g: Cancel the current operation. (general purpose 'oh crap').
  • C-a: Jump to the beginning of line.
  • C-e: Jump to the end of line.
  • Tab: Either indent the current line _or_ complete typing a command or filename for you (like in the bash or tcsh shells).
  • C-x b: switch Buffer. (change the currently visible window)
  • C-s: Search forward for a string.

When I myself decided to learn emacs, I spent an hour typing Meta-x followed by a character or two, followed by tab tab. When I typed the tab key multiple times, emacs shows a list of commands which start with those keys. Thus, when I wanted to learn how to save a file I did this:
Meta-x 's' 'a' 'v' 'tab' 'tab'
and was treated with the following. (I then typed C-h f followed by 'save-buffer' to learn about that command.

An interesting thing to note about the latter screenshot. The 'help buffer' takes up the bottom half of the screen and will not go away until the user makes it go away. Thus the following commands are good to know:

  • C-x o: Switch to Other panel.
  • C-x k: Kill the current panel.
  • C-x 1: Switch from multiple panels to 1 panel.
  • C-x 2: Split the current panel into 2 panels.
As a matter of fact, I spend 95% of my time using emacs with 2 panels open.

Exercises

Vi

Vi is one of the oldest Unix based text editors. When it was first written, it was considered a revolution in terms of the information presented to the user. Previous editors provided a means for the user to access individual addresses in a text document, but not necessarily the means to view them all at the same time. Vi was one of the first editors to make this jump in usability. However, there is one important distinction between vi and other text editors: it is 'modal;' which means that you are either in a command mode, or an editing mode. The distinction between the two main vi modes may not be immediately clear. Below is the initial screen presented to the user by vim:

As the above screenshots hopefully made clear, the escape key is integral to one's use of vi. It is the key to switching between command and insertion mode in a document. Here is a snippet from the vim tutorial: "One of the problems for Vim novices is mode confusion, which is caused by forgetting which mode you are in or by accidentally typing a command that switches modes. To get back to Normal mode, no matter what mode you are in, press the key. Sometimes you have to press it twice. If Vim beeps back at you, you already are in Normal mode."

If you wish to use vi, spend a moment memorizing the following (and try them out right now on a file on your computer!):

  • Esc c w (escape followed by c then w) == Replace the Current Word.
  • Esc : w ! (escape followed by :, w, then !) == Write ! the current file (no matter the consequences)
  • Esc : q ! (escape, then :, then q, then !) == Quit! no matter the consequences
  • Esc : r filename == Read the provided filename and insert its contents into the current file.
  • Esc 5 d == Delete 5 lines. Compare to Esc-d-d which deletes only 1 line at a time. Furthermore, compare to Esc-d-} which deletes everything from the current point until the next paragraph or Esc-d-{ which in turn deletes until the prior paragraph. Esc-d-w will delete a word, too.
  • Esc x == Delete a single character. C-x C-s (Control x followed by Control s): Save the current file.
  • Esc . (Escape followed by a dot) == Perform the last action again.
  • Esc :$,s/U/u/ == This one is more difficult. Let us just say that this provides an easy method to search and replace text matching a pattern anywhere in a document. (In the case of the above example it will change all occurrences of 'U' with 'u')
  • Esc p == Paste the most recently deleted text right
      before
    the current pointer.
Links
Practice

Here is the text of the vim tutorial.
Here is the text of the emacs tutorial.
Download both tutorials. Perform the actions they ask of you in the editor of your choice. In your first iteration, use the tutorial to discover functionality in the editor while the second iteration is an opportunity to try the actions without receiving the (correct) instructions.


Created: Wed Sep 15 00:58:22 EDT 2004 by Charles F. Delwiche
Last modified: Tue Apr 19 15:41:55 EDT 2005 by Ashton Trey Belew.