Lecture 2: Vim's Giant Flaw Part I Recurring Themes Annoucements - - PowerPoint PPT Presentation
Lecture 2: Vim's Giant Flaw Part I Recurring Themes Annoucements - - PowerPoint PPT Presentation
Lecture 2: Vim's Giant Flaw Part I Recurring Themes Annoucements Homework 1 will be out by tonight! Covers everything up to and including this lecture. No commands will be covered (as usual), we will get to that in the second part of
Annoucements
- Homework 1 will be out by tonight!
- Covers everything up to and including this
lecture.
- No commands will be covered (as usual), we
will get to that in the second part of the course.
- Due by the beginning of next lecture. Print.
Last Time
- The Vim Philosophy!
- Why file explorers are usually bad.
- Describe, don't Explain!
Last Time
- The Vim Philosophy!
- Why file explorers are usually bad.
- Describe, don't Explain!
- What happens when we are dealing with
code?
- A few loose ends...
- Ambiguity
- Ways to resolve it
- A few loose ends...
- Ambiguity
- Ways to resolve it
Relative Line Numbers ... are BAD
- vimtutor
- 10j
- 4w
- <number>command
- Also referred to as counts.
Relative Line Numbers ... are BAD
Relative Line Numbers ... are BAD
Relative Line Numbers ... are BAD
Relative Line Numbers ... are BAD
Um...
Relative Line Numbers ... are BAD
Um... 18 words?
Relative Line Numbers ... are BAD
Um... 18 words?
18w
Relative Line Numbers ... are BAD
Um... 18 words?
18w
Relative Numbers ... are BAD
I want to locate the 'std' after namespace. Okay, so I'm at the top of the code, and the word 'std' is 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18 words away... Okay, so 18w. Vim: so I can count 1, 2, 3, .. 18, words away from now, so that's the 'std' after namespace, ohhhh.... Move cursor to the 'std' after 'namespace'...
Relative Numbers ... are BAD
I want to locate the 'std' after namespace. Okay, so I'm at the top of the code, and the word 'std' is 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18 words away... Okay, so 18w. Vim: so I can count 1, 2, 3, .. 18, words away from now, so that's the 'std' after namespace, ohhhh.... Move cursor to the 'std' after 'namespace'...
Relative Numbers ... are BAD
- But hey, I do know how to locate to the
'std' after 'namespace'....
Relative Numbers ... are BAD
- But hey, I do know how to locate to the
'std' after 'namespace'....
- goto 'std' after 'namespace'.
Relative Numbers ... are BAD
- But hey, I do know how to locate to the 'std'
after 'namespace'....
- goto 'std' after 'namespace'.
/namespace<CR>/std<CR>
Relative Numbers ... are BAD
- But hey, I do know how to locate to the 'std'
after 'namespace'....
- goto 'std' after 'namespace'.
/namespace<CR>/std<CR>
- Moral of the story? Don't make life
unneccesarily hard for yourself! Describe, don't Explain!
Relative Numbers ... are BAD
- vimtutor is bad!
- Rule of thumb for relative numbers:
Relative Numbers ... are BAD
- vimtutor is bad!
- Rule of thumb for relative numbers:
DON'T
Relative Numbers ... are BAD
- vimtutor is bad!
- Rule of thumb for relative numbers:
DON'T
(BUT, you'll see it in one of the homeworks... There are actual uses for it.)
"Arrow Keys"
- Same principles apply!
"Arrow Keys"
- Same principles apply!
- Myth #2: In Vim, you don't use the
arrow keys, you use the "hjkl" keys.
"Arrow Keys"
- Same principles apply!
- Myth #2: In Vim, you don't use the
arrow keys, you use the "hjkl" keys.
"Arrow Keys"
- Same principles apply!
- Myth #2: In Vim, you don't use the
arrow keys, you use the "hjkl" keys.
"Arrow Keys"
- Same principles apply!
- Myth #2: In Vim, you don't use the
arrow keys, you use the "hjkl" keys.
- They are no different from the arrow
keys!
"Arrow Keys"
- Same principles apply!
- Myth #2: In Vim, you don't use the arrow
keys, you use the "hjkl" keys.
- They are no different from the arrow keys!
- In fact, in this course, we call them "arrow
keys"!
More about File Explorers...
- Again, suppose we want to navigate to:
~/vimcourse/demo/lecture1/puppies/chad .txt
- In reality, you'll probably won't
remember the file location that accurately....
More about File Explorers...
- Ideally, we remember:
More about File Explorers...
- Ideally, we remember:
- In reality:
More about File Explorers...
- So it's some file (hopefully) named
something memorable...
- The path to it, on the other hand, may
not be that distinctive...
- <something
something>/puppies/chad.txt
More about File Explorers...
- So it's some file (hopefully) named
something memorable...
- The path to it, on the other hand, may
not be that distinctive...
- **/*/puppies/chad.txt
More about File Explorers...
- Tab Completion!
- something about a vimcourse...
More about File Explorers...
- Tab Completion!
- something about a vimcourse...
- cd
- vim<Tab>
More about File Explorers...
- Tab Completion!
- something about a vimcourse...
- cd
- vim<Tab>
- OR, *course<Tab> (globbing)
Key Placement
Fuzzy is Good!
- We don't have to even remember
everything to describe it!
- A fuzzy description would do.
Fuzzy is Good!
- We don't have to even remember
everything to describe it!
- A fuzzy description would do.
- I want the filename that looks like this:
Fuzzy is Good!
- We don't have to even remember
everything to describe it!
- A fuzzy description would do.
- I don't have to describe everything in
the path! (foreshadowing 10ish lectures later...)
Fuzzy is Good!
Fuzzy is Good!
Fuzzy is Good!
Fuzzy is Good!
/cause<CR>
Fuzzy is Good!
/ca<CR>
Sufficient Description to locate 'cause'!
.vimrc
- However, Vim default settings are not
very friendly...
- To change this, we will have to modify
- ur .vimrc file.
- Located in: ~/.vimrc ($HOME/.vimrc)
- (As of now, I recommend not using Vim
to modify it yet... Copy-Paste from course website)
.vimrc
.vimrc
- Uses a language called "vimscript".
- (Used to be called VimL).
.vimrc
- Uses a language called "vimscript".
- (Used to be called VimL).
- Terrible Terrible Language... But for
the purposes of the course, we'll focus
- n the less terrible parts...
.vimrc
- In this course, we'll treat vimscript and
ex commands as the same thing...
- What this means.. (demo)
.vimrc
- Setting options (the skinny)
- set <option>
- Ex.
- set linebreak
- set hlsearch
.vimrc
- Setting options
- set <option name>
- <option name> is a boolean option (we'll
see other options in the future)...
- sets <option name> to True/Yes
.vimrc
- Setting (Enabling) options
- set <option name>
- Ex.
- set ignorecase
- " Ignores case
.vimrc
- Setting (Disabling) options
- set no<option name>
- (simply prepend 'no' in front of option
name)
- Ex.
- set noignorecase
- " Does not ignore case
.vimrc
- Setting (Querying) options
- set <option name>?
- (simply append '?' in front of option
name)
- Ex.
- set ignorecase?
- " If it ignores case
.vimrc
- Setting (Flipping) options (uncommonly used)
- set <option name>!
- (simply append '!' in front of option name)
- Ex.
- set ignorecase!
- " True -> False, False -> True
.vimrc
- There is reference for what options do,
within vim itself!
- Vim Help:
- :h '<option name>'<CR>
- Vim Docs.
.vimrc
.vimrc
.vimrc
.vimrc
- nocompatible
- Removes compatibility for vi.
- (Because we are using Vim, vi defaults
are pretty bad, and it lacks many very important features.)
.vimrc
- nohlsearch
- Disables search higlighting.
- Thus, it won't show every single match
when we use the /<pattern><CR> command, as it gets very annoying.
.vimrc
- incsearch
- Incremental Search.
- Visual feedback for locating.
.vimrc
- incsearch
- Incremental Search.
- Visual feedback for locating.
- This is how you know that your fuzzy
description is sufficient!
.vimrc
- ignorecase
- Ignores case when searching...
- Don't want to bother with annoying
caps.
.vimrc
- smartcase
- With 'ignorecase', it also enables casing
when you type caps (hence when you really care about casing).
Back to our regularly scheduled Vimming...
Fuzzy is Good!
/ca<CR>
Sufficient Description to locate 'cause'!
Fuzzy is Good!
Fuzzy is Good!
- Hence, simply sufficient details would
be enough to locate!
- Faster and more convenient.
/ca<CR> Keycount: 4
Fuzzy is Good!
- Hence, simply sufficient details would
be enough to locate!
- Faster and more convenient.
/ca<CR> Keycount: 4
- Could we run into trouble?
- A few loose ends...
- Ambiguity
- Ways to resolve it
Fuzzy is Good?
/cau<CR>
Sufficient Description to locate 'cause'!
Fuzzy is Good?
- Note that this is NOT an ambiguous
command!
- hlsearch.
- /cau<CR> uniquely identifies 'cause' as
the word you want to edit.
Fuzzy is Good?
- But if we are lazy:
/ca<CR>
- it would be ambiguous! (demo hlsearch)
- Question: What could go wrong?
Fuzzy is Good?
Fuzzy is Good?
Fuzzy is Good?
goto for loop
Fuzzy is Good?
goto for loop /for<CR>
What could go wrong?
Fuzzy is Good?
goto for loop /for<CR>
What could go wrong?
Code has repetition!
Fuzzy is Good?
From Vim's Perspective
Fuzzy is Good?
From Vim's Perspective
Fuzzy is Good?
Fuzzy is Good?
I want to locate that for loop
Fuzzy is Good?
Which for loop????
Fuzzy is Good?
Which for loop????
Fuzzy is Good?
Which for loop????
Ambiguity!!
Fuzzy is Good?
Which for loop????
Ambiguity!!
There is more than one way to interpret a description.
Fuzzy is Good?
Which for loop????
Ambiguity!!
There is more than one way to interpret a description.
Conventions (from last time)
- We have three emphasis on commands
for this course:
- 1. Clarity (no ambiguity!)
- 2. Ergonomics
- 3. Keystrokes
Conventions (from last time)
- We have three emphasis on commands
for this course:
- 1. Clarity (no ambiguity!)
- 2. Ergonomics
- 3. Keystrokes
So how do we deal with it?
- A few loose ends...
- Ambiguity
- Ways to resolve it
Resolving Ambiguity
(In decreasing use case):
- 1. Cheating
- 2. Distinctive features
- 3. Relative jumps
Cheating
Well, it's one of them...
Cheating
Well, it's one of them...
Keep trying until you get to it!!
Cheating
Emphasizing the idea that: "Well, my description is somewhat clear... So there wouldn't be that much ambiguity!"
Cheating
- By default, /<pattern><CR> command
finds the next closest match.
Cheating
- By default, /<pattern><CR> command
finds the next closest match. n
- Finds the next match
N
- Finds the previous match
Cheating
- Note: most of the time, we cheat
because Vim matches things that we don't expect/know. (or we are unfamilar with the language)
- Demo (trouble.cpp)
Cheating
- Note: most of the time, we cheat
because Vim matches things that we don't expect/know.
- Demo (trouble.cpp)
- For beginners, try to match distinctive
features instead, until writing descriptions (in some language) become natural....
Distinctive features
Okay, these are for loops
What makes it different?
Distinctive features
Distinctive features
We defined the variable 'j' as the loop variable!
Distinctive features
We defined the variable 'j' as the loop variable! /int j<CR>
Distinctive features
- This is the recommended way to resolve
ambiguity!
- The reason for this is that ambiguity
arises from imprecise or too-general descriptions.
Distinctive features
- This is the recommended way to resolve
ambiguity!
- The reason for this is that ambiguity
arises from imprecise or too-general descriptions.
- (There is probably more than one for
loop in a program!)
Distinctive features
- However, it is less commonly used than
cheating... (why?)
Distinctive features
- However, it is less commonly used than
cheating... (why?)
- Reason: you need to cheat when you
screw up... sometimes you screw up, and it's not worth the time relocating!
Distinctive features
- However, it is less commonly used than
cheating... (why?)
- Reason: you need to cheat when you
screw up... sometimes you screw up, and it's not worth the time relocating!
Next Time
- More ways to resolve ambiguity!
- Modal Editing and its principles and policies.
- Unix and Conflicting Principles.
- Homework 1 is out! Due next week.
- Think about ambiguity! It's probably the most
annoying part of editing.
- Practice coming up with clear descriptions.
- Review setting boolean options in vimscript.