Vim Quick Reference
Wednesday, December 27, 2006
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!) |
May 2nd, 2007 at 8:16 pm
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.
June 28th, 2007 at 1:49 am
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
July 23rd, 2007 at 8:44 am
‘D’ is useful: delete to end of line.
December 5th, 2007 at 12:49 pm
kjlk kjlkj
April 12th, 2008 at 6:07 pm
This is one of the best vi guides I’ve seen. It made me smile and remember too!
May 11th, 2008 at 5:38 am
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.
September 8th, 2008 at 3:12 am
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 ;-)
December 29th, 2008 at 10:59 pm
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
February 24th, 2009 at 3:22 am
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.
February 24th, 2009 at 3:24 am
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!
March 6th, 2009 at 6:39 am
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
March 7th, 2009 at 3:05 am
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.
May 15th, 2009 at 3:39 pm
So cute!
June 23rd, 2009 at 4:38 am
Hello, welcome to Yiwu city.