Lecture 1: The Vim Philosophy Part I Recurring Themes A bit more - - PowerPoint PPT Presentation
Lecture 1: The Vim Philosophy Part I Recurring Themes A bit more - - PowerPoint PPT Presentation
Lecture 1: The Vim Philosophy Part I Recurring Themes A bit more stuff... File Explorers: locating a file Vim Philosophy Rule I Available commands A bit more stuff... File Explorers: locating a file Vim Philosophy Rule I
- A bit more stuff...
- File Explorers: locating a file
- Vim Philosophy Rule I
- Available commands
- A bit more stuff...
- File Explorers: locating a file
- Vim Philosophy Rule I
- Available commands
From Last Time
- Setup Vim (don't worry if you haven't
done it yet, we won't be actually using Vim until much much later)
- Remapped Caps Lock key, discussed
ergonomics
From Last Time
From Last Time
More on Ergonomics
- There's another reason why we need
good ergonomics:
More on Ergonomics
- There's another reason why we need
good ergonomics:
- Fact: Ergonomics determines speed, not
the number of keystrokes...
Myth #1
- People use Vim because it can
accomplish tasks with the least amount
- f keystrokes.
Myth #1
- People use Vim because it can
accomplish tasks with the least amount
- f keystrokes.
Myth #1
- People use Vim because it can
accomplish tasks with the least amount
- f keystrokes.
Myth #1
- People use Vim because it can
accomplish tasks with the least amount
- f keystrokes.
- This is also a misunderstanding... We'll
get to that today.
Conventions
- We have three emphasis on commands
for this course:
- 1. Clarity
- 2. Ergonomics
- 3. Keystrokes
Conventions
- We have three "emphasis" on commands
for this course:
- 1. Clarity
- 2. Ergonomics
- 3. Keystrokes (we don't care that much)
Keystrokes are good indicators of ergonomics! (kinda)
Commands
Tapping the 'g' key on keyboard twice consecutively: Write As: gg Pronounced As: "gee-gee" Keycount: 2
Commands
Tapping Enter: <CR> "Enter" or "Carriage Return" 1 (all these conventions would be clear when we get to vimscripting)
Commands
Holding down Control and tapping d: <C-d> "Control d" 2
Commands
Holding down Shift and tapping g: G "Shift g" 2
Commands
For nicer formatting, sometimes we will write: qa 0w ciw lol <Esc> q For nicer formatting. Note that there are no newlines unless <CR> explicitly stated!
Commands
Holding down Control and tapping x then o (while holding down control) <C-x><C-o> "Control x o" or "Control x Control o" ?
Commands
Holding down Control and tapping x then o (while holding down control) <C-x><C-o> "Control x o" or "Control x Control o" 3
Commands
Holding down Control and tapping x then o (while holding down control) <C-x><C-o> "Control x o" or "Control x Control o" 3 Remember: in this course, keystrokes are indicators of ergonomics, not how unix parses them!
Commands
Holding down Shift and tapping '4': $ "Dollar" or "Shift Dollar" 2
Commands
Holding down Shift and tapping ';': : "Colon" 1 Special case, since we'll be using it quite
- ften.
Commands
Holding down Control and tapping '[': <C-[> or <Esc> "Escape" 1 Again, 1 of the 2 special cases. We will talk about "unix standards" in the second part of the course.
A few more things about commands
- Treat commands as something you want
to memorize as "finger memory" (through practice).
- Don't use memonics!
- Same reason why you don't use
memonics to remember key locations on a keyboard.
A few more things about commands
- For the first few weeks we won't be
using commands (even though we'll very very briefly mention them), so don't worry too much about them now.
- The midterm will NOT require you to
memorize commands (generally).
- The final will.
Side note about .vimrc
- For this course, we will build our .vimrc
file from scratch.
- By convention, .vimrc is the
settings/resource file for vim.
- The .vim directory is for plugins,
addons, colors, syntax files etc. We won't get to that till much later.
For today...
- We will not talk about editing in the
context of code!
- (we will spend the entirety of next
lecture on it, since it starts getting tricky)
- We will talk about editing in the context
- f structured text...
Quick demo of the Vim Philosophy
(in a few minutes) demo.txt
- A bit more stuff...
- File Explorers: locating a file
- Vim Philosophy Rule I
- Available commands
Case Study: Locating a File
- Suppose I have a file:
~/vimcourse/demo/lecture1/ puppies/chad.txt
- and I want to locate it.
Case Study: Locating a File
- Suppose I have a file:
~/vimcourse/demo/lecture1/ puppies/chad.txt
- and I want to locate it.
- So how would you do it?
Well?
File Explorers
File Explorers
File Explorers
File Explorers
Suppose we are in the puppies directory...
File Explorers
Suppose we are in the puppies directory...
File Explorers
eh...
File Explorers
eh...
File Explorers
eh...
File Explorers
Sort and Binary Search!
File Explorers
- So what if I wanna find a file in /bin?
- This would happen...
File Explorers
File Explorers
File Explorers
File Explorers
File Explorers
File Explorers
File Explorers
File Explorers
File Explorers
The Locating Process
Find ~/vimcourse/demo/lecture1/puppies/chad.txt Asks file manager to give the directory list for ~ Reads the directory list Asks the file manager to sort it Finds it through binary search Click on it.
...
The Locating Process
... Filemanager: Ohh you wanna to go to the directory 'vimcourse'. Okay, I'll take you there, Goes into the directory. Rinse and repeat. Find the file.
The Locating Process
... Filemanager: Ohh you wanna to go to the directory 'vimcourse'. Okay, I'll take you there, Goes into the directory. Rinse and repeat. Find the file.
Wait a sec...
The Locating Process
... Filemanager: Ohh you wanna to go to the directory 'vimcourse'. Okay, I'll take you there, Goes into the directory. Rinse and repeat. Find the file.
Wait a sec...
The Locating Process
... Filemanager: Ohh you wanna to go to the directory 'vimcourse'. Okay, I'll take you there, Goes into the directory. Rinse and repeat. Find the file.
I know that file is in: ~/vimcourse/demo/...
The Locating Process
... Filemanager: Ohh you wanna to go to the directory 'vimcourse'. Okay, I'll take you there, Goes into the directory. Rinse and repeat. Find the file.
Why am I searching for it again?
The Locating Process
- I know the file is in:
~/vimcourse/demo/lecture1/puppies/chad .txt
The Locating Process
- I know the file is in:
~/vimcourse/demo/lecture1/puppies/chad .txt
- I know a command for jumping straight
into the directory: cd
The Locating Process
- I know the file is in:
~/vimcourse/demo/lecture1/puppies/chad .txt
- I know a command for jumping straight
into the directory: cd
- It makes NO sense to SEARCH for it
again!
The Locating Process
- To put it another way:
- I know the file is in that directory,
- But I don't care HOW I get into that
directory!
- I am not responsible for finding the
file, the computer is (and handling even lower level stuff).
The Locating Process
https://xkcd.com/378/
Moral of the Story
- Locating Files is not a FPS game.
- You don't find, target and shoot.
- You go straight into it.
- Doing it >>>> Searching it, Finding it.
Moral of the Story
- Locating Files is not a FPS game.
- You don't find, target and shoot.
- You go straight into it.
- Doing it >>>> Searching it, Finding it.
- Why do we care?
Moral of the Story
- Locating Files is not a FPS game.
- You don't find, target and shoot.
- You go straight into it.
- Doing it >>>> Searching it, Finding it.
- Why do we care?
Foreshadowing 10 lectures later...
In a Text Editor
In a Text Editor
In a Text Editor
Two Steps
- Step 1: Locate.
- Step 2: Edit.
Three Steps
- Step 1: Locate.
- Step 2: Edit.
- Step 3: ???
Three Steps
- Step 1: Locate.
- Step 2: Edit.
- Step 3: ??? (PROFIT!!)
not really...
In a Text Editor
So I've seen it...
In a Text Editor
So I've seen it... goto or cd command?
In Vim
In Vim
- Yup, there is such a command!
- THE most frequent command you'll use
for the course. /<pattern><CR>
In Vim
- Yup, there is such a command!
- THE most frequent command you'll use
for the course. /<pattern><CR>
- (but not quite actually... there are many complications,
we'll talk about them next lecture...)
- A bit more stuff...
- File Explorers: locating a file
- Vim Philosophy Rule I
- Available commands
The Vim Philosophy
- To sum it up:
DESCRIBE, don't EXPLAIN
The Vim Philosophy
- To sum it up:
DESCRIBE, don't EXPLAIN
Tell Vim WHAT you want to do...
Say, change one piece of text to another, reformat some pieces of text, realign code, change variable names, etc.
The Vim Philosophy
- To sum it up:
DESCRIBE, don't EXPLAIN
Vim figures out HOW to do it!
The Vim Philosophy
- To sum it up:
DESCRIBE, don't EXPLAIN
- You are expected to follow this basic
philosophy at all times in this course!
So what can we do in Vim?
What kind of high level descriptions can we use?
- A bit more stuff...
- File Explorers: locating a file
- Vim Philosophy Rule I
- Available commands
Don't worry what the commands are, think about what they mean! (hence, descriptions)
Two Steps
- Step 1: Locate. (What I'm going to edit)
- Step 2: Edit. (What do I do to it?)
Two Steps
- Step 1: Locate. (What I'm going to edit)
- Step 2: Edit. (What do I do to it?)
DESCRIBE, don't EXPLAIN!
Locate Commands
/<pattern><CR> Goto <somewhere> Locate some text with that pattern.
- Ex. /cause<CR>
Meaning: Locate the word cause.
DESCRIBE, don't EXPLAIN!
Edit Commands
c<text object> Change to... Change a certain object to something else.
- Ex. /cause<CR>
ciw lol Meaning: Locate the word 'cause' and change it to the word 'lol'. Succinctly: Change the word 'cause' to 'lol'. DESCRIBE, don't EXPLAIN!
Edit Commands
d<text object> Delete object Delete a certain object.
- Ex. /cause<CR>
daw Meaning: Locate the word cause and delete it. Succinctly: Delete the word 'cause'.
DESCRIBE, don't EXPLAIN!
Edit Commands
ea Append at the end of current word.
- Ex. /cause<CR>
ea d Meaning: Locate the word cause and append 'd' to the end of that word. Succinctly: Change the word 'cause' to 'caused', OR Change 'cause' to past tense by appending a 'd'. DESCRIBE, don't EXPLAIN!
Edit Commands
<C-a> Increment the next number. <C-x> Decrement the next number.
- Ex. /costs<CR>
<C-a> Meaning: Locate the word costs and increment the first number after that. Succinctly: Increment the cost. DESCRIBE, don't EXPLAIN!
Edit Commands
I In front of the line, insert... A At the end of the line, append...
- Ex. /costs<CR>
I P.S. Meaning: In front of the line containing the word 'costs', insert the phrase 'P.S.'
Succinctly: Make the line about costs a P.S.. (This is a little bit too high level , please don't do this in hws)
DESCRIBE, don't EXPLAIN!
Next Time
- What happens when we deal with code?
- (Hint: some of what we talked about
starts breaking down, and we'll fix it)
- Try to make this mental switch in your
- head. Remember: Describe, don't