Slide 1

Slide 1 text

Using vim faster than the other guy Quick tips to master vim

Slide 2

Slide 2 text

Remaps your caps lock to control! You can thank me after a month using it. :) ∴ QUICK TIP OF EFFICIENCY

Slide 3

Slide 3 text

∴ LET’S TALK ABOUT VIM

Slide 4

Slide 4 text

∴ VIM MODES • VIM is a MODAL Text Editor, and the most important modes are: • Normal Mode • Insert Mode • Visual Mode

Slide 5

Slide 5 text

∴ 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?

Slide 6

Slide 6 text

∴ GETTING HELP

Slide 7

Slide 7 text

∴ GETTING HELP MOTION

Slide 8

Slide 8 text

∴ MOTION COMBO

Slide 9

Slide 9 text

∴ WHAT JUST HAPPENED? I searched for the word baixar From normal mode I typed /baixar

Slide 10

Slide 10 text

∴ WHAT JUST HAPPENED? As soon I got there I typed cw which means change word

Slide 11

Slide 11 text

∴ MOTION COMBO

Slide 12

Slide 12 text

∴ WHAT JUST HAPPENED? For some reason I was in the middle of the baixar word, and then I typed change inside word

Slide 13

Slide 13 text

∴ MOTION COMBO

Slide 14

Slide 14 text

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

Slide 15

Slide 15 text

∴ THAT REMEMBER US How destructive vim can be Watch out what you are typing

Slide 16

Slide 16 text

∴ MOTION COMBO

Slide 17

Slide 17 text

∴ WHAT JUST HAPPENED? If I want to change the content of a given tag. I just type change inside tag

Slide 18

Slide 18 text

∴ TPOPE This is possible thanks to the surround.vim plugin, by Tim Pope <3

Slide 19

Slide 19 text

∴ PRACTICE IS THE KEY Get all the keystrokes in your muscle memory, is the best thing you can do

Slide 20

Slide 20 text

∴ MOVING BETWEEN LINES

Slide 21

Slide 21 text

∴ MOVING BETWEEN LINES Using j and k to move between lines is tedious and very inefficient

Slide 22

Slide 22 text

∴ MOVING BETWEEN LINES

Slide 23

Slide 23 text

∴ MOVING BETWEEN LINES Well not tedious, but inefficient for sure. It is a nice to have, but that affect one principle when using vim

Slide 24

Slide 24 text

∴ THAT PRINCIPLE I gonna talk about in a minute

Slide 25

Slide 25 text

∴ MOVING BETWEEN LINES

Slide 26

Slide 26 text

∴ MOVING BETWEEN LINES Now we are talking. Use 12j or 12k, it’s like 12 times faster than use j and k alone

Slide 27

Slide 27 text

∴ MOVING BETWEEN LINES Nice, but when you have a file with hundred lines?

Slide 28

Slide 28 text

∴ MOVING BETWEEN LINES

Slide 29

Slide 29 text

∴ 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

Slide 30

Slide 30 text

∴ PRINCIPLE TO REMEMBER

Slide 31

Slide 31 text

∴ PRINCIPLE TO REMEMBER Read is the worst thing you can do

Slide 32

Slide 32 text

∴ PRINCIPLE TO REMEMBER Scan is a little bit better

Slide 33

Slide 33 text

∴ PRINCIPLE TO REMEMBER But the best scenario is simply do

Slide 34

Slide 34 text

∴ VIM IS ABOUT DRY TOO Whenever possible, don't repeat yourself

Slide 35

Slide 35 text

∴ REPEATABLES

Slide 36

Slide 36 text

By deleting a line with dd, you should never repeat it with dd again ∴ REPEATABLES

Slide 37

Slide 37 text

∴ REPEATABLES

Slide 38

Slide 38 text

∴ REPEATABLES Delete the first line with dd, and then use dot . to repeat it over and over

Slide 39

Slide 39 text

∴ 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 ;

Slide 40

Slide 40 text

∴ FILE NAVIGATION Vim doesn’t have a decent file navigation system

Slide 41

Slide 41 text

∴ FILE NAVIGATION

Slide 42

Slide 42 text

∴ FILE NAVIGATION I would hang myself if I had to navigate between files this way

Slide 43

Slide 43 text

∴ FILE NAVIGATION Thanks to the community we have a plenty options available

Slide 44

Slide 44 text

∴ 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)

Slide 45

Slide 45 text

∴ FILE NAVIGATION

Slide 46

Slide 46 text

∴ FILE NAVIGATION NERDTree, what is it good for?

Slide 47

Slide 47 text

∴ FILE NAVIGATION Well, if you are new in a project and don’t have all directories and files in mind

Slide 48

Slide 48 text

∴ FILE NAVIGATION

Slide 49

Slide 49 text

∴ FILE NAVIGATION Definitely the best, just like the ctrl-p on Sublime

Slide 50

Slide 50 text

∴ FILE NAVIGATION We can improve that even further

Slide 51

Slide 51 text

∴ FILE NAVIGATION

Slide 52

Slide 52 text

∴ FILE NAVIGATION Starting directly from the app/views the fuzzy search became faster to match a given view

Slide 53

Slide 53 text

∴ FILE NAVIGATION • Rails Projects • cv app/views • cm app/models • ct app/controllers • cs spec/ • VivaReal Site • va src/main/webapp-resources/assets • vm src/main/webapp/mustache

Slide 54

Slide 54 text

∴ FILE NAVIGATION Common files such as Gemfile, routes.rb, Gruntfile.js and etc…

Slide 55

Slide 55 text

∴ FILE NAVIGATION Map some keys to go directly to them, without take too much keystrokes

Slide 56

Slide 56 text

∴ FILE NAVIGATION

Slide 57

Slide 57 text

∴ FILE NAVIGATION The best scenario is to have the most used files mapped dynamically

Slide 58

Slide 58 text

∴ FILE NAVIGATION For rails projects the super awesome vim-rails plugin does

Slide 59

Slide 59 text

∴ CONTROLLER - SPEC

Slide 60

Slide 60 text

∴ CONTROLLER - VIEW

Slide 61

Slide 61 text

∴ VIEW - PARTIAL

Slide 62

Slide 62 text

∴ CONTROLLER - MODEL

Slide 63

Slide 63 text

∴ MODEL - SCHEMA

Slide 64

Slide 64 text

∴ 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 • - remap it to , which switch from the current buffer to the last opened

Slide 65

Slide 65 text

∴ FILE NAVIGATION Just :A and :R are from vim-rails plugin, gf on normal mode is vim default behaviour. Such as

Slide 66

Slide 66 text

∴ REGISTERS Your IDE or Text Editor have a huge number of clipboards?

Slide 67

Slide 67 text

∴ REGISTERS On vim you can easily have more than 30 clipboards, including the system clipboard

Slide 68

Slide 68 text

∴ REGISTERS Look at your keyboard, if it’s not a modifier key can be a register

Slide 69

Slide 69 text

∴ REGISTERS They are not just clipboards, you can use registers to record a series of keystrokes creating a macro

Slide 70

Slide 70 text

∴ REGISTERS

Slide 71

Slide 71 text

∴ MACROS

Slide 72

Slide 72 text

∴ NON DUMB WAY

Slide 73

Slide 73 text

∴ JUST OUT OF CURIOSITY You know what grep mean?

Slide 74

Slide 74 text

∴ JUST OUT OF CURIOSITY Where he came from?

Slide 75

Slide 75 text

∴ JUST OUT OF CURIOSITY From vim, of course

Slide 76

Slide 76 text

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

Slide 77

Slide 77 text

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

Slide 78

Slide 78 text

∴ EXAMPLE

Slide 79

Slide 79 text

∴ EX MODE The best mode to edit css or any other sentence that repeats over and over

Slide 80

Slide 80 text

∴ EX MODE

Slide 81

Slide 81 text

∴ VIM IS HUGE There is a lot more to cover, and this talk couldn’t satisfy all vim aspects

Slide 82

Slide 82 text

∴ 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

Slide 83

Slide 83 text

∴ THANK YOU!