vim survival guide

62
The Vim Survival Guide Ben McCormick Windsor Circle Twitter: @ben336 Blog: http://benmccormick.org

Upload: ben-mccormick

Post on 12-Apr-2017

66 views

Category:

Engineering


5 download

TRANSCRIPT

Page 1: Vim survival guide

The Vim Survival Guide

Ben McCormickWindsor CircleTwitter: @ben336Blog: http://benmccormick.org

Page 2: Vim survival guide

Who Am I?

• Software Engineer at Windsor Circle• Vim user since 2013• Wrote a series of blogs on Vim in 2014

Page 3: Vim survival guide

So What Is Vim?• Open Source Text editor created in 1991,

based on an earlier text editor (vi) created in 1976 for UNIX

• Terminal based, but can be used in UI• Some variation on it or vi is shipped in ~all

*nix operating systems• Charityware

Page 4: Vim survival guide

So What Is Vim?

Page 5: Vim survival guide

What To Expect• Intro: Context + History• Part 1: Surviving Vim

• Why? • How?

• Part 2: Using Vim• Why?• How?

Page 6: Vim survival guide

Vim’s Reputation

Page 7: Vim survival guide

Vim’s Reputation

Page 8: Vim survival guide

Vim’s Reputation

Page 9: Vim survival guide

Vim’s Reputation

Page 10: Vim survival guide

Vim’s Reputation

Page 11: Vim survival guide

Vim’s Reputation

Page 12: Vim survival guide

Vim’s Reputation

Page 13: Vim survival guide

Vim’s Reputation: Fair Criticism

• Tough initial learning curve• Truly bad defaults (Bad beginner UX)• Alien for most modern users

Page 14: Vim survival guide

Vim’s Reputation: Myths

• Too old to be relevant• Not really efficient• Tough learning curve lasts forever• Bad (power user) UX

Page 15: Vim survival guide

Editor Wars

• Vi vs Emacs• Many more options now• But Vim stands apart

Page 16: Vim survival guide

vi IDEs

Page 17: Vim survival guide

Vim has different ideas about:

• Shortcut keys• Copy and paste• File system integration / management• Configuration• Keyboard vs mouse use• Naming conventions

Page 18: Vim survival guide

Why use Vim at all?

• Ubiquitous• Many other editors don't run in a terminal

Page 19: Vim survival guide

Surviving Vim: Minimal knowledge

• Vim is a modal editor• Vim has a visual editor and a command

prompt (ex) editor

Page 20: Vim survival guide

What is a modal editor?

• Commands are contextual• Depending on what mode you’re in

different keystrokes do different things

Page 21: Vim survival guide

What is a modal editor?

In this mode, typing `dd`deletes the current line

In this mode, typing `dd`writes out 2 ds

at the start of the line

Page 22: Vim survival guide

Vim Modes

• Normal Mode• Insert Mode• Visual Mode• Others (less important)

Page 23: Vim survival guide

Normal mode• “Normal”• default when Vim is opened• Keystrokes are commands• From other modes use `esc` to switch to

normal mode

Page 24: Vim survival guide

Insert Mode• More normal for modern users• Keystrokes insert text • commands are possible with key

combinations• From normal mode use `i` to switch to

insert mode

Page 25: Vim survival guide

Visual Mode

• For Highlighting/text selection• keystrokes are commands• From normal mode use `v` to switch to

visual mode

Page 26: Vim survival guide

Ex Commands / Command Prompt

• From normal mode `:` to trigger ex commands

• File menu equivalent

• Used for opening, closing files and the editor, find and replace, command line integration, more

Page 27: Vim survival guide

Starting Vim

Page 28: Vim survival guide

Opening Files

• :e/:edit to open a new file• :sp/:split or :vs/:vsplit for opening in a split

Page 29: Vim survival guide

Opening Files

Page 30: Vim survival guide

Closing Files

• :w/:write to save• :q/:quit or :qall/:quitall to quit• :wq to save and quit• :q! to force quit with unsaved changes

Page 31: Vim survival guide

Closing Files

Page 32: Vim survival guide

Navigating Files

• Encourages use of hjkl instead of the arrow keys

• Arrow keys still work• Mouse might or might not work depending

on your environment

Page 33: Vim survival guide

Navigating Files

https://commons.wikimedia.org/wiki/File:QWERTY-home-keys-position.svg

Page 34: Vim survival guide

Navigating Files

Page 35: Vim survival guide

Vim Survival• Remember that Vim is modal• Insert mode is “normal editing” mode• Normal mode is “command mode”• :w to save, :q to quit, :q! to quit

decisively :)

Page 36: Vim survival guide

Resources

• vimtutor• vim-adventures.com

Page 37: Vim survival guide

Using Vim for real

Page 38: Vim survival guide

Why use Vim over [Sublime/Atom/VS/IntelliJ/XCode/

etc]?

• A beautiful editing language• Command Line living• Top notch flexibility and configurability

Page 39: Vim survival guide

Caveats

• Bad defaults• Learning Curve• Low UI polish• Plugin Development

Page 40: Vim survival guide

Vim as language

• Motions: hjkl, w, b• Verbs: d, v

Page 41: Vim survival guide

Vim as language

• dh -> delete one character to the left• dl -> delete one character to the right• dw -> delete to the start of the next word• db -> delete back to the start of the current

word

Page 42: Vim survival guide

Vim as language

Page 43: Vim survival guide

Vim as language

• More Motions: G/gg, f<char> • More Verbs: gU, c

Page 44: Vim survival guide

Vim as language

• dG - delete everything to the end of the file • gUf. - all-caps to the next `.`• cw - delete to the start of the next word,

and then enter insert mode to replace the text

Page 45: Vim survival guide

Vim as language

• Text objects: iw, i(• Double verbs apply to the whole line

Page 46: Vim survival guide

Vim as language• di( - delete everything inside the current

parens• gUiw - all-caps the current word• dd - delete the current line• cc -delete the current line and move to

insert mode

Page 47: Vim survival guide

Vim as language

Page 48: Vim survival guide

Vim as language

• verb + motion/text object -> action• Each new command you learn works with

existing concepts• Everyone has their own “accent”

Page 49: Vim survival guide

Vim as Language: Repetition

• dot command `.` repeats the previous action (combo of verb and motion/text object)

• You can use plain motions in between

Page 50: Vim survival guide

Vim as Language: Repetition

• dw to delete to the start of the next word• `..` to repeat 2 more times

Page 51: Vim survival guide

Vim as Language: Repetition

Page 52: Vim survival guide

Vim as a modern editor

• Fixing bad defaults comes through configuration in ~/.vimrc file

• Control look and feel, custom commands• https://dotfiles.github.io/

Page 53: Vim survival guide

Vim as a modern editor

Page 54: Vim survival guide

Vim as a modern editor

• Feature parity with other editors comes through plugins

• http://vimawesome.com/• Many plugin managers with Github

compatibility (pathogen, vundle, vim-plug)• Plugins are ~100% open source, you can

make your own!

Page 55: Vim survival guide

Vim as a modern editor

Page 56: Vim survival guide

Vim as a modern editor

Page 57: Vim survival guide

Vim as a modern editor

Page 58: Vim survival guide

Vim as a modern editor• Fuzzy-finder• Linting• Git Integration• AutoComplete• Status bars• Command line integration

Page 59: Vim survival guide

Resources

• Practical Vim by Drew Neil• vimcasts.org• http://benmccormick.org/learning-vim-in-

2014/

Page 60: Vim survival guide

Vim Language Elsewhere

• Neovim: a rethinking of Vim• Vim modes: Sublime, Atom, IntelliJ, Visual

Studio• Command Line: vim modes for bash, zsh,

fish• Elsewhere: Gmail has vi-inspired shortcuts

Page 61: Vim survival guide

Questions?

Page 62: Vim survival guide

Ben McCormickWindsor CircleTwitter: @ben336Blog: http://benmccormick.org