Presentation given to students at the University of Utah on Vim basics. Each "mode" of vim is detailed and discussed at a high level. Meant to accompany live editing in Vim.
2. Vim - Why
• Vi was pretty terrible.Vim is vi-improved.
• Purpose:
• Efficient text editing
• Not typing faster
• Nearly every linux/unix install comes
with vi out of the box. Lots of mileage in
many domains.
3. Motivation
• You may have heard that “fast/efficient
typing speed doesn’t make you a good
developer.”
• This is true, but also misleading.
• It doesn’t make you a good developer, but
it does make you a better developer.
4. Motivation
• No one has deep thoughts while they type.
Thinking Typing Thinking Typing
5. Motivation
• The goal is to shorten time spent typing to
maximize thinking.
Thinking Typing Thinking Typing
6. Motivation
• This allows you to think more in the
same amount of time
Thinking Typing Thinking Typing Thinking Typing Thinking Typing
7. Vim
• Modal Editor - Keys on keyboard do different
things in different modes.
• Normal Mode - Keys are used to move
around the text.
• Insert Mode - Keys used to type as normal.
• Visual Mode - Moving the cursor around
highlights text (e.g. for cut/copy/paste)
• Command Mode - Send commands to
Vim, such as changing the font, saving the file,
etc.
8. Normal Mode - Motions
• Motions allow you to move around the document.
• h, j, k, l map to left, down, up, and right respectively.
• w - move one word forward
• b - move one word backward
• e - move to end of word
• ^ and $ move to beginning/end of line (taken from
regular expression syntax)
9. Normal Mode - Motions
(cont.)
• Combine numbers with motions.
• 10j - move 10 lines down
• 4w - move 4 words forward
10. Normal Mode - Advanced Motions
• f<letter> - move cursor on top of first
encountered <letter> in current line.
• F<letter> - same as f, but backwards
• t<letter> - move cursor behind first
encountered <letter> in current line
• T<letter> - same as t, but backward
• / - Search (I prefer this)
11. Normal Mode - Verbs
• Verbs must (usually) be mixed with motions (nouns)
• x - delete forward (no motion required)
• d - delete (cut)
• dw - delete one word forward (include whitespace)
• de - delete to end of word (don’t include whitespace)
• d$ - delete from where my cursor is to the end of
the line
• dd - delete entire line
• d4w - delete 4 words
• c - change (same as delete but puts you in insert mode
after)
• y - yank (copy)
12. Normal Mode - Sentences
• Combine everything for superpowers
• i (inside) a (around)
• syntax - <verb><i/a><motion>
• ci” - delete inside quotes
• ci{ - delete inside { ... }
• ciw - change inside current word
13. Insert Mode
• Text editing as normal
• Pressing i from normal mode enters insert mode
• esc exits insert mode back into normal mode
• (You can also use ctrl+[, which I prefer.You can also
make your own keybinding.)
• shift+i - enter insert mode just before first character
of line
• shift+a - enter insert mode just after last character
in line
14. Visual Mode
• v - enter visual mode. All motions will now
move the highlight.
• shift-v - highlight entire line
• ctrl-v - highlight vertically (mind asplode)
• All motions still work, w to jump words, $ to
jump to the end of the line, etc.
• All verbs still work. Highlight text, press d to
delete, c to change, etc.
15. Command Mode
• Command mode allows you to send commands to vim
• Typing a colon (:) from normal mode puts you in
command mode
• Examples:
• :w - Save the current file
• :e /path/to/file - edit a file
• :q - quit vim
• :q! - quit vim without saving (vim yells at you if you
try to quit without saving, this shuts vim up.)
16. Customizable
• Lots of plugins, most suck.
• NERDtree for tree navigation of files
• taglist also nice.
• Many, many others.
17. Customizable
• Vim uses VimScript/VimL for custom
scripting and it SUCKS.
Percentage of angry
issues/commits on
GitHub by language
18. Using Vim without
using Vim
• Some editors support “vim mode”. Sublime
Text,Visual Studio plugin, Xcode plugin, Qt
editor-thing, emacs.
• “vim mode” will emulate basic keybindings,
but cannot run plugins written in VimScript
(which may be a good thing)
• If I did not feel tied to some Vim plugins, I
would personally use Sublime Text with vim
mode enabled.