Vim for people who don't want to use vim
Published 2013-1-17Watch on YouTube: youtu.be/eXzcs9Lm7d0
vim is 90% muscle memory!
This video is not an explanation, it is an exercise!
You must follow along for this video to work for you.
The most brief introduction to vim
The bare minimum you need to know in a world where vim exists and vi is sometimes your only option.
vim in an editor (a program you can use open a file, change text in the file, and save the file).
My gut wrenches to make this comparison,
but you can think of it as how you would use notepad if you constrained
to using the mouse and navigating through trees of menus.
This introduction is aimed towards people who never intend to use vim and would prefer to know nothing about it, but are also realists and as such understand that, well, they'll still end up using it.
The goal is to teach you just enough to not leave you hopelessly lost, frustrated, or annoyed, but not enough to make you cool or respectable.
Lesson 1: How to exit vim
These are the things you MUST know (perfectly suitable if your only desire with vim is to get quit out of it.)
In order to exit vim and return to a terminal (without breaking anything), you need only to know these 4 things:
<ctrl> + qunfreezes vim after you accidentally hit<ctrl> + siputs you into insert mode<esc>takes you back to the command mode (the from which you can rut the quit command):q!force quits without saving
If you do nothing but those 4 sequences in random order, you'll at least make it out alive.
Note:
Even those with years of experience (i.e. novices like myself)
occasionally hit a key sequence that puts them in a weird state.
Pressing <esc> about 5 times and then i 5 times and then running <esc>:q! twice
has always worked for me
(except when I needed to hit <ctrl> + q first).
Lesson 1.5: How to save an edit
These are the things you MUST know (if you intend edit anything)
When you're in insert mode you can edit.
owill open a new line:xexits after saving
When you're in command (<esc>) or visual mode you can move around
- arrow keys will move you around (even in insert mode)
- The right hand home row (h, j, k, l) will move you around if you're in old-school vi (which is not vim)
Pop quiz: Which home row underneath your right hand can be used for moving around? (answer in the appendix)
Lesson 2: Making it hurt less
If you intend to use vim more than accidentally, here's what I suggest learning first:
Undo
uundoes an action
Visual Selection
vtoggles visual selection (like you would do with a mouse)
Text Manipulation
ddeletes (and copies, aka cuts) the current selection- Tip: use
dand thenuto copy
- Tip: use
ppastes the current buffer
Moving around
-
/foosearch forfoonmoves to the next occurance<shift> + nmoves to the previous occurance
-
^moves to the beginning of line -
$moves to the end of line -
wmoves to the next word -
42jtakes you 42 lines down (use any number you like) -
37ktakes you 37 lines up (use any number you like) -
Note: this combining numbers with commands (or multiple commands) is a pattern
-
Arrow Keys are sometimes an option, but not always.
-
h - move left (it's the leftmost character key on the home row)
-
l - move right (it's the rightmost character key on the home row)
-
j - move down
-
k - move up (like a kangaroo)
File Manipulation
:w- write the file:wq- do both at once (same asx):q!- quit without saving
Lesson 3: Feel the burn
:%s/ABC/XYZ/gcreplaces ABC (or whatever) with XYZ (or whatever else)aedit after the current character>indents all selected lines<unindents all selected lines.repeats the previous action (such as indenting or a macro)shift+gtakes you to the bottom of the fileggtakes you to the top of the file
Worship Services
P.S. vim is also a religion, in case you didn't already know.
Appendix
Pop Quiz Answer
That's right! Underneath your right hand is the home row with the little notch
in the j that is the row that let's you move around!
The magic sequence that will always exit vim
<ctrl> + q
<esc> <esc> <esc> <esc> <esc>
i i i i i
<esc> <esc> <esc> <esc> <esc>
i i i i i
<esc> <esc> <esc> <esc> <esc>
:q!
Things I wish I had taught you
%moves to beginning or closing(,{,[, etcyyanks (copies) the current selectionyy- copy linedd- delete line37ltakes your cursor 37 characters right (use any number you like)7htakes your cursor 7 characters left (use any number you like)wmoves to the next word
References
- http://www.stanford.edu/~jacobm/vim.html
- http://www.marathon-studios.com/blog/solved-vi-vim-editor-is-frozen-by/
By AJ ONeal
Did I make your day?
(you can learn about the bigger picture I'm working towards on my patreon page )
