EMACS Editor Workshop
Introduction
EMACS is an editor available in UNIX. This is a screen editor like vi editor. Unlike vi, EMACS is not an insertion mode editor. Meaning any character typed will be automatically inserted into the file unless it includes a command prefix. Commands in EMACS are either control characters (hold down control key while typing the character) or prefixed by one of a reserved character with escape key. Emacs have the option to divide the screen into several screens. In this case each screen has a buffer. This could be used in case if we want to edit the same file at multiple location at once.
Getting Started
Login to SSH secure shell client using the following information:
- Host Name : willow.olemiss.edu
- User Name : student
- Password : Will be provided during the workshop
EMACS Commands
C- indicates hold down control key while entering character
M- indicates prefix reserved character with escape key
Using Help
- Type emacs -nw to enter the editor
- C- h t : to open a tutorial session
- C- v : to page down
- M- v : to page up
- C- x C- c : to exit
- C- h a : prompts for a string and then searches for all EMACS commands that contains that string
Creating a File
- Type emacs -nw to enter the editor
- C- x C- f : to find a file
- EMACS opens file in insertion mode and therefore we can directly start inserting
- press enter key to get to the next line
- C- x C- s : to save file
- C- g : to stop the command (could be used if the editor is hung or if we typed a wrong command)
- C- x C- c : to exit
View a File
Edit a File
- Type emacs -nw to enter the editor
- C- x C- f : to open a file
- C- x C- s : to save file, here a backup of the original will be automatically created
- C- x C- c : to exit
Moving Around in a File
- Type emacs -nw to enter the editor
- C- x C- f : to open a file
- C- p : move to previous line
- C- n : move to next line
- C- f : move forward a character
- C- b : move backward a character
- M- f : move to next word
- M- b : move to previous word
- C- a : move to beginning of a line
- C- e : move to end of a line
- M- a : move to beginning of a sentence
- M- e : move to end of a sentence
- M- < : move to beginning of the entire text
- M- > : move to end of the entire text
- C- u : to provide a numerical argument to repeat a command . For example, C- u 8 C- f will move 8 characters forward
Delete
- delete key to delete the character after the cursor
- C- d : delete a character before the cursor
- M- d : delete next word
- C- k : delete from the cursor position to the end of the file
- M- k : delete from the cursor position to the end of the sentence
- C- space key : start selecting from the current cursor position
- C- w : delete from the start of the selection to the current cursor position
- M- w : copy the content
- C- y : paste the content
Undo
- C- x u : undo the changes made by a command
Search
Save and Exit
- C- x C- s : to save file, here a backup of the original will be automatically created
- C- x C- c : to exit
Create Multiple screens
- Type emacs -nw to enter the editor
- C- x C- f : to open a file
- C- x 2 : create two screens
- C- x o : switch between screens