![]() |
Intro to Scientific Computing |
![]() |
| 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 |
Of course we'd like a little more functionality.
Recall that C-x means CTRL-x. There are many commands which take the form C-some key.
And, there is another type of command that we haven't yet used yet (I mentioned it on the previous page).
These are commands that take the form
ESC-key this is abreviated M-key
The reason these commands are abreviated M-key is that M stands for Meta, which comes from the days before keyboards were standarized. Now, the dust has settled and M stands for ESC, the Escape key. This key is a prefix key--you his Esc then another key, as opposed to the Ctrl key which is a modifier--you hold CTRL down while you press another key.
Let's learn a bit more about Emacs.
On the previous pages I had you start emacs with the command: emacs
-nw which opens emacs in an xterm window in text (no GUI window) mode.
Now let's open emacs in GUI mode. Open an xterm and at the prompt type:
Just emacs, no -nw.
This will open an emacs window on your screen that looks like this:
Notice that GUI version has the same four areas as the text mode version:
Let's open a file to play with.
We're going to open it a couple of different ways.
First, click on the File menu on the Toolbar.
Click on "Open File...".
You might expect this to open a GUI window that allows you to click on the file you want.
What happens however, is that the text: "Find file: ~/" in the mini-buffer.
What you do is type the name of the file that you want to edit in the mini-buffer. Emacs puts the
name of the current directory after the "Find File:".
Before we open a file, let's
In the Emacs window,
The mini-buffer says "Quit". This is because we
In general, you can always abort whatever you are doing (or were trying to do).
Now click on the Find File Icon:
The same thing happens as before: "Find File:..." appears in the mini-buffer.
Finally, you can open the file using the method you already know!--the text sequence mode
we used before. This is the method to use when connected to a computer over the network.
In the emacs window, type:
Same thing: you get "Find File:" in the mini-buffer.
This time let's open a file.
If you type the name of a file which does not exist, the buffer is renamed to this name, and the words (New File> appears in the mini-buffer.
Go ahead and type the name of a new file: zzz
Do you see the (New File) text in the mini-buffer?
Now type some characters in the buffer window. Anything will do.
Let's not save this file. We can Kill the buffer by clicking on the X in the Tool Icons.
This brings up a dialog window that asks you: Buffer ... modified; kill anyway? [Yes] [No]
Click [No].
Now let's do the same via text-based commands. In the emacs window, where you still have the new zzz
buffer, type:
This is CTRL-x followed by typing the key k.
The mini-buffer should say: Kill buffer: (default zzz)
The mini-buffer will respond with: Buffer zzz modified; kill anyway? (yes or no)
With the cursor at the right end of the mini-buffer (click on the end of this text if it's not there already).
The zzz buffer should disappear.
Let's summarize:
| Click on the File->Open File... button | C-x C-f |
| Click on the X in the Toolbar Icons | C-x k |
So now let's step up the pace a bit.
Your emacs window should still be open. Go ahead and close it (quit). Remember how?
Now cd to your home dir and make a new subdirectory called editplay/.
Cd to editplay/.
Now save the following file into this
directory:
Open it in emacs (use the GUI version of emacs), by typing
In graphical GUI mode, things work pretty much as you would expect from other word processors like MS Word:
Most normal movement cammands work:
In text mode movement can be achieved with the same keys usually, but sometimes on a remote machine the terminal emulation can be strange. For this reason, emacs has some text-based key strokes which implement movement commands. These are
| C-a | Beginning of line |
| M-f | Forward one word |
| M-a | Previous sentence |
| M-v | Previous screen |
| M-< | Beginning of buffer | C-e | End of line | M-b | Back one word | M-e | Next sentence | C-v | Next screen | M-> | End of buffer |
Notice that the GUI mode of Emacs recognizes all the Text-Based commands as well. In fact, I work with emacs over a network connection so often that when I am in GUI mode, I still use the text-based versions of most commands.
Remember that M-f (for example) means ESC f.
In your open "stairway.txt" buffer,
(pick one of the stanzas of the song)
In Emacs lingo this highlighted area is called
We'll come back to this concept in a minute.
With the region still highlighted,
then click Cut
The highlighted region should disappear. This is the same as CTRL-x in MS Word. You have "Cut" the region of text, and at the same time Copied the region to the Clipboard.
Now go to the Toolbar and
This should put back the text you just "Cut". It will be Pasted at the place where the cursor is located.
Notice too that under Edit you also have the option to Undo your changes.
Try this:
This should put back the text you Cut.
Now let's try this in
This is how you cut/copy text when you are editing using emacs on a remote machine via a text terminal.
We can still issue the key sequences in the open emacs window; it will respond the same way.
In your open emacs window,
Preferrably do this with the arrow keys as you would in an xtext window.
Now,
The words Mark set will appear in the mini-buffer.
The
Having set the Mark at the beginning of the stanza,
Now type
This is the text-mode key sequence that does "Cut".
Similarly, the text-mode key sequence to "Copy" is
The text-mode key sequence to Undo is
Pasting
In GUI mode, pasting the text you just cut is easy. Highlight the text, click Edit->Cut, put the cursor where you want it and click Edit->Paste. Pretty easy.
In Text-Mode, the Paste command is C-y ("y" for yank).
Go back and "Cut" a stanza again:
This has just "Cut" some text, as we did above.
To "Paste" the text, move the cursor to the place you want to paste it, then type:
This should "Paste" the text you just "Cut" at that point.
Let's summarize Cutting and Pasting:
| Highlight text; Edit->Cut | Set Region with Mark and Cursor; C-w |
| Highlight text; Edit->Copy | Set Region with Mark and Cursor; M-w |
| Edit->Paste | C-y |
Startup
| at the prompt: emacs file | emacs -nw file | Open file in emacs |
Open/Close Files
| File->Open File... | C-x C-f | Find (Open) File for editting |
| File->Save Buffer As... | C-x C-s | Save Buffer to File |
| File->Exit Emacs | C-x C-c | Quit Emacs |
| File->Close Current Buffer | C-x k | Close (Kill) Buffer |
Movement
| Home | C-a | Beginning of line |
| M-f | Forward one word | |
| M-a | Previous sentence | |
| PgUp | M-v | Previous screen |
| M-< | Beginning of buffer | |
| End | C-e | End of line |
| M-b | Back one word | |
| M-e | Next sentence | |
| PgDn | C-v | Next screen |
| M-> | End of buffer |
Cut/Copy/Paste
| Highlight text; Edit->Cut | Set Region with Mark (C-space) and Cursor; C-w | Cut |
| Highlight text; Edit->Copy | Set Region with Mark (C-space) and Cursor; M-w | Copy |
| Edit->Paste | C-y | Paste |