Slide 1

Slide 1 text

No content

Slide 2

Slide 2 text

You will spend more time editing code than writing code, so it makes sense to optimise editors for this purpose. Vim philosophy

Slide 3

Slide 3 text

Opening files Open the directory you want in vim by going to the command line and typing vim {path} If {path} is a directory, you can open a file by typing :e {relative-path}.

Slide 4

Slide 4 text

• :q = exit, error on unsaved changes • :q! = exit without saving • :w = save • :wq = save and exit How to save lives and exit Vim!

Slide 5

Slide 5 text

Moving the cursor • Use h, j, k, l instead of arrow keys • Use e to go to the end of a word • Use b to go to the beginning of a word • Type the line number + gg to go to that line

Slide 6

Slide 6 text

Modes in Vim • Normal mode • Insert mode • Visual mode

Slide 7

Slide 7 text

By default you’re in normal mode, this mode is meant for fast navigation and commands that require no typing. Modes in Vim

Slide 8

Slide 8 text

Pressing i takes you into insert mode. This is the mode you’re used to from your regular editor. Modes in Vim

Slide 9

Slide 9 text

Pressing v takes you into visual mode. You can now move through the document and everything you come across will be selected. You will use this mode the least. Modes in Vim

Slide 10

Slide 10 text

Pressing esc will take you back into normal mode from whichever mode you’re in. Modes in Vim

Slide 11

Slide 11 text

While in normal mode you can execute operators on the text in the document. These have the following structure: (action)(target) Operators

Slide 12

Slide 12 text

The action is what you want to do, such as delete or change a piece of text. The target is on what you want to performance the actions, such as the word underneath the cursor. Operators

Slide 13

Slide 13 text

Actions and targets are pretty intuitive in Vim, here are some examples: c = change d = delete w = word p = paragraph Operators

Slide 14

Slide 14 text

Let’s try to delete a word by moving to the beginning of the word and typing dw. Operators

Slide 15

Slide 15 text

Once you learn an operator, it’s easy to know the related operators as well. So if you know you can delete a word with dw, and you know c is change, you can figure out that you can change a word with cw. Operators

Slide 16

Slide 16 text

Sometimes you need to tell Vim more about what you want to delete, such as whether you want to delete the text in an html tag, or also the tag itself. Operators

Slide 17

Slide 17 text

You do this by putting i (in) or a (around) in between the action and the target. Deleting the text in an html tag is done by typing dit. Operators

Slide 18

Slide 18 text

Note this also works for other things, so I can empty an array by typing di[ or di]. Operators

Slide 19

Slide 19 text

If you know you want to repeat a command multiple times, you can type the amount of repetitions before the command. Moving up 10 lines is 10j Deleting 5 words if 5dw Repeating commands

Slide 20

Slide 20 text

You can also repeat the last executed command by typing a . Say you just deleted a word with dw and want to delete another one, just type . Repeating commands

Slide 21

Slide 21 text

You can undo stuff by pressing u in normal mode. Again notice how the names of Vim commands make a lot of sense. Undo

Slide 22

Slide 22 text

You search a lot in Vim, since it is much faster to move through a document this way. Searching the current buffer is done by typing / followed by your query. Search in the reverse direction by using ? Searching

Slide 23

Slide 23 text

You can cycle through your search results by using n (next). Or use N to go in the reverse direction. Searching

Slide 24

Slide 24 text

You can also quickly find a certain character on the current line by typing f followed by the character. Search in the reverse direction by using F. Searching

Slide 25

Slide 25 text

Vim allows you to customise all its key bindings. Some default bindings aren’t very convenient on a modern day keyboard layout, so we’ll remap them. Mappings

Slide 26

Slide 26 text

Create and/or open ~/.vimrc Paste in this Gist: https://git.io/vQwOU Mappings

Slide 27

Slide 27 text

There are an enormous amount of plugins for Vim. You can get really close to IDE level functionality. The best thing is you can customise pretty much everything, so you’re never stuck with the defaults. Plugins