vim survival guide
TRANSCRIPT
The Vim Survival Guide
Ben McCormickWindsor CircleTwitter: @ben336Blog: http://benmccormick.org
Who Am I?
• Software Engineer at Windsor Circle• Vim user since 2013• Wrote a series of blogs on Vim in 2014
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
So What Is Vim?
What To Expect• Intro: Context + History• Part 1: Surviving Vim
• Why? • How?
• Part 2: Using Vim• Why?• How?
Vim’s Reputation
Vim’s Reputation
Vim’s Reputation
Vim’s Reputation
Vim’s Reputation
Vim’s Reputation
Vim’s Reputation
Vim’s Reputation: Fair Criticism
• Tough initial learning curve• Truly bad defaults (Bad beginner UX)• Alien for most modern users
Vim’s Reputation: Myths
• Too old to be relevant• Not really efficient• Tough learning curve lasts forever• Bad (power user) UX
Editor Wars
• Vi vs Emacs• Many more options now• But Vim stands apart
vi IDEs
Vim has different ideas about:
• Shortcut keys• Copy and paste• File system integration / management• Configuration• Keyboard vs mouse use• Naming conventions
Why use Vim at all?
• Ubiquitous• Many other editors don't run in a terminal
Surviving Vim: Minimal knowledge
• Vim is a modal editor• Vim has a visual editor and a command
prompt (ex) editor
What is a modal editor?
• Commands are contextual• Depending on what mode you’re in
different keystrokes do different things
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
Vim Modes
• Normal Mode• Insert Mode• Visual Mode• Others (less important)
Normal mode• “Normal”• default when Vim is opened• Keystrokes are commands• From other modes use `esc` to switch to
normal mode
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
Visual Mode
• For Highlighting/text selection• keystrokes are commands• From normal mode use `v` to switch to
visual mode
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
Starting Vim
Opening Files
• :e/:edit to open a new file• :sp/:split or :vs/:vsplit for opening in a split
Opening Files
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
Closing Files
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
Navigating Files
https://commons.wikimedia.org/wiki/File:QWERTY-home-keys-position.svg
Navigating Files
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 :)
Using Vim for real
Why use Vim over [Sublime/Atom/VS/IntelliJ/XCode/
etc]?
• A beautiful editing language• Command Line living• Top notch flexibility and configurability
Caveats
• Bad defaults• Learning Curve• Low UI polish• Plugin Development
Vim as language
• Motions: hjkl, w, b• Verbs: d, v
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
Vim as language
Vim as language
• More Motions: G/gg, f<char> • More Verbs: gU, c
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
Vim as language
• Text objects: iw, i(• Double verbs apply to the whole line
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
Vim as language
Vim as language
• verb + motion/text object -> action• Each new command you learn works with
existing concepts• Everyone has their own “accent”
Vim as Language: Repetition
• dot command `.` repeats the previous action (combo of verb and motion/text object)
• You can use plain motions in between
Vim as Language: Repetition
• dw to delete to the start of the next word• `..` to repeat 2 more times
Vim as Language: Repetition
Vim as a modern editor
• Fixing bad defaults comes through configuration in ~/.vimrc file
• Control look and feel, custom commands• https://dotfiles.github.io/
Vim as a modern editor
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!
Vim as a modern editor
Vim as a modern editor
Vim as a modern editor
Vim as a modern editor• Fuzzy-finder• Linting• Git Integration• AutoComplete• Status bars• Command line integration
Resources
• Practical Vim by Drew Neil• vimcasts.org• http://benmccormick.org/learning-vim-in-
2014/
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
Questions?
Ben McCormickWindsor CircleTwitter: @ben336Blog: http://benmccormick.org