cs 497c – introduction to unix lecture 17: - the gnu emacs editor

12
CS 497C – Introduction to UNIX Lecture 17: - The GNU emacs Editor Chin-Chih Chang [email protected]. edu

Upload: csilla

Post on 08-Jan-2016

36 views

Category:

Documents


3 download

DESCRIPTION

CS 497C – Introduction to UNIX Lecture 17: - The GNU emacs Editor. Chin-Chih Chang [email protected]. The GNU emacs Editor. emacs was create by Richard Stallman (the founder of GNU, now the Free Software Foundation). The program was originally written as a set of macros for the TECO editor. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: CS 497C – Introduction to UNIX Lecture 17: - The GNU emacs Editor

CS 497C – Introduction to UNIXLecture 17: - The GNU emacs

Editor

Chin-Chih [email protected]

Page 2: CS 497C – Introduction to UNIX Lecture 17: - The GNU emacs Editor

The GNU emacs Editor

• emacs was create by Richard Stallman (the founder of GNU, now the Free Software Foundation).

• The program was originally written as a set of macros for the TECO editor.

• emacs is not available in all UNIX systems but is standard on Linux.

• GNU emacs is more than an editor; it handles a number of non-editing functions.

Page 3: CS 497C – Introduction to UNIX Lecture 17: - The GNU emacs Editor

The GNU emacs Editor

• vi often does things with fewer keystrokes, but emacs easily surpass vi when it comes to searching and replacing and using macros.

• After invoking emacs, you have a full screen. 22 of the 25 lines are available for editing.

Page 4: CS 497C – Introduction to UNIX Lecture 17: - The GNU emacs Editor

The GNU emacs Editor

• The top one in reverse video shows a menu, the lower one in reverse video shows the mode line, and the bottom line is the minibuffer showing an emacs-generated message.

• In the mode line you can see the filename and the cursor position (L1).

• Like most word processors unlike vi, emacs is a mode-less editor.

Page 5: CS 497C – Introduction to UNIX Lecture 17: - The GNU emacs Editor

emacs Preliminaries

• In the emacs documentation, key sequences described as:– C-e – This is [Ctrl-e].– C-x C-b – This is [Ctrl-x][Ctrl-b].– C-x b – This is [Ctrl-x]b.– M-e – This is [Meta-e].

• On the PC, you can use the [Alt] key or [Esc]-release to substitute [Meta] key.

Page 6: CS 497C – Introduction to UNIX Lecture 17: - The GNU emacs Editor

emacs Preliminaries• When you press a valid key sequence,

emacs executes a command associated with the key.

• For instance, when you press [Ctrl-n], emacs executes the next-line command.

• To canceling a sequence, use [Ctrl-g].• emacs reads the file .emacs at startup.

emacs –q ignores the .emacs file at startup.• Use [Ctrl-x][Ctrl-c] to quit emacs.

Page 7: CS 497C – Introduction to UNIX Lecture 17: - The GNU emacs Editor

Inserting and Replacing Text• The default input mode is the insert mode.

To switch to the overwrite mode, press the [Insert] key or enter the overwrite-mode command which can be done by the key sequence [Alt-x]ov[tab].

• To enter a control character, first enter [Ctrl-q] and then the control character.

• To save a file, use [Ctrl-x] [Ctrl-s].• To save a file as a different filename, use

[Ctrl-x][Ctrl-w].

Page 8: CS 497C – Introduction to UNIX Lecture 17: - The GNU emacs Editor

Saving Text

• To open a different file, use [Ctrl-x][Ctrl-f].

• emacs has an autosave feature which automatically saves a copy of the buffer in #filename#.

• To recover from the crash, use the recover-file command:

[Alt-x]recover-file

Page 9: CS 497C – Introduction to UNIX Lecture 17: - The GNU emacs Editor

The Digital Argument

• To perform a command as many times, use the digital argument. The number is prefixed by the [Meta] ([Alt] on PC) key.

• For example, to delete 5 characters, use [Meta-5][Ctrl-d].

• The other way is to use the universal argument – [Ctrl-u] such as

[Ctrl-u]5[Ctrl-d].

Page 10: CS 497C – Introduction to UNIX Lecture 17: - The GNU emacs Editor

Navigation

• emacs uses the control keys to move in the four directions. These keys are quite intuitive – b (back), f (forward), p (previous line) and n (next line).

• [Ctrl-b] – move left, [Ctrl-f] – move right, [Ctrl-p] – move up, [Ctrl-n] – move down.

• To scroll full page forward, use [Ctrl-v]. To scroll full page backward, use [Alt-v].

• To redraw the screen and position cursor at center of screen, use [Ctrl-l].

Page 11: CS 497C – Introduction to UNIX Lecture 17: - The GNU emacs Editor

Navigation

• To move to the beginning of a line, use [Ctrl-a]. To move the end of a line, use [Ctrl-e].

• To move the beginning of the word, use [Alt-f]. To move the end of the word, use [Alt-b].

• To move the specified line number, use [Alt-x] goto-line [Enter] and then type the line number.

Page 12: CS 497C – Introduction to UNIX Lecture 17: - The GNU emacs Editor

Working with Regions

• To move to the beginning of the file, use [Alt-<]. To move to the end of the file, use [Alt->].

• To mark a region, first move the cursor to the beginning of the section and use [Ctrl-Spacebar] or [Ctrl-@] and then move the cursor to the end of the section.

• You can use [Ctrl-x][Ctrl-x] to toggle between two ends.