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

Using vim faster than the other guy

Using vim faster than the other guy

Quick tech talk about vim usage, and how be more efficient doing it.

Rubens Stulzer

June 17, 2015
Tweet

More Decks by Rubens Stulzer

Other Decks in Programming

Transcript

  1. Remaps your caps lock to control! You can thank me

    after a month using it. :) ∴ QUICK TIP OF EFFICIENCY
  2. ∴ VIM MODES • VIM is a MODAL Text Editor,

    and the most important modes are: • Normal Mode • Insert Mode • Visual Mode
  3. ∴ WHERE TO START • Always start mastering Normal mode

    from: • Unshifted keys • Shifted keys • Control keys • Looking to your keyboard, do you know what each key do in Normal Mode?
  4. ∴ WHAT JUST HAPPENED? As soon I got there I

    typed cw which means change word
  5. ∴ WHAT JUST HAPPENED? For some reason I was in

    the middle of the baixar word, and then I typed change inside word
  6. ∴ WOW, WHAT JUST HAPPENED? If I want to get

    rid of the entire text block (paragraph). I simply type change inside paragraph
  7. ∴ WHAT JUST HAPPENED? If I want to change the

    content of a given tag. I just type change inside tag
  8. ∴ PRACTICE IS THE KEY Get all the keystrokes in

    your muscle memory, is the best thing you can do
  9. ∴ MOVING BETWEEN LINES Using j and k to move

    between lines is tedious and very inefficient
  10. ∴ MOVING BETWEEN LINES Well not tedious, but inefficient for

    sure. It is a nice to have, but that affect one principle when using vim
  11. ∴ MOVING BETWEEN LINES Now we are talking. Use 12j

    or 12k, it’s like 12 times faster than use j and k alone
  12. ∴ MOVING BETWEEN LINES Search is definitely the most efficient

    way to move between lines, it is fast and you don’t care about how many lines the file have
  13. By deleting a line with dd, you should never repeat

    it with dd again ∴ REPEATABLES
  14. ∴ REPEATABLES Delete the first line with dd, and then

    use dot . to repeat it over and over
  15. ∴ REPEATABLES • For motion, normal mode and other commands

    you have dot . as repeatable • For substitute command :s// you have & as repeatable • For search command / you have n to search next word and N for the previous • For visual lines you have :’<,'>mode to run some mode commands on each selected line • When search a character with f you can go back and forth with , and ;
  16. ∴ FILE NAVIGATION I would hang myself if I had

    to navigate between files this way
  17. ∴ FILE NAVIGATION • Tree directories • NERDTree • For

    fuzzy search • Command-T (sucks because depends on ruby) • Selecta (again depends on ruby) • Ctrl-p (awesomeness is pure Vimscript)
  18. ∴ FILE NAVIGATION Well, if you are new in a

    project and don’t have all directories and files in mind
  19. ∴ FILE NAVIGATION Starting directly from the app/views the fuzzy

    search became faster to match a given view
  20. ∴ FILE NAVIGATION • Rails Projects • <leader>cv app/views •

    <leader>cm app/models • <leader>ct app/controllers • <leader>cs spec/ • VivaReal Site • <leader>va src/main/webapp-resources/assets • <leader>vm src/main/webapp/mustache
  21. ∴ FILE NAVIGATION Map some keys to go directly to

    them, without take too much keystrokes
  22. ∴ FILE NAVIGATION The best scenario is to have the

    most used files mapped dynamically
  23. ∴ FILE NAVIGATION • Most used commands • :A (Alternative)

    - Switch between controller and spec • :R (Relative) - Switch between current cursor controller action to view • gf - Native vim go to file • <leader><leader> - remap it to <C-^>, which switch from the current buffer to the last opened
  24. ∴ FILE NAVIGATION Just :A and :R are from vim-rails

    plugin, gf on normal mode is vim default behaviour. Such as <C-^>
  25. ∴ REGISTERS On vim you can easily have more than

    30 clipboards, including the system clipboard
  26. ∴ REGISTERS They are not just clipboards, you can use

    registers to record a series of keystrokes creating a macro
  27. ∴ EX MODE The best mode to edit css or

    any other sentence that repeats over and over
  28. ∴ VIM IS HUGE There is a lot more to

    cover, and this talk couldn’t satisfy all vim aspects
  29. ∴ JUST REMEMBER • Learn normal mode keys • Motion

    commands • Don’t Repeat Yourself • From lowest to fastest: Read > Scan > Do • Get help from vim or from community • Use vim and have fun