Lecture 1: The Vim Philosophy Part I Recurring Themes A bit more - - PowerPoint PPT Presentation

lecture 1 the vim philosophy
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1

Lecture 1: The Vim Philosophy

Part I Recurring Themes

slide-2
SLIDE 2
  • A bit more stuff...
  • File Explorers: locating a file
  • Vim Philosophy Rule I
  • Available commands
slide-3
SLIDE 3
  • A bit more stuff...
  • File Explorers: locating a file
  • Vim Philosophy Rule I
  • Available commands
slide-4
SLIDE 4

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

slide-5
SLIDE 5

From Last Time

slide-6
SLIDE 6

From Last Time

slide-7
SLIDE 7

More on Ergonomics

  • There's another reason why we need

good ergonomics:

slide-8
SLIDE 8

More on Ergonomics

  • There's another reason why we need

good ergonomics:

  • Fact: Ergonomics determines speed, not

the number of keystrokes...

slide-9
SLIDE 9

Myth #1

  • People use Vim because it can

accomplish tasks with the least amount

  • f keystrokes.
slide-10
SLIDE 10

Myth #1

  • People use Vim because it can

accomplish tasks with the least amount

  • f keystrokes.
slide-11
SLIDE 11

Myth #1

  • People use Vim because it can

accomplish tasks with the least amount

  • f keystrokes.
slide-12
SLIDE 12

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.

slide-13
SLIDE 13

Conventions

  • We have three emphasis on commands

for this course:

  • 1. Clarity
  • 2. Ergonomics
  • 3. Keystrokes
slide-14
SLIDE 14

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)

slide-15
SLIDE 15

Commands

Tapping the 'g' key on keyboard twice consecutively: Write As: gg Pronounced As: "gee-gee" Keycount: 2

slide-16
SLIDE 16

Commands

Tapping Enter: <CR> "Enter" or "Carriage Return" 1 (all these conventions would be clear when we get to vimscripting)

slide-17
SLIDE 17

Commands

Holding down Control and tapping d: <C-d> "Control d" 2

slide-18
SLIDE 18

Commands

Holding down Shift and tapping g: G "Shift g" 2

slide-19
SLIDE 19

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!

slide-20
SLIDE 20

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" ?

slide-21
SLIDE 21

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

slide-22
SLIDE 22

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!

slide-23
SLIDE 23

Commands

Holding down Shift and tapping '4': $ "Dollar" or "Shift Dollar" 2

slide-24
SLIDE 24

Commands

Holding down Shift and tapping ';': : "Colon" 1 Special case, since we'll be using it quite

  • ften.
slide-25
SLIDE 25

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.

slide-26
SLIDE 26

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.

slide-27
SLIDE 27

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.
slide-28
SLIDE 28

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.

slide-29
SLIDE 29

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...
slide-30
SLIDE 30

Quick demo of the Vim Philosophy

(in a few minutes) demo.txt

slide-31
SLIDE 31
  • A bit more stuff...
  • File Explorers: locating a file
  • Vim Philosophy Rule I
  • Available commands
slide-32
SLIDE 32

Case Study: Locating a File

  • Suppose I have a file:

~/vimcourse/demo/lecture1/ puppies/chad.txt

  • and I want to locate it.
slide-33
SLIDE 33

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?
slide-34
SLIDE 34

Well?

slide-35
SLIDE 35

File Explorers

slide-36
SLIDE 36

File Explorers

slide-37
SLIDE 37

File Explorers

slide-38
SLIDE 38

File Explorers

Suppose we are in the puppies directory...

slide-39
SLIDE 39

File Explorers

Suppose we are in the puppies directory...

slide-40
SLIDE 40

File Explorers

eh...

slide-41
SLIDE 41

File Explorers

eh...

slide-42
SLIDE 42

File Explorers

eh...

slide-43
SLIDE 43

File Explorers

Sort and Binary Search!

slide-44
SLIDE 44

File Explorers

  • So what if I wanna find a file in /bin?
  • This would happen...
slide-45
SLIDE 45

File Explorers

slide-46
SLIDE 46

File Explorers

slide-47
SLIDE 47

File Explorers

slide-48
SLIDE 48

File Explorers

slide-49
SLIDE 49

File Explorers

slide-50
SLIDE 50

File Explorers

slide-51
SLIDE 51

File Explorers

slide-52
SLIDE 52

File Explorers

slide-53
SLIDE 53

File Explorers

slide-54
SLIDE 54

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.

...

slide-55
SLIDE 55

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.

slide-56
SLIDE 56

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...

slide-57
SLIDE 57

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...

slide-58
SLIDE 58

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/...

slide-59
SLIDE 59

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?

slide-60
SLIDE 60

The Locating Process

  • I know the file is in:

~/vimcourse/demo/lecture1/puppies/chad .txt

slide-61
SLIDE 61

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

slide-62
SLIDE 62

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!

slide-63
SLIDE 63

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).

slide-64
SLIDE 64

The Locating Process

https://xkcd.com/378/

slide-65
SLIDE 65

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.
slide-66
SLIDE 66

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?
slide-67
SLIDE 67

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...

slide-68
SLIDE 68

In a Text Editor

slide-69
SLIDE 69

In a Text Editor

slide-70
SLIDE 70

In a Text Editor

slide-71
SLIDE 71

Two Steps

  • Step 1: Locate.
  • Step 2: Edit.
slide-72
SLIDE 72

Three Steps

  • Step 1: Locate.
  • Step 2: Edit.
  • Step 3: ???
slide-73
SLIDE 73

Three Steps

  • Step 1: Locate.
  • Step 2: Edit.
  • Step 3: ??? (PROFIT!!)

not really...

slide-74
SLIDE 74

In a Text Editor

So I've seen it...

slide-75
SLIDE 75

In a Text Editor

So I've seen it... goto or cd command?

slide-76
SLIDE 76

In Vim

slide-77
SLIDE 77

In Vim

  • Yup, there is such a command!
  • THE most frequent command you'll use

for the course. /<pattern><CR>

slide-78
SLIDE 78

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...)

slide-79
SLIDE 79
  • A bit more stuff...
  • File Explorers: locating a file
  • Vim Philosophy Rule I
  • Available commands
slide-80
SLIDE 80

The Vim Philosophy

  • To sum it up:

DESCRIBE, don't EXPLAIN

slide-81
SLIDE 81

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.

slide-82
SLIDE 82

The Vim Philosophy

  • To sum it up:

DESCRIBE, don't EXPLAIN

Vim figures out HOW to do it!

slide-83
SLIDE 83

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!

slide-84
SLIDE 84

So what can we do in Vim?

What kind of high level descriptions can we use?

slide-85
SLIDE 85
  • 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)

slide-86
SLIDE 86

Two Steps

  • Step 1: Locate. (What I'm going to edit)
  • Step 2: Edit. (What do I do to it?)
slide-87
SLIDE 87

Two Steps

  • Step 1: Locate. (What I'm going to edit)
  • Step 2: Edit. (What do I do to it?)

DESCRIBE, don't EXPLAIN!

slide-88
SLIDE 88

Locate Commands

/<pattern><CR> Goto <somewhere> Locate some text with that pattern.

  • Ex. /cause<CR>

Meaning: Locate the word cause.

DESCRIBE, don't EXPLAIN!

slide-89
SLIDE 89

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!

slide-90
SLIDE 90

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!

slide-91
SLIDE 91

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!

slide-92
SLIDE 92

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!

slide-93
SLIDE 93

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!

slide-94
SLIDE 94

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

Explain!