Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Semi-skimmed vim

Sam Whitehall
February 15, 2017

Semi-skimmed vim

A practical approach to text editing enlightenment.

A short introduction to vim, why it's different to most text editors you've encountered, and some lessons I learned the hard way. Provides an outline for how to learn iteratively, while remaining productive.

Sam Whitehall

February 15, 2017
Tweet

Other Decks in Technology

Transcript

  1. Semi-Skimmed vim A practical path to text editing enlightenment Sam

    Whitehall 2017-02-15 The Oxford Mega Super Meetup Meetup
  2. What is this talk? • vim is a 25-year old

    command line modal text editor • Based on vi (even older) • Let’s skim the surface of why you may want to invest time into learning it
  3. Learn!? It’s a text editor • Has a reputation of

    being hard to learn • You can’t just start typing and see your code • Insert Mode vs Normal Mode • Normal mode is where the power lies • Often compared with another command-line editor, emacs • We won’t get into the “holy war”
  4. Why would I learn it? Ubiquitous Likely to be available

    Stable Learn it now, and it won’t change much Lightweight Won’t die with large files Fast Code a lot faster than a GUI editor
  5. How do I get started? The Hard Way Everything all

    at once Do things “right” right away How I started (and failed) a few times The Practical Way Step-by-step Don’t worry about doing things “right” How I eventually got going
  6. Step 1: Survive • $ vim my_file • Normal mode:

    • :w to save, :q to quit • i to enter insert mode • u to undo • x to delete character • ESC to return to normal mode Congratulations! You’re now as productive as in a normal text editor (especially if you have mouse mode enabled).
  7. Step 2: Get Comfortable Entering Insert Mode Moving Around a

    o w $ ^ enter insert mode after cursor enter insert mode on line below cursor first character start of next word final character Examples: These may seem like trivial gains, but they add up over time. Especially in terms of focus. You’re telling your editor what you want it to do (reach the end of the line), not how you want to do it (pressing “right” 12 times).
  8. (aside) • Learning vim is not a case of memorising

    loads of arbitrary shortcuts • It’s a grammar: modifiers, verbs & nouns → flow! • Most have mnemonics • d → delete, c → change (i.e. delete, then insert mode) http://stackoverflow.com/questions/1218390/what-is-your-most-productive-shortcut-with-vim/1220118#1220118
  9. dt: di( d$ delete to end of line ($) delete

    to the next : delete inside ()
  10. Step 3: Expand Comfort Zone • Learn one noun/verb every

    day (/relevant time unit) • Stay in normal mode as often as possible (hit ESC a lot) • Make your own cheat sheet • Exponential power from combining these actions
  11. • You can also use hjkl for cursor movement •

    This is weird at first, but requires less finger movement • You can edit your .vimrc to disable arrow keys • vim-adventures.com – great for practicing!
  12. You’ll be fine • Try it a little bit at

    a time, don’t be overwhelmed! • Thousands of people have learned it before, so can you!