Reputation: 2366
I'm a Ruby programming trying to switch from Textmate to MacVim, and I'm having trouble wading through the gargantuan lists of things you can do in VIM and all of the keypresses for them. I'm tired of hearing "You can use 'I' for inserting text, or 'a' for appending text after the character, or 'A' for appending text at the end of the line, or…" I can't imagine everyone uses all 20 different keypresses to navigate text, 10 or so keys to start adding text, and 18 ways to visually select an inner block. Or do you!?
My ideal cheat sheet would be the 30-40 most-used keypresses or commands that everyone uses for writing code on a daily basis, along with the absolute essential plugins that rubyists use daily and the 10 most-used commands for them. In theory, once I have that and start becoming as proficient in VIM as I am in Textmate, then I can start learning the thousands of other VIM commands that will make me more efficient.
Or, am I learning VIM the wrong way altogether?
Upvotes: 148
Views: 148660
Reputation: 994629
Here's a tip sheet I wrote up once, with the commands I actually use regularly:
<Esc>
gets you out of any mode and back to command modeAll insertion commands are terminated with <Esc>
to return to command mode.
<motion>
changes text in the direction of the motion<motion>
deletes in the direction of the motionname
write file to disk as name
tags
file); ^T return to previous position (arbitrary stack of positions maintained)Vim has some features that make it easy to highlight lines that have been changed from a base version in source control. I have created a small vim script that makes this easy: http://github.com/ghewgill/vim-scmdiff
Upvotes: 374
Reputation: 245
Put this in your .bashrc to open vim with last edited file at last edited line
alias vil="vim +\"'\"0"
Upvotes: 1
Reputation: 857
Go to Efficient Editing with vim and learn what you need to get started. Not everything on that page is essential starting off, so cherry pick what you want.
From there, use vim for everything. "hjkl", "y", and "p" will get you a long way, even if it's not the most efficient way. When you come up against a task for which you don't know the magic key to do it efficiently (or at all), and you find yourself doing it more than a few times, go look it up. Little by little it will become second nature.
I found vim daunting many moons ago (back when it didn't have the "m" on the end), but it only took about a week of steady use to get efficient. I still find it the quickest editor in which to get stuff done.
Upvotes: 2
Reputation: 196876
@Greg Hewgill's cheatsheet is very good. I started my switch from TextMate a few months ago. Now I'm as productive as I was with TM and constantly amazed by Vim's power.
Here is how I switched. Maybe it can be useful to you.
Grosso modo, I don't think it's a good idea to do a radical switch. Vim is very different and it's best to go progressively.
And to answer your subquestion, yes, I use all of iaIAoO
everyday to enter insert mode. It certainly seems weird at first but you don't really think about it after a while.
Some commands incredibly useful for any programming related tasks:
r
and R
to replace characters<C-a>
and <C-x>
to increase and decrease numberscit
to change the content of an HTML tag, and its variants (cat
, dit
, dat
, ci(
, etc.)<C-x><C-o>
(mapped to ,,
) for omnicompletion<C-v>
Once you are accustomed to the Vim way it becomes really hard to not hit o
or x
all the time when editing text in some other editor or textfield.
Upvotes: 3
Reputation: 160621
Have you run through Vim's built-in tutorial? If not, drop to the command-line and type vimtutor
. It's a great way to learn the initial commands.
Vim has an incredible amount of flexibility and power and, if you're like most vim users, you'll learn a lot of new commands and forget old ones, then relearn them. The built-in help is good and worthy of periodic browsing to learn new stuff.
There are several good FAQs and cheatsheets for vim on the internet. I'd recommend searching for vim + faq
and vim + cheatsheet
. Cheat-Sheets.org#vim is a good source, as is Vim Tips wiki.
Upvotes: 4
Reputation: 49128
What most people do is start out with the bare basics, like maybe i, yw, yy, and p. You can continue to use arrow keys to move around, selecting text with the mouse, using the menus, etc. Then when something is slowing you down, you look up the faster way to do it, and gradually add more and more commands. You might learn one new command per day for a while, then it will trickle to one per week. You'll feel fairly productive in a month. After a year you will have a pretty solid repertoire, and after 2-3 years you won't even consciously think what your fingers are typing, and it will look weird if you have to spell it out for someone. I learned vi in 1993 and still pick up 2 or 3 new commands a year.
Upvotes: 3
Reputation: 13927
tuxfiles.org holds a pretty good cheat sheet. I think there are a couple of points to learning the commands:
d$
), go a quick google search to see if you can find a command for it.Besides these tips, there are some basic concepts you should understand.
d$
. To highlight a line after a particular character use v$
. So notice that $
indicates you will be doing something to the end of the line from where your cursor currently is.u
is undo, and ctrl+r
is redo.3dd
will delete the line your cursor is on and the two lines that follow, similarly 3yy
will copy the line your cursor is on and the two lines that follow.:ls
to list the buffers, and :bn
, :bp
to cycle through them.:help
This is probably the best way to 'learn the ropes', and the rest of the commands you will learn through usage.Upvotes: 3
Reputation: 1867
I can't imagine everyone uses all 20 different keypresses to navigate text, 10 or so keys to start adding text, and 18 ways to visually select an inner block. Or do you!?
I do.
In theory, once I have that and start becoming as proficient in VIM as I am in Textmate, then I can start learning the thousands of other VIM commands that will make me more efficient.
That's the right way to do it. Start with basic commands and then pick up ones that improve your productivity. I like following this blog for tips on how to improve my productivity with vim.
Upvotes: 2
Reputation: 5848
http://www.viemu.com/a_vi_vim_graphical_cheat_sheet_tutorial.html
This is the greatest thing ever for learning VIM.
Upvotes: 25