Introduction to Unix – CS 21 Lecture 8. Lecture Overview More detail on emacs and vi Regular...
-
Upload
spencer-rice -
Category
Documents
-
view
220 -
download
0
Transcript of Introduction to Unix – CS 21 Lecture 8. Lecture Overview More detail on emacs and vi Regular...
![Page 1: Introduction to Unix – CS 21 Lecture 8. Lecture Overview More detail on emacs and vi Regular expression matching in emacs and vi.](https://reader036.fdocuments.in/reader036/viewer/2022062321/56649ef65503460f94c0a7e9/html5/thumbnails/1.jpg)
Introduction to Unix – CS 21
Lecture 8
![Page 2: Introduction to Unix – CS 21 Lecture 8. Lecture Overview More detail on emacs and vi Regular expression matching in emacs and vi.](https://reader036.fdocuments.in/reader036/viewer/2022062321/56649ef65503460f94c0a7e9/html5/thumbnails/2.jpg)
Lecture Overview More detail on emacs and vi Regular expression matching in
emacs and vi
![Page 3: Introduction to Unix – CS 21 Lecture 8. Lecture Overview More detail on emacs and vi Regular expression matching in emacs and vi.](https://reader036.fdocuments.in/reader036/viewer/2022062321/56649ef65503460f94c0a7e9/html5/thumbnails/3.jpg)
Accessing All Emacs Commands Meta-x Tab completion
Exploring all of the different commands
Approximately 1800 of them
![Page 4: Introduction to Unix – CS 21 Lecture 8. Lecture Overview More detail on emacs and vi Regular expression matching in emacs and vi.](https://reader036.fdocuments.in/reader036/viewer/2022062321/56649ef65503460f94c0a7e9/html5/thumbnails/4.jpg)
Quick 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
![Page 5: Introduction to Unix – CS 21 Lecture 8. Lecture Overview More detail on emacs and vi Regular expression matching in emacs and vi.](https://reader036.fdocuments.in/reader036/viewer/2022062321/56649ef65503460f94c0a7e9/html5/thumbnails/5.jpg)
Quick 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?
![Page 6: Introduction to Unix – CS 21 Lecture 8. Lecture Overview More detail on emacs and vi Regular expression matching in emacs and vi.](https://reader036.fdocuments.in/reader036/viewer/2022062321/56649ef65503460f94c0a7e9/html5/thumbnails/6.jpg)
Search 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
![Page 7: Introduction to Unix – CS 21 Lecture 8. Lecture Overview More detail on emacs and vi Regular expression matching in emacs and vi.](https://reader036.fdocuments.in/reader036/viewer/2022062321/56649ef65503460f94c0a7e9/html5/thumbnails/7.jpg)
Query-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
![Page 8: Introduction to Unix – CS 21 Lecture 8. Lecture Overview More detail on emacs and vi Regular expression matching in emacs and vi.](https://reader036.fdocuments.in/reader036/viewer/2022062321/56649ef65503460f94c0a7e9/html5/thumbnails/8.jpg)
Change In vi C will delete the line you’re 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
![Page 9: Introduction to Unix – CS 21 Lecture 8. Lecture Overview More detail on emacs and vi Regular expression matching in emacs and vi.](https://reader036.fdocuments.in/reader036/viewer/2022062321/56649ef65503460f94c0a7e9/html5/thumbnails/9.jpg)
Replace 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
![Page 10: Introduction to Unix – CS 21 Lecture 8. Lecture Overview More detail on emacs and vi Regular expression matching in emacs and vi.](https://reader036.fdocuments.in/reader036/viewer/2022062321/56649ef65503460f94c0a7e9/html5/thumbnails/10.jpg)
Overwrite 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)
![Page 11: Introduction to Unix – CS 21 Lecture 8. Lecture Overview More detail on emacs and vi Regular expression matching in emacs and vi.](https://reader036.fdocuments.in/reader036/viewer/2022062321/56649ef65503460f94c0a7e9/html5/thumbnails/11.jpg)
Emacs 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 can’t see it, doesn’t mean
it is gone
![Page 12: Introduction to Unix – CS 21 Lecture 8. Lecture Overview More detail on emacs and vi Regular expression matching in emacs and vi.](https://reader036.fdocuments.in/reader036/viewer/2022062321/56649ef65503460f94c0a7e9/html5/thumbnails/12.jpg)
Switching 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
![Page 13: Introduction to Unix – CS 21 Lecture 8. Lecture Overview More detail on emacs and vi Regular expression matching in emacs and vi.](https://reader036.fdocuments.in/reader036/viewer/2022062321/56649ef65503460f94c0a7e9/html5/thumbnails/13.jpg)
Adding 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
![Page 14: Introduction to Unix – CS 21 Lecture 8. Lecture Overview More detail on emacs and vi Regular expression matching in emacs and vi.](https://reader036.fdocuments.in/reader036/viewer/2022062321/56649ef65503460f94c0a7e9/html5/thumbnails/14.jpg)
Read Only Files In Emacs %% will appear on the bottom of
the screen indicating that the file is read-only
You won’t be able to change the file in any way, you’ll just be able to read it
![Page 15: Introduction to Unix – CS 21 Lecture 8. Lecture Overview More detail on emacs and vi Regular expression matching in emacs and vi.](https://reader036.fdocuments.in/reader036/viewer/2022062321/56649ef65503460f94c0a7e9/html5/thumbnails/15.jpg)
Read 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!
![Page 16: Introduction to Unix – CS 21 Lecture 8. Lecture Overview More detail on emacs and vi Regular expression matching in emacs and vi.](https://reader036.fdocuments.in/reader036/viewer/2022062321/56649ef65503460f94c0a7e9/html5/thumbnails/16.jpg)
The 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-<space> The position of the cursor when set
Point Wherever the cursor is located
![Page 17: Introduction to Unix – CS 21 Lecture 8. Lecture Overview More detail on emacs and vi Regular expression matching in emacs and vi.](https://reader036.fdocuments.in/reader036/viewer/2022062321/56649ef65503460f94c0a7e9/html5/thumbnails/17.jpg)
Using The Mark And Point Cntrl-w
Kills (cuts) the region from the mark to the point
Forwards or backwards doesn’t matter
Some actions automatically set the mark Cntrl-y
Pasting (yanking) sets the mark
![Page 18: Introduction to Unix – CS 21 Lecture 8. Lecture Overview More detail on emacs and vi Regular expression matching in emacs and vi.](https://reader036.fdocuments.in/reader036/viewer/2022062321/56649ef65503460f94c0a7e9/html5/thumbnails/18.jpg)
Parenthesis 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
![Page 19: Introduction to Unix – CS 21 Lecture 8. Lecture Overview More detail on emacs and vi Regular expression matching in emacs and vi.](https://reader036.fdocuments.in/reader036/viewer/2022062321/56649ef65503460f94c0a7e9/html5/thumbnails/19.jpg)
Accessing 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
![Page 20: Introduction to Unix – CS 21 Lecture 8. Lecture Overview More detail on emacs and vi Regular expression matching in emacs and vi.](https://reader036.fdocuments.in/reader036/viewer/2022062321/56649ef65503460f94c0a7e9/html5/thumbnails/20.jpg)
Inserting 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
![Page 21: Introduction to Unix – CS 21 Lecture 8. Lecture Overview More detail on emacs and vi Regular expression matching in emacs and vi.](https://reader036.fdocuments.in/reader036/viewer/2022062321/56649ef65503460f94c0a7e9/html5/thumbnails/21.jpg)
Accessing 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*
![Page 22: Introduction to Unix – CS 21 Lecture 8. Lecture Overview More detail on emacs and vi Regular expression matching in emacs and vi.](https://reader036.fdocuments.in/reader036/viewer/2022062321/56649ef65503460f94c0a7e9/html5/thumbnails/22.jpg)
Regular 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
![Page 23: Introduction to Unix – CS 21 Lecture 8. Lecture Overview More detail on emacs and vi Regular expression matching in emacs and vi.](https://reader036.fdocuments.in/reader036/viewer/2022062321/56649ef65503460f94c0a7e9/html5/thumbnails/23.jpg)
Character 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
![Page 24: Introduction to Unix – CS 21 Lecture 8. Lecture Overview More detail on emacs and vi Regular expression matching in emacs and vi.](https://reader036.fdocuments.in/reader036/viewer/2022062321/56649ef65503460f94c0a7e9/html5/thumbnails/24.jpg)
Special Syntax Magic
. * $ treated as special characters This is the default mode
No Magic * . $ treated as normal characters Must be escaped
![Page 25: Introduction to Unix – CS 21 Lecture 8. Lecture Overview More detail on emacs and vi Regular expression matching in emacs and vi.](https://reader036.fdocuments.in/reader036/viewer/2022062321/56649ef65503460f94c0a7e9/html5/thumbnails/25.jpg)
Regular 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 \( \)
![Page 26: Introduction to Unix – CS 21 Lecture 8. Lecture Overview More detail on emacs and vi Regular expression matching in emacs and vi.](https://reader036.fdocuments.in/reader036/viewer/2022062321/56649ef65503460f94c0a7e9/html5/thumbnails/26.jpg)
Colors In Vi Special types of files are
recognized Programming languages
Objects are colored depending on their status Keywords, comments, variables are
all colored differently
![Page 27: Introduction to Unix – CS 21 Lecture 8. Lecture Overview More detail on emacs and vi Regular expression matching in emacs and vi.](https://reader036.fdocuments.in/reader036/viewer/2022062321/56649ef65503460f94c0a7e9/html5/thumbnails/27.jpg)
Colors In Emacs Emacs as well has colors, but not
necessarily on by default Meta-x font-lock-mode
![Page 28: Introduction to Unix – CS 21 Lecture 8. Lecture Overview More detail on emacs and vi Regular expression matching in emacs and vi.](https://reader036.fdocuments.in/reader036/viewer/2022062321/56649ef65503460f94c0a7e9/html5/thumbnails/28.jpg)
Programming 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
![Page 29: Introduction to Unix – CS 21 Lecture 8. Lecture Overview More detail on emacs and vi Regular expression matching in emacs and vi.](https://reader036.fdocuments.in/reader036/viewer/2022062321/56649ef65503460f94c0a7e9/html5/thumbnails/29.jpg)
Startup Files .emacs
Contains all the commands that get executed every time you start emacs
Sets default values .XXXrc
General form of startup files
![Page 30: Introduction to Unix – CS 21 Lecture 8. Lecture Overview More detail on emacs and vi Regular expression matching in emacs and vi.](https://reader036.fdocuments.in/reader036/viewer/2022062321/56649ef65503460f94c0a7e9/html5/thumbnails/30.jpg)
Fun With Emacs Doctor Adventure Solitaire Pong Tetris!
![Page 31: Introduction to Unix – CS 21 Lecture 8. Lecture Overview More detail on emacs and vi Regular expression matching in emacs and vi.](https://reader036.fdocuments.in/reader036/viewer/2022062321/56649ef65503460f94c0a7e9/html5/thumbnails/31.jpg)
In 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
![Page 32: Introduction to Unix – CS 21 Lecture 8. Lecture Overview More detail on emacs and vi Regular expression matching in emacs and vi.](https://reader036.fdocuments.in/reader036/viewer/2022062321/56649ef65503460f94c0a7e9/html5/thumbnails/32.jpg)
Next 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