A Starting Guide to VIM from Textmate
blog.danielfischer.com
blog.danielfischer.com
With Monaco 13 typeface it's bliss.
One thing I'm surprised nobody ever mentions is the ! command.
If I'm working on a file and I want to, say, commit my work, I can do
:!git commit -a -m "committing my changes"
I used to do this a lot when working with Oracle and Bash. It's much quicker than opening another terminal for one-off commands.drops you into a shell
Very handy.
:q
i
ESC
:w
After I learned those, I've really come to love Vim. I imagine I'd need to learn about 50 more commands before I could be really well versed. What are some other important things to know?
http://tnerual.eriogerg.free.fr/vimqrc.html http://www.pixelbeat.org/vim.tips.html http://www.rayninfo.co.uk/vimtips.html
I'd start with looking at commands that allow you to quickly move around in buffers first (/, f, t, w, e, b etc). Then start combining those with actions (ct", dw etc). Then "timesavers" such as macros and built-in conveniences (q, gqq, marks etc). The rest will come to you.
:map * ddp
Then type * in command mode to execute the steps.
And if you mangle your file beyond hope with out of control macros, there's always u to undo and :q! to quit without saving.
Why not do a 'qq' to record your macro as 'q' and @q to replay it.
I and A insert beginning/end of line.
0 and $ go to the beginning/end of line without entering insert mode.
:%!command -- Runs the entire document through the command. If you use visual mode and then press ':!command' and it will run the selection through the command specified. Super useful for sorting a list.
Also ctrl+[ is equivalent to esc. If you rebind caps to ctrl you can easily hit escape and other commands like ^d, ^u (page down and up).
You might find ^ more useful than 0 for indented code as it takes you to the beginning of the text on the line (like the regexp).
I also find that selecting large blocks of text then using the = command to autoindent everything is exceedingly useful.
> Super useful for sorting a list.
Unless you have some special script/filter for specific sorting of lists, then why not just use ':sort' instead of ':!sort' (i.e. the Vim sort command, rather than piping it to /usr/bin/sort)?If you really want to get on a roll with vi, think of all the other cases where you wish it could do something, then make it work with :%!command_written_in_any_language_you_want .
You can also apply it to ranges. "%1,5!rev" reverses lines 1-5, etc.
Being able to pipe through commands is a powerful tool, but using an example where the external command already has a built-in equivalent seems possibly confusing to the (novice Vim'er) reader (please don't rattle me off the laundry list of options that /usr/bin/sort has that :sort doesn't because you'd be missing the point).
That said... On the topic of ranges, never give :bd! a range unless you know what you're doing. I ran :bd! once while I had a number of lines selected in visual mode because I though that the selected lines wouldn't affect :bd. Bad idea. The '<,>' part of the range apparently is converted to line numbers (e.g. '3,6') and then :bd reads that range as the buffers to delete. So when you select lines 1-8 and then hit :bd! it goes something like this:
:<,>bd! -> :1,8bd! -> delete buffers 1-8 without prompting for unsaved changes
Oops!ctrl-[ can be used in place of ESC
. repeats the last edit
Would be interesting to know why. What made you switch from TextMate to VIM?
imap <silent> ii <Esc>:let &insermode=0<CR>
This doesn't work so well if you are frequently editing files on multiple servers you can't edit the .vimrc file on. But for your local environment it'll make going in and out of insert mode a lot more efficient.
I'm dead used to using ii now so I'm probably not going to switch, but others have pointed out kk may be a better choice, due to greater distance between keystrokes/mode. Indeed, about one in ten times I hit ii when I don't need to.
But I think you're right with "Vim", since even on vim.org it's spelled like that.