Dana Vrajitoru
C151 Multi-User Operating Systems
Text Editors
Text Editors
- There are two major editors generally available in most Linux distributions.
- Emacs – a text editor written in Lisp. Modules for improved editing of all kind of files.
The functionality can be expanded. Works both directly in a terminal and in a graphic environment.
- Xemacs – a GUI-based version of Emacs.
- vi – a mostly terminal-based text editor, very reliable.
- vim – (vi improved) – a GUI-based version of vi.
The emacs Editor
- Emacs (Editor MACroS) appeared initially as a set of macros for
another editor (TECO), around 1960. Now it's an editor by itself and
the most commonly used under Linux. Versions of it exist for Windows
and MacOS.
- Emacs is highly programmable and configurable in LISP (similar to
Scheme). It works in text mode too but is more sensitive than other
editors to the terminal properties.
- It helps with writing code in a variety of languages: C++, Python,
HTML, etc. It displays the text with color-codes based on the type of
file and provides automatic indentation.
- It can also read/write email, compile, etc.
- The editor works with a number of buffers, the equivalent of documents
for other editors.
- To start emacs, the emacs command.
Emacs Buffers
- The basic file manipulated by emacs is called a buffer.
- Special buffers, belonging to the editor, whose names are between *
*:
- scratch, can be used for any temporary purpose
- Messages: contains a list of messages from emacs for all the actions
we perform.
- Completions
- mail
- compilation, debug, etc. - specialized buffers for particular
actions
- Every file that we edit is opened in a separate buffer.
- A status line at the bottom contains some information about the
buffer: name, current line,
- Menu operations:
- The Buffers menu lists the buffers and lets us switch the active
buffer. The modified but unsaved buffers are marked with a *.
- The File menu contains the usual file operations.
Emacs Key Bindings
- A key binding is a combination of keys to execute a command.
- Basic editing:
- Open a file
Ctrl-x Ctrl-f
- Save the file
Ctrl-x Ctrl-s
- Quit
Ctrl-x Ctrl-c
- Emacs doesn't wrap the written text.
- Meta-q wrap the text.
- Tab language-sensitive indentation.
-
Cut and paste:
- Any highlighted text is automatically copied (no need for a special
command).
- Right-click selects the text from the previous cursor position to the
click position.
- Easiest way to paste is the middle mouse button or the two mouse
button simultaneously.
- Kill and Yank, equivalent of cut and paste: Ctrl-K, Ctrl-Y
vi
- A text editor, written by Bill Joy in 1976. Short for Visual Interface. Improved versions or clones exist, the most popular being vim.
- It enables fast, simple, and effective text editing mostly based on simple key bindings.
- It provides fast and convenient moving around files and between files.
- "Emacs is a good operating system, while vi is a good editor."
- One must learn a good number of commands to be proficient in vi. Emacs is easier for "newbies".
vi modes
- vi works in two modes: insert mode and command mode.
- Command mode: allows you to do global operations like saving the file, searching for a string and replacing it.
- Insert mode: Everything you type in this mode is directly inserted in the text.
- Switching modes: i in command mode to insert, Esc in insert mode to switch to command.