0% found this document useful (0 votes)
69 views20 pages

Unix Text Editors: vs. Battle To The Death Coming Soon On Pay-Per-View

vi and emacs are two popular Unix text editors. vi is a visual text editor that has two main modes - command mode for cursor movement and editing commands, and insert mode for typing text. It uses key combinations like dd to delete lines and i to enter insert mode. Emacs also allows editing text and has its own set of key commands that typically begin with Control or Meta (usually Escape) like C-x C-c to exit. Both editors have searching, saving files, and other advanced features but vi is more cryptic while emacs is highly customizable with ELisp.

Uploaded by

Sangram Anand
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
69 views20 pages

Unix Text Editors: vs. Battle To The Death Coming Soon On Pay-Per-View

vi and emacs are two popular Unix text editors. vi is a visual text editor that has two main modes - command mode for cursor movement and editing commands, and insert mode for typing text. It uses key combinations like dd to delete lines and i to enter insert mode. Emacs also allows editing text and has its own set of key commands that typically begin with Control or Meta (usually Escape) like C-x C-c to exit. Both editors have searching, saving files, and other advanced features but vi is more cryptic while emacs is highly customizable with ELisp.

Uploaded by

Sangram Anand
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 20

Unix Text Editors

vs. vi

Battle to the Death


Coming soon on pay-per-view.
The vi command

vi is a visual text editor.

Most of you are too young to understand what a
non-visual editor might be!
 check out the ed editor!

vi shows you part of your file and allows you to
enter commands that change something (add
new stuff, delete a char or line, etc).
vi modes
vi has a couple of modes:
 command mode: move the cursor around, move
to a different part of the file, issue editing
commands, switch to insert mode.
 insert mode: whatever you type is put in the file
(not interpreted as commands).

when you first start vi you will be in command mode.


Cursor Movement Commands
(only in command mode!)

h move left one position


l move right one position t hi s
d oes
al so
j move up one line ce bar
spa
k move down one line

Your arrow keys might work (depends on the


version of vi and your terminal)
More Cursed Cursor Movement
w move forward one word
b move backward one word
e move to the end of the word
) move to beginning of next sentence
( move to beginning of current sentence
Scrolling Commands
CTRL-F scroll forward one screen
CTRL-B scroll backward one screen
CTRL-D scroll forward 1/2 screen
CTRL-U scroll backward 1/2 screen
Command that delete stuff
x delete character (the one at the cursor)
dw delete word
dd delete line
X delete back one character (backspace)
3x delete 3 characters (any number works)
5dd delete 5 lines (any number works)
Changing Text
cw change word (end with Esc)
cc change line (end with Esc)
C change rest of the line
rx replace character with 'x' (could be
anything, not just 'x')
Insert Mode

In insert mode whatever you type goes in to
the file. There are many ways to get in to
insert mode:
i insert before current position
a append (insert starting after cursor)
A append at end of line
R begin overwriting text
Ending Insert Mode

To get out of insert mode (back to command
mode) you press "Esc" (the escape key).


There is a status line (bottom of screen) that
tells you what mode/command you are in.
Saving and Exiting
ZZ save if changes were made, and quit.
:wq Write file and quit
:w Write file
:w file Write to file named file
:q Quit
:q! Really quit (discard edits)
Searching Commands
/text search forward for text
?text search backward for text
n repeat previous search
N repeat search in opposite direction
Other Stuff

Copying and Yanking (Paste)

Remembering positions

Switching files

Repeating commands

Display line numbers

Run Unix commands (for example: emacs)

emacs is every bit as cryptic as vi!

emacs allows you to customize it with new
commands and keyboard shortcuts.

The emacs commands are written in elisp (a
dialect of Lisp), so you need to understand elisp
to do serious customization.
Emacs online help

Emacs has a built-in help system.


Press ^h (Ctrl-h) to get to the help system.
 Now Press ? For a list of options
 Press "t" for a tutorial!
Emacs meta key

Many emacs commands are invoked with
sequence of keystrokes.

Emacs doesn't have modes like vi – you can
always enter text (at the current cursor
position) or commands.

Many commands start with a special
keystroke called the metakey. (others use the
control key).

The ESC key is (usually) the meta key.
Command List Syntax

The book shows a list of tons of emacs
commands. The syntax used to show this list
looks like this:

C-a C-b (means Ctrl-a , Ctrl-b)


M-a M-b (means Esc, a, Esc, b)
Important Commands

Exit: C-x C-c

Save file : C-x C-s

Undo: C-x u

Get out of a command: C-g
Cursor movement

Cursor keys usually work (it depends on how
your terminal is set up and how emacs is
configured).
C-f: forward (right arrow)
C-b: backward (left arrow)
C-p: previous line (up arrow)
C-n: next line (down arrow)
Other stuff in emacs

Move by words, sentences, paragraphs

File handling – save/load file, etc.

Delete char, word, sentence, region

Buffer manipulation (multiple buffers)

Searching, replacing

Automatic indentation (major mode)

Lots more (try the tutorial, read the book!)

You might also like