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.

412292ca8d206e602f2c6331b5838ad3?s=128

Rubens Stulzer

June 17, 2015
Tweet

Transcript

  1. Using vim faster than the other guy Quick tips to

    master vim
  2. Remaps your caps lock to control! You can thank me

    after a month using it. :) ∴ QUICK TIP OF EFFICIENCY
  3. ∴ LET’S TALK ABOUT VIM

  4. ∴ VIM MODES • VIM is a MODAL Text Editor,

    and the most important modes are: • Normal Mode • Insert Mode • Visual Mode
  5. ∴ 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?
  6. ∴ GETTING HELP

  7. ∴ GETTING HELP MOTION

  8. ∴ MOTION COMBO

  9. ∴ WHAT JUST HAPPENED? I searched for the word baixar

    From normal mode I typed /baixar
  10. ∴ WHAT JUST HAPPENED? As soon I got there I

    typed cw which means change word
  11. ∴ MOTION COMBO

  12. ∴ WHAT JUST HAPPENED? For some reason I was in

    the middle of the baixar word, and then I typed change inside word
  13. ∴ MOTION COMBO

  14. ∴ WOW, WHAT JUST HAPPENED? If I want to get

    rid of the entire text block (paragraph). I simply type change inside paragraph
  15. ∴ THAT REMEMBER US How destructive vim can be Watch

    out what you are typing
  16. ∴ MOTION COMBO

  17. ∴ WHAT JUST HAPPENED? If I want to change the

    content of a given tag. I just type change inside tag
  18. ∴ TPOPE This is possible thanks to the surround.vim plugin,

    by Tim Pope <3
  19. ∴ PRACTICE IS THE KEY Get all the keystrokes in

    your muscle memory, is the best thing you can do
  20. ∴ MOVING BETWEEN LINES

  21. ∴ MOVING BETWEEN LINES Using j and k to move

    between lines is tedious and very inefficient
  22. ∴ MOVING BETWEEN LINES

  23. ∴ MOVING BETWEEN LINES Well not tedious, but inefficient for

    sure. It is a nice to have, but that affect one principle when using vim
  24. ∴ THAT PRINCIPLE I gonna talk about in a minute

  25. ∴ MOVING BETWEEN LINES

  26. ∴ MOVING BETWEEN LINES Now we are talking. Use 12j

    or 12k, it’s like 12 times faster than use j and k alone
  27. ∴ MOVING BETWEEN LINES Nice, but when you have a

    file with hundred lines?
  28. ∴ MOVING BETWEEN LINES

  29. ∴ 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
  30. ∴ PRINCIPLE TO REMEMBER

  31. ∴ PRINCIPLE TO REMEMBER Read is the worst thing you

    can do
  32. ∴ PRINCIPLE TO REMEMBER Scan is a little bit better

  33. ∴ PRINCIPLE TO REMEMBER But the best scenario is simply

    do
  34. ∴ VIM IS ABOUT DRY TOO Whenever possible, don't repeat

    yourself
  35. ∴ REPEATABLES

  36. By deleting a line with dd, you should never repeat

    it with dd again ∴ REPEATABLES
  37. ∴ REPEATABLES

  38. ∴ REPEATABLES Delete the first line with dd, and then

    use dot . to repeat it over and over
  39. ∴ 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 ;
  40. ∴ FILE NAVIGATION Vim doesn’t have a decent file navigation

    system
  41. ∴ FILE NAVIGATION

  42. ∴ FILE NAVIGATION I would hang myself if I had

    to navigate between files this way
  43. ∴ FILE NAVIGATION Thanks to the community we have a

    plenty options available
  44. ∴ 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)
  45. ∴ FILE NAVIGATION

  46. ∴ FILE NAVIGATION NERDTree, what is it good for?

  47. ∴ FILE NAVIGATION Well, if you are new in a

    project and don’t have all directories and files in mind
  48. ∴ FILE NAVIGATION

  49. ∴ FILE NAVIGATION Definitely the best, just like the ctrl-p

    on Sublime
  50. ∴ FILE NAVIGATION We can improve that even further

  51. ∴ FILE NAVIGATION

  52. ∴ FILE NAVIGATION Starting directly from the app/views the fuzzy

    search became faster to match a given view
  53. ∴ 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
  54. ∴ FILE NAVIGATION Common files such as Gemfile, routes.rb, Gruntfile.js

    and etc…
  55. ∴ FILE NAVIGATION Map some keys to go directly to

    them, without take too much keystrokes
  56. ∴ FILE NAVIGATION

  57. ∴ FILE NAVIGATION The best scenario is to have the

    most used files mapped dynamically
  58. ∴ FILE NAVIGATION For rails projects the super awesome vim-rails

    plugin does
  59. ∴ CONTROLLER - SPEC

  60. ∴ CONTROLLER - VIEW

  61. ∴ VIEW - PARTIAL

  62. ∴ CONTROLLER - MODEL

  63. ∴ MODEL - SCHEMA

  64. ∴ 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
  65. ∴ FILE NAVIGATION Just :A and :R are from vim-rails

    plugin, gf on normal mode is vim default behaviour. Such as <C-^>
  66. ∴ REGISTERS Your IDE or Text Editor have a huge

    number of clipboards?
  67. ∴ REGISTERS On vim you can easily have more than

    30 clipboards, including the system clipboard
  68. ∴ REGISTERS Look at your keyboard, if it’s not a

    modifier key can be a register
  69. ∴ REGISTERS They are not just clipboards, you can use

    registers to record a series of keystrokes creating a macro
  70. ∴ REGISTERS

  71. ∴ MACROS

  72. ∴ NON DUMB WAY

  73. ∴ JUST OUT OF CURIOSITY You know what grep mean?

  74. ∴ JUST OUT OF CURIOSITY Where he came from?

  75. ∴ JUST OUT OF CURIOSITY From vim, of course

  76. ∴ JUST OUT OF CURIOSITY From command mode :g/re/p

  77. ∴ JUST OUT OF CURIOSITY Which means :global/regularExpression/print :g/re/p grep

  78. ∴ EXAMPLE

  79. ∴ EX MODE The best mode to edit css or

    any other sentence that repeats over and over
  80. ∴ EX MODE

  81. ∴ VIM IS HUGE There is a lot more to

    cover, and this talk couldn’t satisfy all vim aspects
  82. ∴ 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
  83. ∴ THANK YOU!