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

The Path to Jedi Text Editing With VIM - Padawan Edition

Jaime
November 13, 2013

The Path to Jedi Text Editing With VIM - Padawan Edition

Introduction to VIM :) (presented in dev friday at Medius)

Jaime

November 13, 2013
Tweet

More Decks by Jaime

Other Decks in Programming

Transcript

  1. View Slide

  2. View Slide

  3. View Slide

  4. …In the remotest galaxy…
    There’s
    Known as…
    planet
    a
    EARTH…

    View Slide

  5. Jaime ponders…
    True story

    View Slide

  6. View Slide

  7. • Edit text at the speed of light
    • Precise like a surgeon
    • 100% keyboard driven
    • It’s on every platform
    • Highly configurable
    • Very extensible via plugins
    • Great documentation
    • It’s free
    • Worthwhile long-term investment (since 1991/1976)

    View Slide

  8. View Slide

  9. “You are a surgeon performing emergency surgery.”
    “That’s how I feel
    when I am using Vim”
    “With very precise moves and using the right tools
    you quickly slice, extract, and inject new code.”
    “Laying on the bed is the patient, your code. “

    View Slide

  10. “Vim is just a programming
    language for editing text”
    “edit text at the
    speed of thought”

    View Slide

  11. • Maximize what you can do with as few keystrokes as possible
    • It’s all about editing text efficiently
    • VIM Modes
    By using different modes you avoid the
    need to use weird combinations

    View Slide

  12. • VIM Modes
    Normal or Command
    Insert
    Visual
    Command-line
    etc…

    View Slide

  13. • You spend more time editing and manipulating text than writing
    it in the first place
    • That’s why the initial mode is the NORMAL mode

    View Slide

  14. • The most important things are at the tip of your fingers
    You can move around
    right from the home row

    View Slide

  15. • Vim commands build upon each other with outstanding results
    d delete a character
    dw delete a word
    d2w delete two words

    View Slide

  16. • Vim commands build upon each other with outstanding results
    d2wword
    delete
    two
    (operator, count, motion)

    View Slide

  17. • Jedi Youngling
    • Jedi Padawan
    • Jedi Knight
    • Jedi Master
    • Jedi Grand Master

    View Slide

  18. 1. Learn touch typing
    2. Normal and Insert modes
    3. Basic commands

    View Slide

  19. • i -> insert mode, ESC back to normal mode
    • x -> delete character
    • dd -> delete current line (and copy)
    • p -> paste
    • y -> copy character (yank)
    • yy -> copy current line
    • hjkl -> mode around (←↓↑→)
    • :help
    • :w -> save, :q -> quit, :wq -> save and quit

    View Slide

  20. View Slide

  21. 1. Learn more commands!
    2. Combine operators, counts and motions
    3. Commands in caps are big versions of commands in lower case
    4. The .(dot) command repeats the last change
    5. The search and find commands
    6. The visual mode
    7. Code completion
    8. Macros

    View Slide

  22. • a -> instead after character (append)
    • w -> go to the beginning of next word (word)
    • b -> go to the beginning of last work (back)
    • e -> go to the end of next word (end)
    • u -> undo last change (undo)
    • cw -> change word
    • o -> insert new line after the current one
    • gg -> go to the beginning of the document
    • $ -> go to the end of the line, 0 -> go to the beginning of the line

    View Slide

  23. • c2w -> change two words
    • d$ -> delete until the end of the line
    • daw -> delete all word (word and whitespace around it)
    • d2p -> delete two paragraphs
    • dt) -> delete until the parenthesis (not incluse)
    • di” -> delete inside quotes
    • da” -> delete inside quotes and quotes
    • % -> go to matching bracket
    • d2/hello -> delete until second occurrence of hello

    View Slide

  24. Taken from “Learn Vim Progressively”
    http://yannesposito.com/Scratch/en/blog/Learn-Vim-Progressively/

    View Slide

  25. • I -> insert at the beginning of the line
    • A -> append at the end of the line
    • D -> delete until the end of the line (shortcut for d$)
    • C -> change until the end of the line
    • O -> new line before the current line
    • G -> go to the end of the file
    • J -> append previous line

    View Slide

  26. • Vim is design to tackle repetition
    • Use the . command to repeat the last change
    • Use . to repeat the last command
    • Learn which combos are more repeatable

    View Slide

  27. • / to seach for patterns (e.g. /hello)
    • n for next occurrence
    • N for previous occurrence
    • * runs search for word under cursor
    • f find next occurrence of character in current line
    • ; next character in same line
    • , previous character in same line
    • F find but in reverse
    • t, like f but sets the cursor before the character

    View Slide

  28. • The visual mode lets you select text and perform operations on that
    selection
    • v -> go into visual mode with character selection
    • V -> go into visual mode with line selection
    • -> go into visual mode with block selection
    • Useful for instance for:
    • J -> join all lines together
    • < > -> add indentation
    • = -> autoindent

    View Slide

  29. • In insert mode you can
    have code completion
    • Use and

    View Slide

  30. • You can record useful chains of commands for later use
    • Use q to start recording a macro
    • Type register where to store macro
    • Record macro
    • Save macro with q
    • If they are really useful you can save them permanently

    View Slide

  31. • ReSharper is very keyboard friendly
    • Use ReSharper for macro refactorings
    • Use Vim for micro changes and moving around

    View Slide

  32. View Slide

  33. View Slide

  34. View Slide

  35. View Slide

  36. View Slide

  37. Vim is a fast and efficient text editor
    that will make you a faster and more
    efficient developer.
    It’s available on almost every OS—if you
    master the techniques in this book,
    you’ll never need another text editor.
    In more than 100 Vim tips, you’ll quickly
    learn the editor’s core functionality and
    tackle your trickiest editing and writing
    tasks.
    It’s Maciej Certified!

    View Slide

  38. Learn Vim Progressively
    http://yannesposito.com/Scratch/en/blog/Learn-Vim-Progressively/
    http://pluralsight.com/training/Courses/TableOfContents/smash-into-vim
    Smash into Vim
    Vim Adventures
    http://vim-adventures.com/

    View Slide

  39. Don’t overwrite Visual
    Studio and reSharper’s
    Key Bindings in the
    beginning

    View Slide

  40. Windows Mac

    View Slide

  41. View Slide

  42. http://bit.ly/more-instantly-better-vim
    “More Instantly Better Vim”
    http://bit.ly/expert-level-vim
    “Write code faster: Expert-level vim”

    View Slide

  43. http://www.derekwyatt.org/vim/vim-tutorial-videos/
    Vim tutorial videos
    http://vimcasts.org/
    Vimcasts, Practical VIM

    View Slide

  44. View Slide