+ All Categories
Home > Documents > Introduction to Unix – CS 21

Introduction to Unix – CS 21

Date post: 06-Jan-2016
Category:
Upload: kohana
View: 36 times
Download: 0 times
Share this document with a friend
Description:
Introduction to Unix – CS 21. Lecture 8. Lecture Overview. More detail on emacs and vi Regular expression matching in emacs and vi. Accessing All Emacs Commands. Meta-x Tab completion Exploring all of the different commands Approximately 1800 of them. Quick Jump To A Line In vi. G - PowerPoint PPT Presentation
32
Introduction to Unix – CS 21 Lecture 8
Transcript
Page 1: Introduction to Unix – CS 21

Introduction to Unix – CS 21

Lecture 8

Page 2: Introduction to Unix – CS 21

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

emacs and vi

Page 3: Introduction to Unix – CS 21

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Fun With Emacs Doctor Adventure Solitaire Pong Tetris!

Page 31: Introduction to Unix – CS 21

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

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


Recommended