I’m a “Vim”:http://www.vim.org user. Over the many years there has been a “war” between Emacs and Vi users. I know a little Emacs (it was the first unix editor I learned) and later learned some Vi. Why I learned Vi? Simple, every unix flavoured system has it installed. So if you want to edit a file quickly without installing additional software you have to know some Vi.
“Vim”:http://www.vim.org stands for Vi improved, so it’s an improved version of the original Vi. Vim is free and available for most platforms (including Linux, FreeBSD, Windows and OS X). Vim adds many features too the original Vi, such as syntax highlighting, frames (split your screen into multiple “windows” so you can edit multiple files simultaneously), code completion (Ctrl+p in edit mode) and much, much more. “This is a nice Vim free Vim book”:http://www.truth.sk/vim/vimbook-OPL.pdf.
The problem with Vim and Vi aswell is that the learning curve is amazingly steep. When you are in Vi and don’t know it, you probably won’t even be able to type any text or even how to exit it (use “:q!”). This is because Vi uses modes, Vi has three (command mode, insert mode and the less used ex mode) and Vim has four (additionally it has visual mode). When Vi starts you’re in command mode by default in this mode you can use ‘h’, ‘j’, ‘l’ and ‘k’ to move the cursor around and other keys to do other stuff. When you press for example ‘i’ you’ll enter insert mode, this mode will just allow you to type text. You can always return to command mode by using Esc. Anyway, I don’t intend to explain Vi right now, “Vi for smarties”:http://www.jerrywang.net/vi/ is a nice tutorial that will learn you the basics.
Here’s GVim (the GUI version of Vim) in action:
Some features of Vim that I like:
* *Code completion*, when you type a part of a word and then press Ctrl+p it will try to complete it by matching with other words in that same file or other open files, pressing Ctrl+p multiple times will switch between different completion possibilities
* *Code highlighting*, Vim by default includes code highlighting for an amazing amount of languages and config file types (over 300), it can also do code reformatting (to reformat a whole file use “mm1GVG=`m”, obviously)
* *The dot key*, when pressing the dot (“.”) in command mode it will automatically apply the previous command you executed, which can speed up your editting a lot when you know when to use it
* *No mouse necessary*, when I use vim I _never_ use my mouse.
* *Search as you type*, when you set your settings right you can start searching by using ‘/’ and start typing (Emacs supports this by using Ctrl+s).
* *Macros*, it’s very easy to define a macro which you can then repeat multiple times.
* *x p*, it’s very common that you make typing mistakes like “tihs”, if you want to swap the ‘i’ and the ‘h’ in that word you move your cursor to the ‘i’ in “tihs” and type “xp”. The two characters are swapped, simple as that.
* *c w*, which replaces the (rest of) the word your cursor is in and puts you in insert mode. You’d say, “when would I need that?” I use it all the time.
Want to learn Vim? Remember that you’ll have a hard time being productive at first, it might take months before you start to find the tricks that improve your productivity (and I recommend reading the “Vim book”:http://www.truth.sk/vim/vimbook-OPL.pdf I mentioned earlier to discover them). Good luck to you.
As an additional treat, “here’s my .vimrc file”:/upload/_vimrc (which you can place in your home directory).