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

Vim for newbies

Vim for newbies

Internal talk for Mollie Development

Mattijs Bliek

July 06, 2017
Tweet

More Decks by Mattijs Bliek

Other Decks in Technology

Transcript

  1. You will spend more time editing code than writing code,

    so it makes sense to optimise editors for this purpose. Vim philosophy
  2. 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}.
  3. • :q = exit, error on unsaved changes • :q!

    = exit without saving • :w = save • :wq = save and exit How to save lives and exit Vim!
  4. 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
  5. By default you’re in normal mode, this mode is meant

    for fast navigation and commands that require no typing. Modes in Vim
  6. Pressing i takes you into insert mode. This is the

    mode you’re used to from your regular editor. Modes in Vim
  7. 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
  8. Pressing esc will take you back into normal mode from

    whichever mode you’re in. Modes in Vim
  9. While in normal mode you can execute operators on the

    text in the document. These have the following structure: (action)(target) Operators
  10. 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
  11. Actions and targets are pretty intuitive in Vim, here are

    some examples: c = change d = delete w = word p = paragraph Operators
  12. Let’s try to delete a word by moving to the

    beginning of the word and typing dw. Operators
  13. 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
  14. 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
  15. 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
  16. Note this also works for other things, so I can

    empty an array by typing di[ or di]. Operators
  17. 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
  18. 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
  19. You can undo stuff by pressing u in normal mode.

    Again notice how the names of Vim commands make a lot of sense. Undo
  20. 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
  21. You can cycle through your search results by using n

    (next). Or use N to go in the reverse direction. Searching
  22. 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
  23. 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
  24. 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