Open Side Menu Go to the Top
Register
Vim reference guide Vim reference guide

12-01-2015 , 12:01 AM
I thought I'd encourage new vim users to try it by offering a reference guide. I know it's a lot, but one day you'll be bored enough to try vim, develop some practice and never go back! Also, I recommend using vim in a Unix-based OS (Linux, Mac) as opposed to Windows - vim is a terminal text editor so part of vim's quickness also comes being able to quickly go in and out of files while in the terminal.

Please offer additions or corrections.


ESC: Navigation mode
v: Visual mode*
SHIFT+V: Select line in visual mode

*Unless I need to select a bunch of lines or select a very few amount of characters on one particular line, I usually go into visual mode as a last resort. If I need to copy some text, it might be faster to copy the entire line and create edits around that, e.g. yy to yank (copy) the entire line, p to paste to the next line, then D to trim off the end of a line, then something like CTRL+J to join it to some other line if I need to etc.


i: Insert mode at cursor
I: Insert mode line start
o: Insert mode starting on next line
O: Insert mode starting on line above
a: Insert mode after current letter
A: Insert mode at the end of the current line

j: Move cursor 1 line down
k: Move cursor 1 line up
h: Move cursor 1 letter left
l: Move cursor 1 letter right
[n]j: Moves cursor n lines down. Same for k,h and l
gg: Go to line 1
G: Go to last line
[n]gg: Moves you to line n

CTRL+D: Scroll down
CTRL+U: Scroll up
H: Move cursor to top of the terminal
M: Move cursor to middle of the terminal
L: Move cursor to bottom line on terminal
^: Move cursor to start of the line
$: Move cursor to end of the line
zt: Scroll so that the line the cursor is on is that the top of the terminal window
zz: Scroll making the line the cursor is on to the middle of the terminal window
zb: Scroll making the line the cursor is on to the bottom of the terminal window

w: Skip to start of the next next word
b: Skip to the start of the last word
e: Skip to last letter of current word

d [ ]: Cut [next] (e.g. if next key is w, it'll delete next word)
dw: Cut next word
dd: Cut current line
[n]dd: Cut next n lines
y[ ]: Yank (copy) next
yy: Yank line
[n]yy: Yank next n lines

p: Paste after cursor
P: Paste before cursor

u: undo
CTRL + r: redo
CTRL+O: Go to last place where cursor is
CTRL+I: Go to next place where cursor was

r: replace character
J: Join next line with current
r + ENTER: trick to cut the line. Do this when the cursor is on a space

:%s/[original regex]/[new text]/g Substitute text using reg ex. Use \ to escape regex
/ Find text
. Repeat operation on current line at where the cursor is

>> Indent
<< Indent
[n]>> Indent next n lines
[n]<<

x: Forward delete in nav mode
X: Backward delete in nav mode
gm: To to middle of the terminal window

:w Write (save)
:q quit
:q! Force quit (e.g. no prompts to save)
:wq Save and quit
:n Next file if you opened more than 1
:wn Write and next

Last edited by :::grimReaper:::; 12-01-2015 at 12:14 AM.
Vim reference guide Quote
12-01-2015 , 01:54 AM
there are so many of these guides that i'm surprised you didn't just link to one instead of writing your own

when you want to get really crazy:
http://zzapper.co.uk/vimtips.html
Vim reference guide Quote
12-01-2015 , 04:28 AM
Actually, I already had it written.

Those are commands I use the most and think it's a good starting point for new users. Now that I googled some reference guides, I think my post is less intimidating.
Vim reference guide Quote
12-01-2015 , 02:47 PM
Quote:
Originally Posted by :::grimReaper:::
j: Move cursor 1 line down
k: Move cursor 1 line up
h: Move cursor 1 letter left
l: Move cursor 1 letter right
This is a good example of why I hate vim. Just use the arrow keys like every other program. Makes the learning curve unnecessarily steep.
Vim reference guide Quote
12-01-2015 , 02:52 PM
It's a perfect example of what's awesome about vim.

The arrow keys usually (always?) still work so there's no "unnecessarily steep learning curve" because you can just keep using what works intuitively.

But once you get around to learning movement keys - j/k/h/l is significantly more comfortable and efficient than using arrow keys.
Vim reference guide Quote
12-01-2015 , 03:27 PM
Quote:
Originally Posted by maxtower
This is a good example of why I hate vim. Just use the arrow keys like every other program. Makes the learning curve unnecessarily steep.
http://yehudakatz.com/2010/07/29/eve...vim-was-wrong/
Vim reference guide Quote
12-01-2015 , 07:35 PM
Quote:
Originally Posted by maxtower
This is a good example of why I hate vim. Just use the arrow keys like every other program. Makes the learning curve unnecessarily steep.
You can map them to other keys though? Think vim is great but not so much in windows.
Vim reference guide Quote
12-01-2015 , 11:13 PM
Thanks for the post OP. Nice little reminder to myself that I need to keep learning new hotkeys, otherwise I'll rely to heavily on h-j-k-l.
Vim reference guide Quote
12-01-2015 , 11:42 PM
http://vim-adventures.com/ is a great starter. The free version gets you through most of basic movement in vim which for me was good enough to about equal my productivity in Sublime Text.

These days I use RubyMine with a vim plugin and I love it. I'm way faster now than my coworkers who use plain vim or are still stuck on Sublime.

My most used command is probably gd (Go to definition). This is made even more powerful by RubyMine which allows it to jump between files.
Vim reference guide Quote
12-02-2015 , 12:17 AM
You can also type in `vimtutor` in terminal and run the tutor program.
Vim reference guide Quote
12-02-2015 , 12:20 AM
Quote:
Originally Posted by jjshabado
It's a perfect example of what's awesome about vim.

The arrow keys usually (always?) still work so there's no "unnecessarily steep learning curve" because you can just keep using what works intuitively.

But once you get around to learning movement keys - j/k/h/l is significantly more comfortable and efficient than using arrow keys.
In my opinion its much more useful to just have those keys type the characters jkhl.
Vim reference guide Quote
12-02-2015 , 12:30 AM
Quote:
Originally Posted by greg nice
The first thing he mentions is ci ". Isn't it simple enough to just double click that in textmate and start typing?
Vim reference guide Quote
12-02-2015 , 12:37 AM
Quote:
Originally Posted by maxtower
In my opinion its much more useful to just have those keys type the characters jkhl.
No, vim has multiple modes. Those commands are when you're in navigation mode, which is the default mode. You should be in navigation mode most of the time (hitting ESC becomes a reflex). If you want to type, go into insert mode. There are many ways to go into insert mode depending on what you want to do, but "i" is the most straight forward.
Vim reference guide Quote
12-02-2015 , 02:06 AM
Oh also a must for any vim user: bind caps lock to esc
Vim reference guide Quote
12-02-2015 , 10:06 AM
maxtower, it's fine to say you don't like vim. I get that keyboard-centric editors aren't for everybody. But its silly to complain about keyboard-centric features in vim when that's its whole purpose.
Vim reference guide Quote
12-02-2015 , 12:27 PM
recording is a nice feature imo, I often open vim just to use it
Vim reference guide Quote
12-02-2015 , 12:57 PM
Quote:
Originally Posted by jjshabado
maxtower, it's fine to say you don't like vim. I get that keyboard-centric editors aren't for everybody. But its silly to complain about keyboard-centric features in vim when that's its whole purpose.
I agree. I am surprised how much people like it though given my bias.
Vim reference guide Quote
12-02-2015 , 01:02 PM
So I've read about effective study habits, and they have definitely helped me be more productive when reading for school and helped with retention immensely. (Or maybe I'm finally studying something I consider worth remembering)

I can't help wonder if there's some sort of similar divide between the keyboard and mouse versus keyboard-centric models of programming.

Namely, if what I have cobbled together as habit for programming could be improved in organization and efficiency if it was given a bit of intention and direction. Perhaps by refocusing on using keyboard only, but maybe just more generally speaking as well.

/thought
Vim reference guide Quote
12-02-2015 , 01:33 PM
Meh, one of the first thing I do when looking at a new editor-like thing is look for a vim plugin. It's just so much faster in most situations to use the keyboard for navigation.
Vim reference guide Quote
12-02-2015 , 02:09 PM
Quote:
Originally Posted by Noodle Wazlib
So I've read about effective study habits, and they have definitely helped me be more productive when reading for school and helped with retention immensely. (Or maybe I'm finally studying something I consider worth remembering)

I can't help wonder if there's some sort of similar divide between the keyboard and mouse versus keyboard-centric models of programming.

Namely, if what I have cobbled together as habit for programming could be improved in organization and efficiency if it was given a bit of intention and direction. Perhaps by refocusing on using keyboard only, but maybe just more generally speaking as well.

/thought
Obviously vim makes you more productive programming in certain languages. But what's talked less is how more enjoyable programming is with vim.

Vim makes programming even more enjoyable by killing all of the tedious parts of programming, e.g. if you have to copy and paste a line, instead of reaching for the mouse and dragging, pressing CTRL+c then CTRL+v, you just type yyp in vim. It's kinda addicting watching how much text manipulation can be performed with just a few keystrokes.

Programming is also more enjoyable when laying back in bed (especially during winter nights). I increase the font on my terminal and literally bring my keyboard with me to bed. This would be almost impossible without vim (and the keyboardr search engine and vimium chromium extension help too).
Vim reference guide Quote
12-02-2015 , 02:10 PM
Ok you guys convinced me to give vim a chance. I have a project that is best developed on a Linux system so I am giving it a go. I will report back soon.
Vim reference guide Quote
12-02-2015 , 04:21 PM
Quote:
Originally Posted by maxtower
I agree. I am surprised how much people like it though given my bias.
When I first saw some other (superior-to-vim) editor, I was shocked that anyone would want to program without a mouse or IDE. I think you have to give it an honest shot before you can judge it.

Yeah, it can be painful at first, but the payoff is worth it.
Vim reference guide Quote
12-02-2015 , 06:04 PM
Quote:
Originally Posted by blackize5
Oh also a must for any vim user: bind caps lock to esc
vim is unusable without doing this. I hit A,esc much more often than I hit $

I think a lot of people don't get vim because of this. Switching back and forth between insert and movement modes needs to be effortless or its not a net positive benefit.
Vim reference guide Quote
12-02-2015 , 06:09 PM
I can see where doing a lot of touch typing a text based editor is helpful. I am sure you can configure vim to do automated things you do on source files regularly. You can configure IDE editors too but vim probably is more custimizable than most I would think. I was able to setup a .vmrc file to customize a few things today. I am doing a lot compiling/assembling/linking from the command line for the project I am working on so vim fits in pretty well. One thing is that yeah the guides are fine but I am just using Google for the most part. Just google what I want to do and then take it from there.
Vim reference guide Quote
12-02-2015 , 06:23 PM
adios, that's the best way. One command at a time. Adds up quick.
Vim reference guide Quote

      
m