Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to Unix – CS 21 Lecture 8. Lecture Overview More detail on emacs and vi Regular expression matching in emacs and vi.

Similar presentations


Presentation on theme: "Introduction to Unix – CS 21 Lecture 8. Lecture Overview More detail on emacs and vi Regular expression matching in emacs and vi."— Presentation transcript:

1 Introduction to Unix – CS 21 Lecture 8

2 Lecture Overview More detail on emacs and vi Regular expression matching in emacs and vi

3 Accessing All Emacs Commands Meta-x Tab completion Exploring all of the different commands Approximately 1800 of them

4 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

5 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?

6 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

7 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

8 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

9 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

10 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)

11 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

12 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

13 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

14 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

15 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!

16 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- The position of the cursor when set Point Wherever the cursor is located

17 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

18 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

19 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

20 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

21 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*

22 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

23 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

24 Special Syntax Magic. * $ treated as special characters This is the default mode No Magic *. $ treated as normal characters Must be escaped

25 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 \( \)

26 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

27 Colors In Emacs Emacs as well has colors, but not necessarily on by default Meta-x font-lock-mode

28 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

29 Startup Files.emacs Contains all the commands that get executed every time you start emacs Sets default values.XXXrc General form of startup files

30 Fun With Emacs Doctor Adventure Solitaire Pong Tetris!

31 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

32 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


Download ppt "Introduction to Unix – CS 21 Lecture 8. Lecture Overview More detail on emacs and vi Regular expression matching in emacs and vi."

Similar presentations


Ads by Google