Policies and Principles Part I Recurring Themes Annoucements - - PowerPoint PPT Presentation
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
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 resolving
ambiguity...
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...
- Relative jumps
- Modal Editing and Principles
- "Unix Standards"
- Relative jumps
- Modal Editing and Principles
- "Unix Standards"
Relative Jumps
Relative Jumps
Misspelled words are hard to describe!
Relative Jumps
Misspelled words are hard to describe! "Misspelled" is not a very good description, from Vim's standpoint!
Relative Jumps
Misspelled words are hard to describe! "Misspelled" is not a very good description, from Vim's standpoint!
Relative Jumps
Relative Jumps
Um...
It is pretty much unreadable as it is....
Relative Jumps
Um...
It is pretty much unreadable as it is....
Nearly impossible to describe/read!
Relative Jumps
- Relative jumps deals with the special
case that some objects are inherently hard to describe!
Relative Jumps
- Relative jumps deals with the special
case that some objects are inherently hard to describe!
- ex. perl oneliners, regular expressions,
typos, etc...
Relative Jumps
- What this means: Don't abuse it!!!
- Many people use them for very very
very very bad reasons...
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>
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...)
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.
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?
Relative Jumps
Well, it's the regex that I am grepping for!
Relative Jumps
Well, it's the regex that I am grepping for! /grep<CR> -- Locate a grep call
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.
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!!
Relative Jumps
/grep<CR> -- Locate a grep call f/ -- Jump to the regex relative to that grep call.
Relative Jumps
/grep<CR> -- Locate a grep call f/ -- Jump to the regex relative to that grep call. Locates any grep call!
Relative Jumps
/grep<CR> -- Locate a grep call f/ -- Jump to the regex relative to that grep call. /author<CR> -- Locate author block
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.
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.
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!
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
Common Jumps
- One word/WORD jumps (rarely used,
sometimes known as motions): w Jump to next word b Jump to previous word
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)
Relative Jumps
- Again, use it only when needed!
- Often used as a combination of:
/<pattern><CR> f<char> <some other precise close jumps>
- Relative jumps
- Modal Editing and Principles
- "Unix Standards"
- Relative jumps
- Modal Editing and Principles
- (actually)
- "Unix Standards"
Modal Editing
- So we've talked about locating...
Modal Editing
- So we've talked about locating...
- When we're typing, we want to be able
to type every single character...
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!
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...
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...
Modal Editing
- Before that...
- Myth #3: In Vim, you are almost always
in Normal Mode.
Modal Editing
- Before that...
- Myth #3: In Vim, you are almost always
in Normal Mode.
- This is highly misleading! (albeit well-
intentioned)
Modal Editing
Modal Editing
Um, don't have any text to actually 'edit'.
Modal Editing
- When using Vim, there are different
phases:
- Drafting
- Skimming
- Editing
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
Modal Editing
- When using Vim, there are different
phases:
- Drafting
- Skimming
– Reading through existing text
Modal Editing
- When using Vim, there are different
phases:
- Drafting
- Skimming
- Editing
– Manipulating or correcting existing text
Modal Editing
- When using Vim, there are different
phases:
- Drafting
- Skimming
- Editing
- So what does this have to do with
modes?
Insert Mode
Insert Mode
Insert Mode
- Well, we have to be able to type every
character...
- Hence, insert mode is the mode for
typing every character!
Insert Mode
- What this means:
– All keyboard characters behave as you would expect... (ex. 'i' just enters the character i, etc.)
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!
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.
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...)
Insert Mode
Well, most keys are mapped to some print character that we have to type...
Insert Mode
Well, most keys are mapped to some print character that we have to type...
That one nonprintable character on the keyboard!
Insert Mode
- Hence, all commands in insert mode are
prefixed with <C->.
- Which is why there are so few of
them...
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)
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)
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)
Insert Mode
Modal Editing
- Myth #3: In Vim, you are almost always
in Normal Mode.
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!
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!
Modal Editing
- When using Vim, there are different
phases:
- Drafting -- almost always in insert mode
- Skimming
- Editing
Modal Editing
- When using Vim, there are different
phases:
- Drafting -- almost always in insert mode
- Skimming
- Editing
Skimming
- When you just want to skim/read the
content of the file, you probably don't want to make modifications...
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...
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!
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!
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!
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
Normal Mode
Window and Cursor Policy
- Vim's cursor and screen behaves very
differently from other editors.
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)
Window and Cursor Policy
- What this means:
- skimming -- view -- screen
- editing -- edit -- cursor
Window and Cursor Policy
- What this means:
- skimming -- view -- screen
- editing -- edit -- cursor
- Implication: you use different
commands in different phases!
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! :(
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! :(
Modal Editing
- When using Vim, there are different
phases:
- Drafting -- almost always in insert mode
- Skimming -- always in normal mode
- Editing
Modal Editing
- When using Vim, there are different
phases:
- Drafting -- almost always in insert mode
- Skimming -- always in normal mode
- Editing
Editing
- Complication:
– Want to be able to type every character – Want to have not completely terrible ergonomics for editing commands as well....
Editing
- Complication:
– Want to be able to type every character – Want to have not completely terrible ergonomics for editing commands as well....
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.
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....
Editing
- Example:
ciw lol ???
Editing
- Example:
ciw change current word (while in normal mode), then jumps into insert mode. lol ???
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) ???
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) ???
Editing
- Complication: you want to continue
editing by using normal mode commands....
Editing
- Complication: you want to continue
editing by using normal mode commands....
- But, you are currently in insert mode...
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!
'Escape' command
<Esc>
Editing
- Has debatable ergonomics...
- You may choose to remap this key in the
future...
- Specialized purpose: escaping from
insert mode to normal mode!
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!
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
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!
Next time
- Repeating commands!
- Over and over again!
- Pretty cool and powerful feature of Vim!
- Why descriptions?