VI(M) is a very powerful editor which requires you to survive a learning period as it is different from almost any interface you have used before. If you survive, you will love it, if not you will hate it.
So lets us vi a file right now!
The first thing that whacks you in the face is that you cannot type text into your document! Why? VI has two modes:
1) command mode
2) edit mode
And you initially start in command mode. You can enter edit mode by pressing 'i'. Now you can type into the document. You can always get back to command mode by pressing escape. Back in command mode you can type :x to exit and save. That is the major hurdle that most people don't jump. There are plenty of good VIM documents on the web explaining basic usage to build on from there.
Here are some development specific tips once you are comfortable with VIM as an editor which make it far more productive than an IDE:
If you were recently editing but navigated away and want to go back to where you were, press u for undo then (ctr)r for redo.
This is 'repeat last command'
Suppose you called a variable 'notvalid' and then later decided you wanted it to be 'isvalid':
(searches forward for occurance of notvalid)
(change word - replaces notvalid with !isvalid)
(repeat last command - this will replace the notvalid we just found with !isvalid)
Of course you could also use a global search and replace:
Which is less typing, but I prefer to check each replace as I go, so the search and repeat is good for that. You can do very complex editing very quickly using this technique, just by putting a little thought into how to modify text in a repeatable way.
will build your project from within VIM. The advantage of this is that it will take you instantly to the line and file of any error that might occur in the build.
:cn and :cp can be used to move forward and backward through the error messages.
Customise your ~/.vimrc
This is what will transform VIM into a customised IDE.
Will do syntax highlighting
au BufReadPost * if line("'\"") > 0|if line("'\"") <= line("$")|exe("norm '\"")|else|exe "norm $"|endif|endif
Will remember the last line you were in when you lasted edited a file.
Is usually the easiest way to ensure tab size is irrelevant.
Will allow you to search for strings case-insensitive unless you use capitals. There are many more handy ones, look up the documentation and go nuts!
If you press this while over a brace, it will take you to the complimentary brace. This is a life saver if the code isn't formatted how you like it and you can't be sure what nest you are in.
Go to end of file
/(up) or %(up) or ?(up)
each time you press (up) it goes back to the previous string so you can modify it. (down) goes forward through the list.
insert at start of line
append at end of line,
just press (esc) after if you dont want to put any text in
Will copy 8 lines and paste it where you want it
Will delete 8 lines of code
Will move down 8 lines
I use this to measure how much I want to cut copy or delete.
Alternatively you can use visual select mode