![]() |
Intro to Scientific Computing |
![]() |
The printed ASCII characters (those that get printed to your screen, as opposed to control keys like ^D or ESC, are:
!"#$%&'()*+,-./0123456789:;<=>?
@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_
`abcdefghijklmnopqrstuvwxyz{|}~
There are a few others for a TAB, New Line, and "Alarm" (tell the
computer to make a noise or flash).
When interacting with your computer, you will need to create text
files containing data, programs, scripts (short
programs that are not compiled), and LaTeX files. We'll
learn more about each of these later.
A Text editor is very different from a WYSIWYG editor
(
ASCII files will often be read by another program, such as a list of numbers to be plotted, or the source code (the text) to be compiled into an executable program file (like an .exe file). You might use your computer very professionally in a business office for many years without using a text editor, but for scientific computing and programming, we can't do much without a text editor.
If you are using a Windows computer, try Notepad now.
I myself, use The One True Editor: Emacs.
To get a sense of the features and comparisons of the most popular text editors, open the following link:
Impressive, eh? As you can see, there are many...
Another site (here) lists the editors by popularity.
The top three text editors are: Vim (a modern version of vi), Emacs, and jEdit
(note that Scribus is a page layout application).
Over the years, I've used all three and they are all good. Let's compare some features that we will need.
As I said earlier, an essential feature that we will need is that they can be used in text mode over a networked connection, such as an xterm window connected to a computer on the other side of the world. If you want to edit a file on that remote machine, you will want to use an efficient editor which has hi functionality using only text based commands.
Both Vim and Emacs are text based.
The alternative to this is using a GUI (Graphical User Interface) editor that has little icons for buttons and opens its own window(s)--something like MS Word. While these editors are very nice and have lots of features, they use a lot of computing power to update the windows, respond to the mouse clicks, highlight text, etc. Transmitting these features over the network can be quite demanding. Consider that anytime a character is written to the window, the entire window is usually refreshed. When the editor window is running on you own PC, you don't notice this. But when each update has to go across the country and back, you do.
jEdit is such an editor. It runs only in GUI mode. Another thing we want is that the editor has powerful features like syntax-color-coded text, modes for different types of files (C++, LaTeX, PHP, Perl, etc.). Fortunately, all three editors are very feature rich.
So in summary, I would summarize things this way.
| Editor | Powerful Features | Ease of Use | Text Based over Network | Editing Modes | Portabitily | Cost |
| Vim | Yes | Hard | Yes | Yes | Always on Unix, available for PCs and Macs | Free |
| Emacs | Yes | Moderate | Yes | Yes | Available for Unix, PCs, and Macs | Free |
| jEdit | Yes | Easy | No | Yes | Java based (all platforms) | Free |
Since vi is always available on unix machines (it's part of the system), it's good to learn at least the very basics of how to use vi. We won't be doing that in this course; I'll leave that to you, if you go on in scientific computing. (If you are interested in vi, ask Dr. Louise Stark in the School of Engineering and Computer Science--she's a vi expert!).
Note too, that there are also various "Notepad clones" under Linux and Solaris (i.e. the Sunrays) such as gedit which may be available on your Applications menu. If it doesn't say "gedit", it may say "Text Editor". These editors act just like Notepad. They do text editing, but have very few features.
As I said, I use Emacs as my text editor, partly
because I am old and have had too many years of practice with emacs to
switch. Another reason I am recommend it is that it's Free!
If you look at the comparison list of editors, above, you will notice that
many of them have a cost. I have tried to only use free software for this
course. In fact Emacs was one of the first applications developed by
The Free Software Foundation, the people behind
GNU software, which you may have heard of. Cygwin, Linux, and much of the Unix
world is built on the work of the FSF. Check them out!
So, let's fire up Emacs.
There are two ways to start emacs.
When running emacs over a network connection, or for a quick edit, use the terminal mode of emacs;
at the xterm prompt, type:
The -nw stands for "No Window".
You should see something like this:
There are four areas to the emacs screen:
File Edit Options Buffers Tools HelpIt's not used in terminal mode, but is still there.
This is where you edit your files. Each file that you are editing is called a buffer (it's really a part of memory, which becomes a file on your disk only when you write (or Save) the Buffer. You can have many buffers open at once, i.e. you can be editing many files in one emacs session.
----:---F1 *scratch* (Lisp Interaction)--L1--All-------------------------------------------------------This is a highlighted line of text that tells you information about the buffer you are currently editing. We'll learn more about what these phrases mean shortly.
Finally, there is a line of text below the Mode Line
For information about the GNU Project and its goals, type M-x describe-project.This is where emacs communiates with you. Emacs will put error or other messages here for you (such as the "For more informations..." phrase when emacs starts up). You also can enter commands here.
Jim Hetrick
Notice also that two
----:** -F1 *scratch* (Lisp Interaction)--L1--All-------------------------------------------------------
These two asterics signify that the buffer has been modified. In order to save these modifications,
you will need to save the buffer to a file.
The word
Emacs commands are entered by typing either:
Let's finish the example we have open.
So save this buffer to a file, we type the "save-buffer" command:
Type this:
This is equivalent the usual File->Save on most editors.
Using the Mini-Buffer, emacs asks you for the name of the file in which to save this buffer:
File to save in: ~/
I happen to have opened emacs in my Home directory, so emacs asks for the file name in ~/.
Emacs responds with
Once you have your address in the buffer,
You can see that emacs acts pretty much like Notepad. Aside from the text based commands like
C-x C-s, it's pretty intuitive (
Once your have your correct address back, save your changes
with "
You should have your xterm prompt back. Do an ls to see that
your file is there. Go ahead and cat it which will print the
contents of your file to the screen so you can see that you indeed
did just edit a text file.
Two more things to try:
At your xterm prompt, type
Notice that this opens your file for editing.
Quit Emacs with
Now you can tell emacs to open your YOURLASTNAME.txt file by issuing the command:
Emacs responds by asking you the name for the file you wish it to find in the mini-buffer:
Type YOURLASTNAME.txt and hit ENTER. Emacs will open your file.
Quit emacs again with C-x C-c.
You now know the most basic skills of using emacs.
Let's summarize:
Wrote /home/jhetrick/hetrick.txt
in the Mini-buffer, and the Mode-line changes to
----:---F1 hetrick.txt (Text)--L1--All---------------------------------------------------------------------------
The Mode-line now displays the name of the file which is connected to this buffer (hetrick.txt),
and the "modified" asterisks (**) are gone since our changes have been saved.
We can continue to edit the file.
To Quit emacs, remember that we have to type a text sequence. Do:
Now, open emacs without telling it which file to open.
Find file: ~/
Summary
You can open a file, edit it, and save it, pretty much the same as you can do with Notepad.
Command Action At xterm prompt: emacs -nw file Open file in emacs In Emacs: C-x C-f Find (Open) File for editting In Emacs: C-x C-s Save Buffer to File In Emacs: C-x C-c Quit Emacs