Title: Introduction to Unix CS 21
1Introduction to Unix CS 21
2Lecture Overview
- More detail on emacs and vi
- Regular expression matching in emacs and vi
3Accessing All Emacs Commands
- Meta-x
- Tab completion
- Exploring all of the different commands
- Approximately 1800 of them
4Quick Jump To A Line In vi
- G
- By itself, it jumps to the end of the file
- 3G
- Jumps to line 3
- Any number works
5Quick Jump To A Line In emacs
- Meta-x goto-line
- Then type in the line to go to
- Which is faster?
- Which is better?
- Which is more conformant to Unix style?
6Search And Replace In Vi
- s/old/new
- Replaces old with new on the current line
- s/old/new/g
- Replaces all old with new on the current line
- 1, s/old/new/g
- Replaces all old with new in the whole file
7Query-Replace In Emacs
- Meta-
- Meta-x query-replace
- Prompts you for old pattern and new pattern
- Questions you on every instance if you would like
to replace it
8Change In vi
- C will delete the line youre at and put you into
insert mode - Changing the current line
- c works much like d
- cc change line
- cw change word
- c10 change next ten lines
9Replace In vi
- From command mode
- r will replace a single character
- R will put you into Replace mode
- Everything you type overwrites what was
previously there
10Overwrite Mode In Emacs
- Hitting the Insert key changes modes in emacs
- Takes you into and out of overwrite
- You suddenly will find yourself overwriting
instead of inserting - Check for (Ovwrt)
11Emacs Buffer Primer
- When emacs is run without any parameters, it
opens up a buffer called scratch - All files opened and all messages that pop up are
stored in different buffers and are always
accessible - Window vs. buffer
- Just because you cant see it, doesnt mean it is
gone
12Switching Buffers And Multiple Windows
- Cntrl-x, cntrl-b
- List all buffers
- Cntrl-x b
- Switch to buffer
- Cntrl-x 4 b
- Switch to buffer in another window
13Adding Or Getting Rid Of Windows
- Cntrl-x 2
- Add another window (vertically)
- Cntrl-x 3
- Add another window (horizontally)
- Cntrl-x 1
- Only show one window
14Read Only Files In Emacs
- will appear on the bottom of the screen
indicating that the file is read-only - You wont be able to change the file in any way,
youll just be able to read it
15Read Only Files In vi
- vi will warn you when you attempt to modify a
read-only file - It will let you change the file, though
- If you attempt to save the changes, it will warn
you again - Using the !, you can force the changes
- vi will let you modify a read-only file!
16The Mark And The Point
- In order to highlight large sections of text,
emacs introduces the idea of the mark and the
point - Mark
- Set with Cntrl-
- The position of the cursor when set
- Point
- Wherever the cursor is located
17Using The Mark And Point
- Cntrl-w
- Kills (cuts) the region from the mark to the
point - Forwards or backwards doesnt matter
- Some actions automatically set the mark
- Cntrl-y
- Pasting (yanking) sets the mark
18Parenthesis Matching In Emacs
- Emacs will warn you when parenthesis are
mismatched - ()
- Emacs will always tell you what a parenthesis
matches - On screen
- Temporarily highlight
- Off screen
- State what matches
19Accessing Unix Commands in vi
- vi has access to the shell and can run commands
- !COMMAND
- Will allow you to run one command
- !!COMMAND
- Replace the current line with output of the
command
20Inserting Files And Commands In vi
- r FILE
- Insert the contents of FILE directly where the
cursor is - ! COMMAND
- Pipe the contents of the current paragraph into
COMMAND and replace the current paragraph with
the output
21Accessing Unix Commands In Emacs
- Oh yeah? Watch this!
- Meta-x shell
- Actually opens up a shell (command line) INSIDE
of emacs that allows you to run any program and
still move around, cut and paste, and do anything
you want - The shell is located in another buffer
- shell
22Regular Expression Matching In vi
- Just like searching for a normal pattern
- Syntax is mostly the same as grep
- Some symbols must be escaped
- \?
- \
- \(
- \)
- Character sets are escape characters
23Character Sets
- \d digit
- \D non-digit
- \a alphabetic character
- \A non-alphabetic character
- \l lowercase character
- \L non-lowercase character
- \u uppercase character
- \U non-uppercase character
24Special Syntax
- Magic
- . treated as special characters
- This is the default mode
- No Magic
- . treated as normal characters
- Must be escaped
25Regular Expression Matching In Emacs
- Cntrl-Meta-S
- Regular expression search forwards
- Cntrl-Meta-R
- Regular expression search backwards
- Syntax is mostly the same as grep
- Some characters must be escaped
- \( \)
26Colors In Vi
- Special types of files are recognized
- Programming languages
- Objects are colored depending on their status
- Keywords, comments, variables are all colored
differently
27Colors In Emacs
- Emacs as well has colors, but not necessarily on
by default - Meta-x font-lock-mode
28Programming Modes In Emacs
- More than just colors
- C and C files
- HTML files
- VHDL files
- Perl, prolog, ml, lisp, shell programming
- Pretty much any language you can think of has had
a mode in emacs written for it - Some are more extensive than others
29Startup Files
- .emacs
- Contains all the commands that get executed every
time you start emacs - Sets default values
- .XXXrc
- General form of startup files
30Fun With Emacs
- Doctor
- Adventure
- Solitaire
- Pong
- Tetris!
31In Lab Today
- You will play around with both Emacs and vi
- You will try out both basic file editing as well
as some of the more advanced features
32Next Week
- We look more at shells and specifically we look
at special features of bash - Midterm next Thursday
- Covers all material up from the first day of
class until next Tuesday