vim survival guide
TRANSCRIPT
![Page 1: Vim survival guide](https://reader038.vdocuments.net/reader038/viewer/2022102612/58ed8d911a28ab254e8b45a1/html5/thumbnails/1.jpg)
The Vim Survival Guide
Ben McCormickWindsor CircleTwitter: @ben336Blog: http://benmccormick.org
![Page 2: Vim survival guide](https://reader038.vdocuments.net/reader038/viewer/2022102612/58ed8d911a28ab254e8b45a1/html5/thumbnails/2.jpg)
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](https://reader038.vdocuments.net/reader038/viewer/2022102612/58ed8d911a28ab254e8b45a1/html5/thumbnails/3.jpg)
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](https://reader038.vdocuments.net/reader038/viewer/2022102612/58ed8d911a28ab254e8b45a1/html5/thumbnails/4.jpg)
So What Is Vim?
![Page 5: Vim survival guide](https://reader038.vdocuments.net/reader038/viewer/2022102612/58ed8d911a28ab254e8b45a1/html5/thumbnails/5.jpg)
What To Expect• Intro: Context + History• Part 1: Surviving Vim
• Why? • How?
• Part 2: Using Vim• Why?• How?
![Page 6: Vim survival guide](https://reader038.vdocuments.net/reader038/viewer/2022102612/58ed8d911a28ab254e8b45a1/html5/thumbnails/6.jpg)
Vim’s Reputation
![Page 7: Vim survival guide](https://reader038.vdocuments.net/reader038/viewer/2022102612/58ed8d911a28ab254e8b45a1/html5/thumbnails/7.jpg)
Vim’s Reputation
![Page 8: Vim survival guide](https://reader038.vdocuments.net/reader038/viewer/2022102612/58ed8d911a28ab254e8b45a1/html5/thumbnails/8.jpg)
Vim’s Reputation
![Page 9: Vim survival guide](https://reader038.vdocuments.net/reader038/viewer/2022102612/58ed8d911a28ab254e8b45a1/html5/thumbnails/9.jpg)
Vim’s Reputation
![Page 10: Vim survival guide](https://reader038.vdocuments.net/reader038/viewer/2022102612/58ed8d911a28ab254e8b45a1/html5/thumbnails/10.jpg)
Vim’s Reputation
![Page 11: Vim survival guide](https://reader038.vdocuments.net/reader038/viewer/2022102612/58ed8d911a28ab254e8b45a1/html5/thumbnails/11.jpg)
Vim’s Reputation
![Page 12: Vim survival guide](https://reader038.vdocuments.net/reader038/viewer/2022102612/58ed8d911a28ab254e8b45a1/html5/thumbnails/12.jpg)
Vim’s Reputation
![Page 13: Vim survival guide](https://reader038.vdocuments.net/reader038/viewer/2022102612/58ed8d911a28ab254e8b45a1/html5/thumbnails/13.jpg)
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](https://reader038.vdocuments.net/reader038/viewer/2022102612/58ed8d911a28ab254e8b45a1/html5/thumbnails/14.jpg)
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](https://reader038.vdocuments.net/reader038/viewer/2022102612/58ed8d911a28ab254e8b45a1/html5/thumbnails/15.jpg)
Editor Wars
• Vi vs Emacs• Many more options now• But Vim stands apart
![Page 16: Vim survival guide](https://reader038.vdocuments.net/reader038/viewer/2022102612/58ed8d911a28ab254e8b45a1/html5/thumbnails/16.jpg)
vi IDEs
![Page 17: Vim survival guide](https://reader038.vdocuments.net/reader038/viewer/2022102612/58ed8d911a28ab254e8b45a1/html5/thumbnails/17.jpg)
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](https://reader038.vdocuments.net/reader038/viewer/2022102612/58ed8d911a28ab254e8b45a1/html5/thumbnails/18.jpg)
Why use Vim at all?
• Ubiquitous• Many other editors don't run in a terminal
![Page 19: Vim survival guide](https://reader038.vdocuments.net/reader038/viewer/2022102612/58ed8d911a28ab254e8b45a1/html5/thumbnails/19.jpg)
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](https://reader038.vdocuments.net/reader038/viewer/2022102612/58ed8d911a28ab254e8b45a1/html5/thumbnails/20.jpg)
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](https://reader038.vdocuments.net/reader038/viewer/2022102612/58ed8d911a28ab254e8b45a1/html5/thumbnails/21.jpg)
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](https://reader038.vdocuments.net/reader038/viewer/2022102612/58ed8d911a28ab254e8b45a1/html5/thumbnails/22.jpg)
Vim Modes
• Normal Mode• Insert Mode• Visual Mode• Others (less important)
![Page 23: Vim survival guide](https://reader038.vdocuments.net/reader038/viewer/2022102612/58ed8d911a28ab254e8b45a1/html5/thumbnails/23.jpg)
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](https://reader038.vdocuments.net/reader038/viewer/2022102612/58ed8d911a28ab254e8b45a1/html5/thumbnails/24.jpg)
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](https://reader038.vdocuments.net/reader038/viewer/2022102612/58ed8d911a28ab254e8b45a1/html5/thumbnails/25.jpg)
Visual Mode
• For Highlighting/text selection• keystrokes are commands• From normal mode use `v` to switch to
visual mode
![Page 26: Vim survival guide](https://reader038.vdocuments.net/reader038/viewer/2022102612/58ed8d911a28ab254e8b45a1/html5/thumbnails/26.jpg)
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](https://reader038.vdocuments.net/reader038/viewer/2022102612/58ed8d911a28ab254e8b45a1/html5/thumbnails/27.jpg)
Starting Vim
![Page 28: Vim survival guide](https://reader038.vdocuments.net/reader038/viewer/2022102612/58ed8d911a28ab254e8b45a1/html5/thumbnails/28.jpg)
Opening Files
• :e/:edit to open a new file• :sp/:split or :vs/:vsplit for opening in a split
![Page 29: Vim survival guide](https://reader038.vdocuments.net/reader038/viewer/2022102612/58ed8d911a28ab254e8b45a1/html5/thumbnails/29.jpg)
Opening Files
![Page 30: Vim survival guide](https://reader038.vdocuments.net/reader038/viewer/2022102612/58ed8d911a28ab254e8b45a1/html5/thumbnails/30.jpg)
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](https://reader038.vdocuments.net/reader038/viewer/2022102612/58ed8d911a28ab254e8b45a1/html5/thumbnails/31.jpg)
Closing Files
![Page 32: Vim survival guide](https://reader038.vdocuments.net/reader038/viewer/2022102612/58ed8d911a28ab254e8b45a1/html5/thumbnails/32.jpg)
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](https://reader038.vdocuments.net/reader038/viewer/2022102612/58ed8d911a28ab254e8b45a1/html5/thumbnails/33.jpg)
Navigating Files
https://commons.wikimedia.org/wiki/File:QWERTY-home-keys-position.svg
![Page 34: Vim survival guide](https://reader038.vdocuments.net/reader038/viewer/2022102612/58ed8d911a28ab254e8b45a1/html5/thumbnails/34.jpg)
Navigating Files
![Page 35: Vim survival guide](https://reader038.vdocuments.net/reader038/viewer/2022102612/58ed8d911a28ab254e8b45a1/html5/thumbnails/35.jpg)
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 37: Vim survival guide](https://reader038.vdocuments.net/reader038/viewer/2022102612/58ed8d911a28ab254e8b45a1/html5/thumbnails/37.jpg)
Using Vim for real
![Page 38: Vim survival guide](https://reader038.vdocuments.net/reader038/viewer/2022102612/58ed8d911a28ab254e8b45a1/html5/thumbnails/38.jpg)
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](https://reader038.vdocuments.net/reader038/viewer/2022102612/58ed8d911a28ab254e8b45a1/html5/thumbnails/39.jpg)
Caveats
• Bad defaults• Learning Curve• Low UI polish• Plugin Development
![Page 40: Vim survival guide](https://reader038.vdocuments.net/reader038/viewer/2022102612/58ed8d911a28ab254e8b45a1/html5/thumbnails/40.jpg)
Vim as language
• Motions: hjkl, w, b• Verbs: d, v
![Page 41: Vim survival guide](https://reader038.vdocuments.net/reader038/viewer/2022102612/58ed8d911a28ab254e8b45a1/html5/thumbnails/41.jpg)
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](https://reader038.vdocuments.net/reader038/viewer/2022102612/58ed8d911a28ab254e8b45a1/html5/thumbnails/42.jpg)
Vim as language
![Page 43: Vim survival guide](https://reader038.vdocuments.net/reader038/viewer/2022102612/58ed8d911a28ab254e8b45a1/html5/thumbnails/43.jpg)
Vim as language
• More Motions: G/gg, f<char> • More Verbs: gU, c
![Page 44: Vim survival guide](https://reader038.vdocuments.net/reader038/viewer/2022102612/58ed8d911a28ab254e8b45a1/html5/thumbnails/44.jpg)
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](https://reader038.vdocuments.net/reader038/viewer/2022102612/58ed8d911a28ab254e8b45a1/html5/thumbnails/45.jpg)
Vim as language
• Text objects: iw, i(• Double verbs apply to the whole line
![Page 46: Vim survival guide](https://reader038.vdocuments.net/reader038/viewer/2022102612/58ed8d911a28ab254e8b45a1/html5/thumbnails/46.jpg)
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](https://reader038.vdocuments.net/reader038/viewer/2022102612/58ed8d911a28ab254e8b45a1/html5/thumbnails/47.jpg)
Vim as language
![Page 48: Vim survival guide](https://reader038.vdocuments.net/reader038/viewer/2022102612/58ed8d911a28ab254e8b45a1/html5/thumbnails/48.jpg)
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](https://reader038.vdocuments.net/reader038/viewer/2022102612/58ed8d911a28ab254e8b45a1/html5/thumbnails/49.jpg)
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](https://reader038.vdocuments.net/reader038/viewer/2022102612/58ed8d911a28ab254e8b45a1/html5/thumbnails/50.jpg)
Vim as Language: Repetition
• dw to delete to the start of the next word• `..` to repeat 2 more times
![Page 51: Vim survival guide](https://reader038.vdocuments.net/reader038/viewer/2022102612/58ed8d911a28ab254e8b45a1/html5/thumbnails/51.jpg)
Vim as Language: Repetition
![Page 52: Vim survival guide](https://reader038.vdocuments.net/reader038/viewer/2022102612/58ed8d911a28ab254e8b45a1/html5/thumbnails/52.jpg)
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](https://reader038.vdocuments.net/reader038/viewer/2022102612/58ed8d911a28ab254e8b45a1/html5/thumbnails/53.jpg)
Vim as a modern editor
![Page 54: Vim survival guide](https://reader038.vdocuments.net/reader038/viewer/2022102612/58ed8d911a28ab254e8b45a1/html5/thumbnails/54.jpg)
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](https://reader038.vdocuments.net/reader038/viewer/2022102612/58ed8d911a28ab254e8b45a1/html5/thumbnails/55.jpg)
Vim as a modern editor
![Page 56: Vim survival guide](https://reader038.vdocuments.net/reader038/viewer/2022102612/58ed8d911a28ab254e8b45a1/html5/thumbnails/56.jpg)
Vim as a modern editor
![Page 57: Vim survival guide](https://reader038.vdocuments.net/reader038/viewer/2022102612/58ed8d911a28ab254e8b45a1/html5/thumbnails/57.jpg)
Vim as a modern editor
![Page 58: Vim survival guide](https://reader038.vdocuments.net/reader038/viewer/2022102612/58ed8d911a28ab254e8b45a1/html5/thumbnails/58.jpg)
Vim as a modern editor• Fuzzy-finder• Linting• Git Integration• AutoComplete• Status bars• Command line integration
![Page 59: Vim survival guide](https://reader038.vdocuments.net/reader038/viewer/2022102612/58ed8d911a28ab254e8b45a1/html5/thumbnails/59.jpg)
Resources
• Practical Vim by Drew Neil• vimcasts.org• http://benmccormick.org/learning-vim-in-
2014/
![Page 60: Vim survival guide](https://reader038.vdocuments.net/reader038/viewer/2022102612/58ed8d911a28ab254e8b45a1/html5/thumbnails/60.jpg)
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](https://reader038.vdocuments.net/reader038/viewer/2022102612/58ed8d911a28ab254e8b45a1/html5/thumbnails/61.jpg)
Questions?