98-277: The Vim Editor: Philosophy, Principles and Practice

Post on 14-Feb-2017

225 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

Transcript

98-277: The Vim Editor: Philosophy, Principles and Practice

Lecture 0: Welcome & Conventions

(Hence, not much of meat, but a lot to know)

Announcements

• There will be no class next Monday!

• (Labour day!)

• Go out and have fun!

Course Website

http://andrew.cmu.edu/~haoxuany/vim

Props to Andrew Benson(adbenson) for creating the amazingly beautiful CSS!!!

:)

Poll the website for homeworks and announcements!

• Course Logistics :(

• A Bit of Foreshadowing...

• Installing Vim

• Keyboard Ergonomics

• Course Logistics :(

• A Bit of Foreshadowing...

• Installing Vim

• Keyboard Ergonomics

whoami

• Haoxuan "Aaron" Yue (Plz call me Aaron)

• haoxuany@andrew.cmu.edu

• School of Computer Science, Class of 2018

• Started using Vim rougly 6+ years ago

• Thought it was awful, was miserable (but we'll talk about it later...)

• Use Vim exclusively for text editing now

This is me!

http://abstrusegoose.com/354

Before that...

This is a StuCo course!!!

Meaning...

• You are REQUIRED to attend class!

• More specifically, you are not allowed to miss more than 2 classes. (StuCo policy)

• (If there are documented illnesses, emergency situations, university bussiness etc., email me or talk to me preferably BEFORE it happens)

Meaning...

• Def Missing Class: Not coming, Tardiness (miss more than 15 minutes of class).

• To enforce that, you are REQUIRED to sign an attendence sheet (during class)

• Please remember to do that!! It's hard to verify attendence if you don't.

Grading

• Aside from attendance...

• 40% Homeworks

• 5 homeworks in total (each 8%).

• PRINT, finish, and hand it in the next class after it is assigned.

• Unless in special circumstances, will not accept late homework.

Homework

• Roughly 3 problems each.• 1st problem is basically lecture material.• Recommend doing without referencing the

lecture notes.• (*May* show up on exams *hint hint*).

• Other problems extend the discussion in lecture.

• Please do them! Very few resources out there cover these (will talk about that later).

Grading

• 30% Midterm

• 30% Finals

• Midterm will NOT be curved. Finals may be.

• Midterm will not cover commands (generally), hence understand, don't memorize.

• Final will cover nearly all commands in lecture!

• Passing requires 60% (under consideration...)

Grading

• On a side note

• It shouldn't be a tough course!

• Please do all the homeworks!

• Pay attention in lecture, since the material is very different from others...

• Which brings us to...

• Course Logistics :(

• A Bit of Foreshadowing...

• Installing Vim

• Keyboard Ergonomics

• Course Logistics :(

• A Bit of Foreshadowing...

• Installing Vim

• Keyboard Ergonomics

Yay! :D

What is Vim?

• Vim is a text editor.

What is Vim?

• Vim is a text editor.

•This is actually true.• Moreover, Vim is a text editor specially

designed for programmers. (Especially C-style programmers, but also works pretty well with other languages).

A bit more about me...

• 14 slides ago: "Started using Vim rougly 6+ years ago"

• Emphasis on the word *started*

• Then I quit...

A bit more about me...

• 15 slides ago: "Started using Vim rougly 6+ years ago"

• Emphasis on the word *started*

• Then I ragequit...

A bit more about me...

• 16 slides ago: "Started using Vim rougly 6+ years ago"

• Emphasis on the word *started*

• Then I ragequit...

• Well not completely. Picked it up again sometime around 6 years ago.

• Then ragequit again. Until finally one day decided to actually learn it.

A bit more about me...

• 17 slides ago: "Started using Vim rougly 6+ years ago"

• Emphasis on the word *started*

• Then I ragequit...

• Well not completely. Picked it up again sometime around 6 years ago.

• Then ragequit again. Until finally one day decided to actually learn? it.

A bit more about me...

• 3 weeks. Food + vimtutor.

• At least 4 hrs of vimtutor drill over and over and over again.

A bit more about me...

• 3 weeks. Food + vimtutor.

• At least 4 hrs of vimtutor drill over and over and over and over and over and over and over and over and over and over and over and over and over and over and over and over and over and over and over and over and over and over again.

Moral of the Story?

• Vim is hard!

• Vim is not for mortals like me!

• Screw that, I'll just use another editor instead.... Why would I spend so much time on it? (in your case, an entire course)

Moral of the Story?

• Vim is hard!

• Vim is not for mortals like me!

• Screw that, I'll just use another editor instead.... Why would I spend so much time on it? (in your case, an entire course)

• Completely WRONG moral of the story

Actual Moral of the Story

• vimtutor is BAD BAD BAD!!!

• Something you learn in retrospect...

Something you hear very often...

• "Vim is hard to learn for beginners"

• "Vim is great since it has many commands, which makes you fast"

Something you hear very often...

• "Vim is hard to learn for beginners"

• "Vim is great since it has many commands, which makes you fast"

• "<insert random editor name> is better since it has <insert feature name>."

Something you hear very often...

• They are all either wrong, or unintentionally misleading...

• They all miss the point!

• Vim is also not hard to learn, it is just that most resources out there are complete garbage.

To list a few...

• Resources you should avoid:

• vimtutor (Worst offender, probably should give it some kind of award)

• Two books from O'Reilly

• Also, almost everything...

To list a few...

• Resources you should avoid:

• vimtutor (Worst offender, probably should give it some kind of award)

• Two books from O'Reilly

• Also, almost everything...

To list a few...

• Resources you should avoid:

• vimtutor (Worst offender, probably should give it some kind of award)

• Two books from O'Reilly

• Also, almost everything...

Actually Good Resources

Actually Good Resources

• However, Practical Vim requires some familiarity with Vim...

• By that time, most people have already completed vimtutor :(

• There are also roughly 3 screencasts from Destroy All Software, by Gary Bernhardt, though it's a bit pricy...

Emphasis in this course

• Systematic use of Vim

Emphasis in this course

• Systematic use of Vim

• Command Clarity and Ergonomics

Emphasis in this course

• Systematic use of Vim

• Command Clarity and Ergonomics

• Use Cases– When to use certain commands

Emphasis in this course

• Systematic use of Vim

• Command Clarity and Ergonomics

• Use Cases– When to use certain commands

– When NOT to use certain commands (antipatterns)

Emphasis in this course

• Systematic use of Vim

• Command Clarity and Ergonomics

• Use Cases– When to use certain commands

– When NOT to use certain commands (antipatterns)• WHY?

So why this course?

• Explain HOW to think about text editing. (Philosophy)

So why this course?

• Explain HOW to think about text editing. (Philosophy)

• Explain what RULES we follow when we manage integration of features, and why some commands are better than others. Also, why we DON'T use some commands. (Principles)

So why this course?

• Explains HOW to use Vim commands. (Practice).

• And most importantly, throughout the course explains a fundamental question...

WHY VIM?

Word of Warning!!

• This course does have prerequisites!!!• Requires working knowledge of using a unix(-

based/-like) command line• basic shell commands (ls, mkdir, cd, ...)• some utilities (make, man, ...)• it's okay to be bad at shell scripting• These commands will NOT be reviewed in

lecture!!• There is a course for that:

http://www.cs.cmu.edu/~15131/

Word of Warning!!

• This course is in no way "beginner-friendly", nor is it a crash course.

• In fact, you should be very wary of crash courses that tries to explain Vim.

• We won't even be able to actually use Vim until roughly the 6th lecture.

Word of Warning!!

• Some topics will be covered in much detail (navigation, repetition...)

• Some of them will only be covered if there is time left at the end of the semester (plugins...)

• This is a new course with brand new material, so the syllabus should only used as a rough reference.

Word of Warning!!

• Some topics will only be briefly mentioned, because these features are nearly obsolete (marks...)

• Some topics will be intentionally avoided! Because they are either broken or its fundamental ideas are WRONG (vimscript, vim regular expressions, certain plugins)

• Course Logistics :(

• A Bit of Foreshadowing...

• Installing Vim

• Keyboard Ergonomics

• Cool thing about Vim is that it is *mostly* designed to be portable.

• *mostly*

• However, it doesn't run on your toaster.• (maybe if you really try).

• For the purposes of this course, we will be using a very specific version of Vim.

Requirements

• For this particular course, you need Vim 7.4 huge version with ruby support.

• (Huh?)

• First thing to know is that every subversion upgrade introduces quite a few important changes.

• Vim 7.3 *may* work, but do not depend on it.

• Vim comes in different flavors...

• tiny

• small

• normal

• big

• huge

• There is very little reason not to use the huge version...

Check Version

• vim --version

• (good idea to pipe into less)

• Within vim:

• :version<CR>

• <CR> stands for "Carriage Return". For our purposes, it's the Enter key on the keyboard.

Ruby Support

• The only reason for this requirement is that there is a very specific plugin that we will talk about called Command-T:

• https://github.com/wincent/Command-T

• Requires vim compiled with ruby support

• vim --version | grep ruby

• Make sure that there is a "+" sign next to "ruby".

Ruby Support

• Also requires a "compatible" ruby version installed in system.

• Read the plugin README markdown on github, gives you all the details for that.

• Also requires a C compiler, highly unlikely that you don't have one.

OS woes

• Some operating systems are very uncooperative...

• In fact, one specific operating system comes to mind.

• We'll try workarounds, for time being, here's a general guide.

Linux (okay, GNU/Linux)

• Assume that you know what you are doing... (probably hear that pretty often).

• For ubuntu-based systems, apt-get has precompiled packages

• sudo apt-get install vim vim-common vim-nox vim-runtime

• vim-gtk?• vim-nox contains ruby support

Unix based OSes

• Also assume you know what you are doing...

• Package managers are the way to go.

• For Macs, I believe homebrew has macvim packages.

• According to the website, macvim has all features of Vim 7.4.

• I don't own a Mac.

Windows (ugh)

• Would be a good time to reflect on your life choices...

• Why are you even using Windows for development?

• Also does not have prebuilt unix utilites, such as make, grep, etc.

• Insanely hard to work with.

Windows

• With that said, I could not get Vim on Windows to work. :(

• I've tried many many things: compile from source (doesn't work with rubygems), gvim (also doesn't work with rubygems), Cygwin (doesn't work with anything).

• If anyone knows workarounds, email me and I'll post it.

Temporary Workaround

• For those who use Windows or those who do not fit in either category

• Use SSH, requires andrewid• First, you need an ssh client (only

applies to Windows users)• PuTTy has some saner colorschemes.• Cygwin (along with its tools) is actually

pretty nice.

Temporary Workaround

• Update!: As of writing, computing services just installed the required vim version for this course :D

Temporary Workaround

• Update!: As of writing, computing services just installed the required vim version for this course :D

Temporary Workaround

• Put this in your .bashrc over AFS timeshares:

• alias vim='vim74'• alias vimdiff='vim -d'• alias vi='vim'

Temporary Workaround

• Put this in your .bashrc over AFS timeshares:

• alias vim='vim74'• alias vimdiff='vim -d'• alias vi='vim'• (OPTIONALLY):• alias vimtutor='clear && @#$% you!'

Temporary Workaround

• Put this in your .bashrc over AFS timeshares:

• alias vim='vim74'• alias vimdiff='vim -d'• alias vi='vim'• (OPTIONALLY):• alias vimtutor='clear && @#$% you!'• Outdated again! (default is vim7.4)

4-letter curse word of

your choice

Temporary Workaround

• We will be installing Vim in AFS with andrew linux/unix.

• In short:

• Dowload Vim: ftp://ftp.vim.org/pub/vim/unix/vim-7.4.tar.bz2

• untar/unbzip

• Make with options

Temporary Workaround

• As per unix standards...

• First cd to src directory...• make distclean• ./configure --with-features=huge --

enable-rubyinterp• Now add the directory to your $PATH

• Course Logistics :(

• A Bit of Foreshadowing...

• Installing Vim

• Keyboard Ergonomics

A bit of a history lesson

• Back in the good ol' days.

• ed

A bit of a history lesson

• Back in the good ol' days.

• ed

• while(scanf("%s", str) != EOF)– printf("?\n");

A bit of a history lesson

• em

• "editor for mortals"

• en

• redesigned into ex (by Bill Joy)

A bit of a history lesson

• then there's vi.

• pronouced "vee-eye"

• Stands for "Visual mode" (literally)

• Modes <- very central

A bit of a history lesson

• Licensing issues...

• -> "vi clones": elvis, nvi, etc.

• Vim

• Note that in this course, we will be talking about Vim specifically, not vi

• There are very important differences!!

A bit of a history lesson

• "Vim"

• Stands for "Vi IMitation" initally...

• Now, it stands for "Vi IMproved"!

• Drastic improvements.

Why do we care?

Why do we care?

• Because software isn't the only thing that changed over the years...

• vi first written in 1976..

• with ADM-3...

• Hardware also changed as well.

Keyboards

What it looked like in the good ol' days

Keyboards

What it looked like in the good ol' days

Keyboards

• The keyboards back in the good ol' days are surprisingly well-designed!

• (the key placements at least)

• There are still problems. Many.

Standard Keyboards

Standard Keyboards

Standard Keyboards

More obvious issue: 3 hands?!?

Standard Keyboards

• Mouse... Same issues

http://xkcd.com/1530/

Standard Keyboards

• For the purposes for this course, we shall pretend that those areas and the mouse do not exist.

• They're just a figment of your imagination.

Standard Keyboards

Standard Keyboards

Um...

Standard Keyboards

Um...

Standard Keyboards

Um...

Standard Keyboards

Um...

Standard Keyboards

Solution?

Ergonomics Split Keyboard!

Split Keyboards

Split Keyboards

Split Keyboards

Microsoft Natural Ergonomics 4000

Split Keyboards

• You can still get Carpal Tunnel if you use Vim!!

• Significantly better than emacs keybindings, still...

Split Keyboards

• There are two modifier keys Vim uses:

• Control: <C->

• Shift: <S-> (usually no explicit notation)

Keyboards

Keyboards

Eh..

Keyboards

Eh..

Keyboards

Control

Legitimate reasons not to remap your Caps Lock key

Legitimate reasons not to remap your Caps Lock key

1. Skyrim

Legitimate reasons not to remap your Caps Lock key

1. Skyrim

2. Batman: Arkham

Legitimate reasons not to remap your Caps Lock key

1. Skyrim

2. Batman: Arkham

3. Balanced Keyboarding (N/A if you're using a laptop).

http://ergoemacs.org/emacs/swap_CapsLock_Ctrl.html

Legitimate reasons not to remap your Caps Lock key

Legitimate reasons not to remap your Caps Lock key

"Pop up"

Legitimate reasons not to remap your Caps Lock key

1. Skyrim

2. Batman: Arkham

3. Balanced Keyboarding (N/A if you're using a laptop).

http://ergoemacs.org/emacs/swap_CapsLock_Ctrl.html

Typing all Caps? Not a problem in Vim

Remapping Caps Lock

• For the purposes of this course, we won't be delving that deep into ergonomics.

• Windows: AutoHotKey (can be turned off) http://vim.wikia.com/wiki/Map_caps_lock_to_escape_in_Windows

Remapping Caps Lock

• Macs:

• https://stackoverflow.com/questions/15435253/how-to-remap-the-caps-lock-key-to-control-in-os-x-10-8

Remapping Caps Lock

• Linux/GNU Linux/Unix/Unix-like/Other:

• Assume you know what you're doing...

• check system settings

• xmodmap

• Google (shouldn't be too hard)

Aside

• When Vim was designed, it used the QWERTY layout....

• Sorry Dvorak users...

• I don't know how to type dvorak, some people have some experience with Vim + dvorak, google them

Finally

Finally

Finally

"Bad" Ergonomics

"Good" Ergonomics

Next Time

• The Vim Philosophy (2 most important lectures in the course!!)

• How do we think about text editing?

• What does it mean for an editor to edit text?

• Please set up Vim, and remap your keys!• Study the keyboard layout carefully.

• Remember, no class next Monday!

top related