Vim for newbies

Vim for newbies

Internal talk for Mollie Development

72635a06781143410d1ef4a25bf164ae?s=128

Mattijs Bliek

July 06, 2017
Tweet

Transcript

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

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

    = exit without saving • :w = save • :wq = save and exit How to save lives and exit Vim!
  5. 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
  6. Modes in Vim • Normal mode • Insert mode •

    Visual mode
  7. By default you’re in normal mode, this mode is meant

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

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

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

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

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

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

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

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

    (next). Or use N to go in the reverse direction. Searching
  24. 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
  25. 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
  26. Create and/or open ~/.vimrc Paste in this Gist: https://git.io/vQwOU Mappings

  27. 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