Policies and Principles Part I Recurring Themes Annoucements - - PowerPoint PPT Presentation

policies and principles
SMART_READER_LITE
LIVE PREVIEW

Policies and Principles Part I Recurring Themes Annoucements - - PowerPoint PPT Presentation

Lecture 3: Relative Jumps, Policies and Principles Part I Recurring Themes Annoucements Homework 1 due now! '*' means it will not be in any of the exams. Last Time We talked about the ambiguity! We talked about two ways of


slide-1
SLIDE 1

Lecture 3: Relative Jumps, Policies and Principles

Part I Recurring Themes

slide-2
SLIDE 2

Annoucements

  • Homework 1 due now!
  • '*' means it will not be in any of the

exams.

slide-3
SLIDE 3

Last Time

  • We talked about the ambiguity!
  • We talked about two ways of resolving

ambiguity...

slide-4
SLIDE 4

Last Time

  • We talked about the ambiguity!
  • We talked about two ways of resolving

ambiguity...

  • In Homework 1, you saw the f command.
  • An example of relative jumps...
slide-5
SLIDE 5
  • Relative jumps
  • Modal Editing and Principles
  • "Unix Standards"
slide-6
SLIDE 6
  • Relative jumps
  • Modal Editing and Principles
  • "Unix Standards"
slide-7
SLIDE 7

Relative Jumps

slide-8
SLIDE 8

Relative Jumps

Misspelled words are hard to describe!

slide-9
SLIDE 9

Relative Jumps

Misspelled words are hard to describe! "Misspelled" is not a very good description, from Vim's standpoint!

slide-10
SLIDE 10

Relative Jumps

Misspelled words are hard to describe! "Misspelled" is not a very good description, from Vim's standpoint!

slide-11
SLIDE 11

Relative Jumps

slide-12
SLIDE 12

Relative Jumps

Um...

It is pretty much unreadable as it is....

slide-13
SLIDE 13

Relative Jumps

Um...

It is pretty much unreadable as it is....

Nearly impossible to describe/read!

slide-14
SLIDE 14

Relative Jumps

  • Relative jumps deals with the special

case that some objects are inherently hard to describe!

slide-15
SLIDE 15

Relative Jumps

  • Relative jumps deals with the special

case that some objects are inherently hard to describe!

  • ex. perl oneliners, regular expressions,

typos, etc...

slide-16
SLIDE 16

Relative Jumps

  • What this means: Don't abuse it!!!
  • Many people use them for very very

very very bad reasons...

slide-17
SLIDE 17

Relative Jumps

  • What this means: Don't abuse it!!!
  • Many people use them for very very

very very bad reasons...

  • Explanation: when there is a

straightforward way to navigate, always use the straightforward way!! /<pattern><CR>

slide-18
SLIDE 18

Relative Jumps

  • What this means: Don't abuse it!!!
  • Many people use them for very very

very very bad reasons...

  • Another name that you'll hear, which is

essentially synonmous: motions.

  • (prime example: vimtutor and relative

numbers...)

slide-19
SLIDE 19

Relative Jumps

  • What this means: Don't abuse it!!!
  • Many people use them for very very

very very bad reasons...

  • There is a very specific reason why they

are inconvenient... we will cover it next lecture.

slide-20
SLIDE 20

Relative Jumps

hm, so I can't exactly describe it through the CONTENTS of the location... But what do I KNOW about the purpose/characteristic of the location?

slide-21
SLIDE 21

Relative Jumps

Well, it's the regex that I am grepping for!

slide-22
SLIDE 22

Relative Jumps

Well, it's the regex that I am grepping for! /grep<CR> -- Locate a grep call

slide-23
SLIDE 23

Relative Jumps

Well, it's the regex that I am grepping for! /grep<CR> -- Locate a grep call f/ -- Jump to the regex relative to that grep call.

slide-24
SLIDE 24

Relative Jumps

Well, it's the regex that I am grepping for! /grep<CR> -- Locate a grep call f/ -- Jump to the regex relative to that grep call.

BUT!! This is unclear!!

slide-25
SLIDE 25

Relative Jumps

/grep<CR> -- Locate a grep call f/ -- Jump to the regex relative to that grep call.

slide-26
SLIDE 26

Relative Jumps

/grep<CR> -- Locate a grep call f/ -- Jump to the regex relative to that grep call. Locates any grep call!

slide-27
SLIDE 27

Relative Jumps

/grep<CR> -- Locate a grep call f/ -- Jump to the regex relative to that grep call. /author<CR> -- Locate author block

slide-28
SLIDE 28

Relative Jumps

/grep<CR> -- Locate a grep call f/ -- Jump to the regex relative to that grep call. /author<CR> -- Locate author block Description: Locate the regular expression in the grep call under the author block.

slide-29
SLIDE 29

Relative Jumps

/grep<CR> -- Locate a grep call f/ -- Jump to the regex relative to that grep call. /author<CR> -- Locate author block Description: Locate the regular expression in the grep call under the author block.

slide-30
SLIDE 30

Relative Jumps

  • It is a natural way to resolve ambiguity

due to unwieldy code!!

  • Natural description of some

regex/body/block: the <object> under <name>

  • Hence, locating requires jumping

relative to something easier to describe!

slide-31
SLIDE 31

Common Jumps

  • Distinctive character jumps
  • (you've seen it in the homework...)

f<char> Jump to the next <char> on the same line F<char> Jump to the previous <char> on the same line

slide-32
SLIDE 32

Common Jumps

  • One word/WORD jumps (rarely used,

sometimes known as motions): w Jump to next word b Jump to previous word

slide-33
SLIDE 33

Common Jumps

  • One line jumps

j Jump down one line k Jump up one line Try to avoid using one line jumps! It doesn't always jump to where you expect. (in this course, you'll never have to use it more than twice consecutively)

slide-34
SLIDE 34

Relative Jumps

  • Again, use it only when needed!
  • Often used as a combination of:

/<pattern><CR> f<char> <some other precise close jumps>

slide-35
SLIDE 35
  • Relative jumps
  • Modal Editing and Principles
  • "Unix Standards"
slide-36
SLIDE 36
  • Relative jumps
  • Modal Editing and Principles
  • (actually)
  • "Unix Standards"
slide-37
SLIDE 37

Modal Editing

  • So we've talked about locating...
slide-38
SLIDE 38

Modal Editing

  • So we've talked about locating...
  • When we're typing, we want to be able

to type every single character...

slide-39
SLIDE 39

Modal Editing

  • So we've talked about locating...
  • When we're typing, we want to be able

to type every single character... f<char>

  • We want to be able to use f<char>, but

also type out the character 'f' as well!

slide-40
SLIDE 40

Modal Editing

  • Hence there are modes:
  • Normal Mode
  • Insert Mode
  • ???
  • Insert-Normal Mode
  • other modes that for the purposes of this

course, we don't care about/are bad...

slide-41
SLIDE 41

Modal Editing

  • Hence there are modes:
  • Normal Mode
  • Insert Mode
  • ??? (We'll talk about extensively in another

lecture)

  • Insert-Normal Mode
  • other modes that for the purposes of this

course, we don't care about/are bad...

slide-42
SLIDE 42

Modal Editing

  • Before that...
  • Myth #3: In Vim, you are almost always

in Normal Mode.

slide-43
SLIDE 43

Modal Editing

  • Before that...
  • Myth #3: In Vim, you are almost always

in Normal Mode.

  • This is highly misleading! (albeit well-

intentioned)

slide-44
SLIDE 44

Modal Editing

slide-45
SLIDE 45

Modal Editing

Um, don't have any text to actually 'edit'.

slide-46
SLIDE 46

Modal Editing

  • When using Vim, there are different

phases:

  • Drafting
  • Skimming
  • Editing
slide-47
SLIDE 47

Modal Editing

  • When using Vim, there are different

phases:

  • Drafting

– Refers to composing something entirely new, either from scratch, or appending large chunks to some existing text

slide-48
SLIDE 48

Modal Editing

  • When using Vim, there are different

phases:

  • Drafting
  • Skimming

– Reading through existing text

slide-49
SLIDE 49

Modal Editing

  • When using Vim, there are different

phases:

  • Drafting
  • Skimming
  • Editing

– Manipulating or correcting existing text

slide-50
SLIDE 50

Modal Editing

  • When using Vim, there are different

phases:

  • Drafting
  • Skimming
  • Editing
  • So what does this have to do with

modes?

slide-51
SLIDE 51

Insert Mode

slide-52
SLIDE 52

Insert Mode

slide-53
SLIDE 53

Insert Mode

  • Well, we have to be able to type every

character...

  • Hence, insert mode is the mode for

typing every character!

slide-54
SLIDE 54

Insert Mode

  • What this means:

– All keyboard characters behave as you would expect... (ex. 'i' just enters the character i, etc.)

slide-55
SLIDE 55

Insert Mode

  • What this means:

– All keyboard characters behave as you would expect... (ex. 'i' just enters the character i, etc.) – We will have to find another way to use commands to manipulate text!

slide-56
SLIDE 56

Insert Mode

  • For these reasons, there are very few

commands in insert mode, but they are very important nevertheless!

  • When you are drafting, you are always

in insert mode.

slide-57
SLIDE 57

Insert Mode

  • For these reasons, there are very few

commands in insert mode, but they are very important nevertheless!

  • When you are drafting, you are almost

always in insert mode. (we'll see why in the future...)

slide-58
SLIDE 58

Insert Mode

Well, most keys are mapped to some print character that we have to type...

slide-59
SLIDE 59

Insert Mode

Well, most keys are mapped to some print character that we have to type...

That one nonprintable character on the keyboard!

slide-60
SLIDE 60

Insert Mode

  • Hence, all commands in insert mode are

prefixed with <C->.

  • Which is why there are so few of

them...

slide-61
SLIDE 61

Insert Mode

  • Commands follow a 'unix standard' or
  • convention. (usually...)
  • <C-h>: remove the last character.
  • <C-w>: remove the last word.
  • <C-u>: remove the entire line.
  • <C-r>: a bit more complicated...
  • etc.
  • These commands are relative to the current

cursor! (quickdemo)

slide-62
SLIDE 62

Insert Mode

  • Commands follow a 'unix standard' or
  • convention. (usually...)
  • <C-h>: remove the last character.
  • <C-w>: remove the last word. (will be discussed

in the future)

  • <C-u>: remove the entire line.
  • <C-r>: a bit more complicated...
  • etc.
  • These commands are relative to the current

cursor! (quickdemo)

slide-63
SLIDE 63

Insert Mode

  • Commands follow a 'unix standard' or
  • convention. (usually...)
  • <C-h>: remove the last character.
  • <C-w>: remove the last word. (will be discussed

in the future)

  • <C-u>: remove the entire line.
  • <C-r>: a bit more complicated...
  • etc.
  • These commands are relative to the current

cursor! (quickdemo)

slide-64
SLIDE 64

Insert Mode

slide-65
SLIDE 65

Modal Editing

  • Myth #3: In Vim, you are almost always

in Normal Mode.

slide-66
SLIDE 66

Modal Editing

  • Myth #3: In Vim, you are almost always

in Normal Mode.

  • When you are drafting in Vim, you are

almost always in Insert Mode!

slide-67
SLIDE 67

Modal Editing

  • Myth #3: In Vim, you are almost always

in Normal Mode.

  • When you are drafting in Vim, you are

almost always in Insert Mode!

slide-68
SLIDE 68

Modal Editing

  • When using Vim, there are different

phases:

  • Drafting -- almost always in insert mode
  • Skimming
  • Editing
slide-69
SLIDE 69

Modal Editing

  • When using Vim, there are different

phases:

  • Drafting -- almost always in insert mode
  • Skimming
  • Editing
slide-70
SLIDE 70

Skimming

  • When you just want to skim/read the

content of the file, you probably don't want to make modifications...

slide-71
SLIDE 71

Skimming

  • When you just want to skim/read the

content of the file, you probably don't want to make modifications...

  • <C-> itself provides limited number of

commands...

slide-72
SLIDE 72

Skimming

  • When you just want to skim/read the

content of the file, you probably don't want to make modifications...

  • <C-> itself provides limited number of

commands...

  • Most importantly, poor ergonomics!
slide-73
SLIDE 73

Normal Mode

  • Hence, we have normal mode!
  • Entire mode for 2 main purposes:

– Provide good skimming/scrolling commands – Provide good editing commands Without completely awful ergonomics!

slide-74
SLIDE 74

Normal Mode

  • Hence, we have normal mode!
  • Entire mode for 2 main purposes:

– Provide good skimming/scrolling commands – Provide good editing commands Without completely awful ergonomics!

slide-75
SLIDE 75

Normal Mode

  • Hence, we have normal mode!
  • Entire mode for 2 main purposes:

– Provide good skimming/scrolling commands – Provide good editing commands Without completely awful ergonomics!

so far, all commands we've talked about are in normal mode! /<pattern><CR> f c d I A ea

slide-76
SLIDE 76

Normal Mode

slide-77
SLIDE 77

Window and Cursor Policy

  • Vim's cursor and screen behaves very

differently from other editors.

slide-78
SLIDE 78

Window and Cursor Policy

  • Vim's cursor and screen behaves very

differently from other editors.

  • Principle:
  • cursor follows edit
  • screen follows view
  • quickdemo (lorem.txt)
slide-79
SLIDE 79

Window and Cursor Policy

  • What this means:
  • skimming -- view -- screen
  • editing -- edit -- cursor
slide-80
SLIDE 80

Window and Cursor Policy

  • What this means:
  • skimming -- view -- screen
  • editing -- edit -- cursor
  • Implication: you use different

commands in different phases!

slide-81
SLIDE 81

Skimming

  • We use the screen commands in normal mode while

skimming.

  • They do not modify the file!
  • <C-d>: Half screen down
  • <C-u>: Half screen up
  • <C-e>: One line down
  • <C-y>: One line up
  • zz: Set screen to cursor in midscreen
  • etc...
  • Many commands have <C-> modifiers... Because Vim has

waaaayy too many key mappings! :(

slide-82
SLIDE 82

Skimming

  • We use the screen commands in normal mode while

skimming.

  • They do not modify the file!
  • <C-d>: Half screen down
  • <C-u>: Half screen up
  • <C-e>: One line down
  • <C-y>: One line up
  • zz: Set screen to cursor in midscreen
  • etc...
  • Many commands have <C-> modifiers... Because Vim

has wayy too many key mappings! :(

slide-83
SLIDE 83

Modal Editing

  • When using Vim, there are different

phases:

  • Drafting -- almost always in insert mode
  • Skimming -- always in normal mode
  • Editing
slide-84
SLIDE 84

Modal Editing

  • When using Vim, there are different

phases:

  • Drafting -- almost always in insert mode
  • Skimming -- always in normal mode
  • Editing
slide-85
SLIDE 85

Editing

  • Complication:

– Want to be able to type every character – Want to have not completely terrible ergonomics for editing commands as well....

slide-86
SLIDE 86

Editing

  • Complication:

– Want to be able to type every character – Want to have not completely terrible ergonomics for editing commands as well....

slide-87
SLIDE 87

Editing

  • Normal modes provides commands for

locating and editing (as you've seen already)...

  • But after using some edit command,

have to specify what to edit TO.

slide-88
SLIDE 88

Editing

  • Normal modes provides commands for

locating and editing (as you've seen already)...

  • But after using some editing command,

have to specify what to edit TO.

  • Solution: Call locating and editing

commands in normal mode. Then jumps into insert mode to specify what to edit to....

slide-89
SLIDE 89

Editing

  • Example:

ciw lol ???

slide-90
SLIDE 90

Editing

  • Example:

ciw change current word (while in normal mode), then jumps into insert mode. lol ???

slide-91
SLIDE 91

Editing

  • Example:

ciw change current word (while in normal mode), then jumps into insert mode. lol changes the word to 'lol' (now I am in insert mode) ???

slide-92
SLIDE 92

Editing

  • Example:

ciw change current word (while in normal mode), then jumps into insert mode. lol changes the word to 'lol' (now I am in insert mode) ???

slide-93
SLIDE 93

Editing

  • Complication: you want to continue

editing by using normal mode commands....

slide-94
SLIDE 94

Editing

  • Complication: you want to continue

editing by using normal mode commands....

  • But, you are currently in insert mode...
slide-95
SLIDE 95

Editing

  • Complication: you want to continue

editing by using normal mode commands....

  • But, you are currently in insert mode...
  • So: we need some nonprintable

character to jump from insert mode to normal mode!

slide-96
SLIDE 96

'Escape' command

<Esc>

slide-97
SLIDE 97

Editing

  • Has debatable ergonomics...
  • You may choose to remap this key in the

future...

  • Specialized purpose: escaping from

insert mode to normal mode!

slide-98
SLIDE 98

Editing

  • Example:

ciw change current word (while in normal mode), then jumps into insert mode. lol changes the word to 'lol' (now I am in insert mode) <Esc> Return to normal mode!

slide-99
SLIDE 99

Modal Editing

  • When using Vim, there are different

phases:

  • Drafting -- almost always in insert mode
  • Skimming -- always in normal mode
  • Editing -- always alternating between

normal mode and insert mode

slide-100
SLIDE 100

Modal Editing

  • When using Vim, there are different phases:
  • Drafting -- almost always in insert mode
  • Skimming -- always in normal mode
  • Editing -- always alternating between normal

mode and insert mode

  • Takeaway: do not be afraid of insert mode!

Many actions should be done in insert mode!

slide-101
SLIDE 101

Next time

  • Repeating commands!
  • Over and over again!
  • Pretty cool and powerful feature of Vim!
  • Why descriptions?