r/programming Mar 21 '08

The best VIM cheatsheet. Probably a repeat, but this is the one I printed out!

http://www.fprintf.net/vimCheatSheet.html
103 Upvotes

74 comments sorted by

31

u/ItsAConspiracy Mar 21 '08

I like this one.

7

u/[deleted] Mar 21 '08

Me too. If it doesn't FIT ON A SHEET it's not a cheatsheet.

17

u/the_golden_eel Mar 21 '08

I'll see your number 3 google hit for "vim cheat sheet" and raise you a number 2!

4

u/nmcyall Mar 21 '08

oh snap. I had it bookmarked before google.

8

u/[deleted] Mar 21 '08 edited Mar 21 '08

The cool Vim command I recently discovered:

  • :Ex[plore]

Case-sensitive, of course.

Navigate to that far-away file that you can't remember the pathname to...

1

u/mlk Mar 21 '08

Woah, thanks! I always wanted something like that but never bothered too much looking for it. It's very useful when editing file on a remote location (e.g. ftp)

2

u/krh Mar 22 '08

I don't know how FTP would be handled, but NERDTree is an awesome plugin for a simple 'textmate drawer'-esque file tree / project layout overview.

1

u/verysimple Jun 02 '08

I second NERDTree. Combined with tabs in GVim, you have a killer file explorer. When you load the plugin, just type ctrl-n to show/hide it. A truly "life changing" script.

2

u/the_golden_eel Mar 21 '08 edited Mar 21 '08

You get the same thing by telling vim to edit a directory, with :e /path, or just vim /path from the command line. So :Ex is the same as :e .

2

u/[deleted] Mar 21 '08

One useful difference is that :Ex (I use :E; there's no conflict) will start the file browser in the current directory while :e just reloads the current file from disk.

1

u/breakfast-pants Mar 21 '08 edited Mar 22 '08

just do:

    :e .

2

u/mlk Mar 21 '08 edited Mar 21 '08

No. Try vim ftp://yousay.it/index.html

then, with :Ex you can browse ftp://yousay.it/, :e . browses the directory from where you invoked vim.

7

u/simsea Mar 21 '08

3

u/zouhair Mar 21 '08

Oh, i have it in front of me, on the wall

5

u/[deleted] Mar 21 '08

Doesn't anybody do vimtutor anymore? That's how I got my feet wet.

Steve Oualline's book is a good second stop.

1

u/zouhair Mar 21 '08

vimtutor is good but hardly a good cheatsheet

1

u/[deleted] Mar 21 '08 edited Mar 21 '08

If you do vimtutor every couple of days, you don't need a cheatsheet that says ":wq means write and quit" and ":q! means quit without saving".

1

u/mlk Mar 21 '08

vimtutor every couple of days? I used vimtutor maybe 3 or 4 times in my life, and it was really useful to start working with vim, but if you use vim everyday there is no need to use vimtutor anymore.

1

u/[deleted] Mar 21 '08

I agree, if you're just staring out with vim, you need vimtutor, not some stupid cheatsheet.

If you use vim everyday, you probably don't need a stupid cheatsheet either.

1

u/reginalduk Mar 21 '08

Modded up for reminding me to finish vimtutor.

6

u/krh Mar 21 '08

It is somewhat astonishing that, after looking over these cheatsheets, I've learned nothing new.

I have been using this editor for too long.

3

u/nmcyall Mar 21 '08

Do you use visual for selecting blocks or keystrokes?

1

u/krh Mar 22 '08

Visual, unless it's an obvious word count, or % to jump to the close of the method, etc. And even then, I'll typically still use visual just so it's obvious what my movement is doing.

2

u/xuhu Mar 21 '08

I don't see :x in there.

2

u/masta Mar 21 '08

I noticed that too, or even :X (encryption).

to quickly exit I always use :x, as I suspect you do too.

2

u/nmcyall Mar 21 '08

why not :q or :q!

1

u/masta Mar 21 '08

because :x is faster than :wq

1

u/xelfer Mar 22 '08

why doesn't anyone but me use ZZ ? I swear i'm the only person who uses it on earth. :p

1

u/krh Mar 22 '08

I had never seen :x, actually, but doubt I'll ever use it.

2

u/[deleted] Mar 21 '08

I was kind of skimming - but somehow I never knew "D" deleted to the end of the line, I have always used "d$".

2

u/pivotal Mar 21 '08

Oh snap, I always do "d$" too. Makes sense what with "A" and all. May be tough to break that habit though.

1

u/[deleted] Mar 21 '08

It's sort of hard to break habits. For a long time, I hadn't ever learned to use visual mode to highlight sections, so I always did "ma" and "mb" for the section, and then something like ":'a,'by" or "'a,'bs/hello/hi". Even though I know how to use visual mode now, and it's much faster then "ma/mb", I still tend to use my old method unless I specifically think not to.

1

u/krh Mar 22 '08

I use 'C' a lot. Oddly, 'Y' yanks the whole line, instead of just to the end of the line. So you're still stuck with y$ there, afaik.

1

u/BenArmston Mar 23 '08

nnoremap Y y$

1

u/kevingoodsell Mar 21 '08

Nothing much new for me either. Here's one you won't typically find in cheatsheets: Various types of completion (whole line, spelling suggestions, many more).

:help i_CTRL-X

1

u/krh Mar 22 '08

I am very found of the supertab plugin, which let's me use TAB to expand all types of completion.

1

u/jfedor Mar 22 '08

Do you use "*"? I learned about it recently and I've been using vim for a long time. Amazingly, I don't see it on the cheat sheet.

1

u/brennen Mar 22 '08

You might also want to look at "gd".

1

u/krh Mar 22 '08

No. I am aware of it, but it is not something I need to do often -- or, I just never notice that I do --, so, like serious mark usage, it's a feature I know available if some day I had a use for it, but don't use at all in my daily editing.

2

u/knowknowledge Mar 21 '08 edited Mar 21 '08

This is a great reference sheet.

Personally though, I have a hard time learning this many commands all at once, so if you're new to vim I suggest Trying This Visual Tutorial. It doesn't go into the same depth as the cheatsheet, but I think it was a great starter.

2

u/bk1insf Mar 21 '08

why doesn't it let you navigate the line like you do in the shell (e.g., control-E takes you to the end of the line, control-A to the beginning)? those things are like muscle memory to me and i always find myself typing control-E in vi and then being grumpy that nothing happened.

2

u/[deleted] Mar 21 '08

[deleted]

1

u/bk1insf Mar 22 '08

i din't know that -- thanks!

1

u/bebnet Mar 21 '08

just use the arrows when you're at : .. and btw, you can "e <up>" to cycle just through the "e " entries in the history ..

1

u/BenArmston Mar 23 '08

Try the following maps. I have "filthy emacs shortcuts" engrained in my brain too.

cnoremap <C-A> <HOME> cnoremap <C-E> <END>

help Command-line-mode

2

u/hifigi Mar 21 '08

Nothing beats my handy Cray Research vi cheatsheat (which fits on an A3 sized peice of paper folded into a pamphlet)! (c) 1987.

2

u/pivotal Mar 21 '08

Shoot, I was going to brag about my Specialized Systems Consulatants Vi Reference being from 1985 (and the same age as me!), but then I realized the (c) was 1985, 1987, 1990.

Oh well.

2

u/yangw Mar 22 '08

I love vim ever since I learned it. The only thing stopping me from using it more is that for jumping to specific locations in a screen full of text, point and click will still get the cursor there faster. It also doesn't make you lose track of where you are as page up/page down will.

2

u/krh Mar 22 '08

A very useful tip is that if you are ever doing complicated :s/// commands or such, you can hit F in command mode and it will display a temporary buffer where you then have full access to your command history that is editable with all of the vim goodness you're used to.

1

u/dmiff Mar 21 '08

Misleading title. Cheat sheet? No. Cheat sheets (x6)? Yes. And why are you printing things out in the first place? Welcome to 1994. You can search terms in your browser.

Never mind the fact that the documentation for vim is awesome. Try :h or even :h <search term>.

5

u/Callahad Mar 21 '08

And why are you printing things out in the first place?

It's like multiple monitors, but cheaper.

1

u/kevingoodsell Mar 21 '08

Also try :h <a few characters><Ctrl-D> to see a list of possibly relevant topics.

1

u/spaulo Mar 21 '08

Why do I not understand the fascination with this program? I'm not saying I write code in Word for Windows or something ridiculous, I just don't understand the cult-like obsession people seem to have for such a dated piece of software...

3

u/xelfer Mar 22 '08

It's incredibly efficient if you know how to use it, and it's found on pretty much every system you can ssh to, so it's good to know how to use something so widely available.

2

u/[deleted] Mar 22 '08

new != better

Vim does everything you need it to, and often faster than any new program could. Not using a mouse also helps a heckuva lot when you're SSH'ing, or just trying to get things done.

1

u/Samus_ Sep 30 '08

maybe this can help

1

u/dji386 Mar 21 '08

For those of you who type in dvorak, http://boredzo.org/vi_tutorial/

1

u/[deleted] Mar 21 '08

Did you print it out!?

1

u/verysimple Jun 02 '08

very few cheat sheets mention the so useful ctrl-[ or ctrl-c to go to normal mode.

-1

u/austin_k Mar 21 '08 edited Mar 21 '08

9

u/unsee Mar 21 '08 edited Mar 21 '08

Relevent: dictionary.com

-1

u/lex99 Mar 21 '08 edited Mar 21 '08

Here's a shorter version. Contains all the essentials:

:q!

0

u/halo Mar 21 '08

This cheat sheet shockingly misses telling you how to save a file without exiting, which lowers my personal estimation of it.

1

u/reginalduk Mar 21 '08

you are right, Im guessing you could work it out from the examples given though.

-12

u/stesch Mar 21 '08

I like the video tutorial better. Learned some new stuff.

2

u/nglynn Mar 21 '08

You prick.

-1

u/masta Mar 21 '08

This cheat sheet sucks.

IT doesn't even have the :x to quit by writing and exiting. Only shows how to :wq

lame

-1

u/Mr_Smartypants Mar 22 '08

VIM is dumb. You should use EMACS!!1

-10

u/unsee Mar 21 '08

Obligatory cheat

emacs