Vim for people who don't want to use vim
Watch 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> + s
iputs 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.
Even those with years of experience (i.e. novices like myself)
occasionally hit a key sequence that puts them in a weird state.
<esc> about 5 times and then
i 5 times and then running
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 (
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:
uundoes an action
vtoggles visual selection (like you would do with a mouse)
ddeletes (and copies, aka cuts) the current selection
- Tip: use
- Tip: use
ppastes the current buffer
nmoves 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)
:w- write the file
:wq- do both at once (same as
: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 file
ggtakes you to the top of the file
vim is also a religion, in case you didn't already know.
Pop Quiz Answer
That's right! Underneath your right hand is the home row with the little notch
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
yyanks (copies) the current selection
yy- copy line
dd- delete line
37ltakes 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
By AJ ONeal
Was this useful to you? Share it!give me a tip or hire me.