Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Vim survival guide

517 views

Published on

An introduction to Vim

Published in: Engineering
  • Be the first to comment

Vim survival guide

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

×