Vim Quick Reference

I often use vim as the editor when I’m connecting to my hosting
provider…. so I figured I’d put the most common tasks up
here, since I can never remember some of these.

Open /
Save / Exit
:w Save File
:q Quit
:q! Really quit, don’t just talk about it.
:wq Quit, but save first, cause who really wants to do
something in vim more than once?
:x Pretty much the same as the above, but it doesn’t save
if you don’t need to. This makes more sense, and it’s one keystroke
shorter.
ESC Go back to command mode
 
Navigating
/ Edit
So this is where the gmail keys came from!
j Up one line
k Down one line
l right
h left
e end of the world. I mean word.
b beginning of the word.
0 Beginning of a line
$ End of a line
H kinda like Home, takes you to the top left
L also means loser, takes you to the bottom of the screen.
:88 takes you to line #88. Don’t try this with any line
other than 88.
i insert text. This is one of the only keys you need to
know.
x delete the character you are standing on. This is the
other character you really need to know.
cw delete the current word and start inserting. means “Change Word”. Thanks Quinn!
r overwrite a single character. I like this one.
R replace lots of characters.
o Make a new line below and start insert mode
O Make a new line above and start insert mode
a append right here. You’ll probably use i more.
A Appends at the end of the line. I use this a lot.
dd delete the entire line.
9dd delete 9 lines. This only works for 9 lines. You
couldn’t say, use this to delete 8 lines by doing ‘8dd’. No way would
that work.
yy yank the current line to the clipboard, or
whatever they call it in vim terms.
5y yank 5 lines to the clipboard.
p paste the line you just yanked.
u Undo. This app actually has undo? very cool.
/pattern search for the pattern “pattern” Kinda redundant
example.
n Works like F3 does in windows, takes you to the next
search result.
N works like F3 doesn’t in windows, and takes you to the
previous search result.
%s/stuff/toreplace/g Replace stuff with toreplace everywhere in the file.
G Go to the end of the file (thanks Q!)

14 Responses to “Vim Quick Reference”

  1. pete Says:

    Some more vim commands I use often:

    - An alternate to ‘n’ is to just type ‘/’ again to move to the next search result.
    - ‘?’ also takes you to the previous search result (or searches backwards if you prefer to think of it that way).
    - CTRL-R is the command for redo (or undo undo).
    - At the command prompt (the ‘:’ thingy), type ‘!’ and then a bash command to see the output in a shell window (there’s a command to insert the output of that shell command, but I can’t remember it right now).
    - ‘J’ joins the current line with the next one (comes in more handy than you’d think).
    - In addition to just doing a %s/…/…/ search and replace, you can do line ranges. ‘.’ means the first line of the program, ‘$’ means the last line, and a number is that line number. So you can do .,8s/…/…/, or 15,$s/…/…/, or even .,$s/…/…/ if you’re feeling silly.
    - In addition to ‘g’ after a search and replace, there’s ‘c’ which will make vim ask your permission for each replacement, and ‘i’ which will do a case-insensitive search. There’s probably others I don’t know about.

  2. Gert Van Gool Says:

    In addition to Pete:
    just s/…/…/ replaces on the current line, adding a g (%s/…/…/g) replace multiple items on the same line

    Extra:
    - If you edit a lot of source code: ‘gf’ to open the file under the cursor
    - When the cursor is on a (, ), [, ], { or }, press % to go to the matching opening or closing bracket

  3. johnnygri Says:

    ‘D’ is useful: delete to end of line.

  4. jkj Says:

    kjlk kjlkj

  5. Barney Says:

    This is one of the best vi guides I’ve seen. It made me smile and remember too!

  6. Natasna Says:

    nice

    I have found two interesting sources and would like to give the benefit of my experience to you.
    I am tuning my pc by the best software for free, with the file search engine http://fileshunt.com and http://filesfinds.com May be you have your own experience and could give some useful sites too. Because this two social sites help me much.

  7. Fuujuhi Says:

    Very nice guide! I notice a very small mistake, I think. Yanking 5 lines is actually ‘5yy’, not ‘5y’. But I’m still looking how we can yank 4 lines ;-)

  8. Electronic Cigarette Says:

    The Slider Controls let you provide a more dynamic method for selecting from within a range of values. When using this control, make sure that the javascript is below the html elements that you are using for the sliders.
    China suppliers http://www.soundasia.com
    LV handbag wholesale http://www.my-pursemall.com

  9. China Wholesale Electronics Says:

    Dashshopping is a leading world-wide wholesaler company. We supply high-quality consumer Electronics and China famous brand name products, all at wholesale prices. There is NO minimum order amount.You can try our first class services by initially making small quantity orders. All of our merchandises can be initially purchased in single units as a retail product and also at Wholesale prices. Buy larger amounts and receive discounts and cheaper prices.

    Wholesale Consumer Electronics, China Cell Phones, Wholesale Mobile Phones, Digital Cameras, Car Audio, Digital Camcorders, Car Electronics, MP3 Players, Bluetooth Products, MP4 Players, MP5 Players, Digital Picture Frames, Portable DVD Players and Electronic Gadgets from China.

  10. Chinese Cell Phone Says:

    Buy Cheap and high-quality chinese cell phone from Chinese Wholesale:http://www.dashshopping.com/.

    Find Unlocked Cell Phone and Cheap Cell Phone? We provide fashionable and stylish cell phones at discount price. Wholesale cell phones, buy cell phones, enjoy brand and multi function cell phone now!

  11. Scott Zrubek Says:

    To yank into a buffer so that you can take some line from one file and paste them into another is:

    “a5yy

    That puts 5 lines into buffer a

    Edit the next file and

    “ap

    Will put the lines in buffer a into the current file

  12. Movie Download Says:

    I’ve been looking for some files for further using Suddenly I found myself on sharesdigger.com and was surprised by it’s benefit. Really useful recourse, everybody should try it.

  13. online film izle Says:

    So cute!

  14. yiwu Says:

    Hello, welcome to Yiwu city.

Leave a Reply