Learning Vim
When I started working on my first PHP project at Inuits I had to decide which editor or IDE to use. Obviously while I was still working in the .NET-world I used Visual Studio, just as almost everybody else. However I also used jEdit at home for PHP, Ruby etc. I always felt that learning a general purpose editor, and learning it very well, is more interesting than learning an IDE for one specific platform (VS.NET in this case).
One of my new colleagues recommended me to use NetBeans for PHP development, so I had a look at it. While I'm sure it has a lot to offer, it just didn't feel like the tool I wanted to use. Obviously I had also installed jEdit. While I have always loved jEdit, somehow I wasn't convinced anymore. I also had a look at gEdit, which certainly has potential if you install some extra plugins and configure it, but compared to other editors and IDE's it seems to be rather limited. So then there was still that other editor. The editor which has fascinated me since at least 5 years. The editor which I have been using from time to time to make small edits on config files. The one editor which has a history which dates back to 1976. Yes, indeed, I'm talking about vi and it's modern incarnation vim (Vi IMproved).
As I already mentioned I had been using vi for at least 5 years to make small changes to config files, mostly over SSH on webservers, so I knew the basics. But the basics are, imho, just not enough to do some serious development. Therefore I decided to try and learn at least one new thing about vim everyday. Be it a new shortcut, a plugin, whatever. Reading an entire article with lots and lots of vim-shortcuts really isn't the best method to learn vim, because it's impossible to memorize them all at once.
However after using other editors and IDE's, such as VS.NET, for so many years, it is difficult to just start with vim, because it has a steep learning curve. By example, I got used to navigating code with the arrow keys, certainly in combination with the control and shift keys, to move the cursor by words and select text. Because I did not yet know the correct vim keys and learning them all at once is impossible I had to find a solution to ease my transition. I found this solution in the mswin.vim script which comes with vim by default. You can enable this script by placing the following lines in your .vimrc file:
source $VIMRUNTIME/mswin.vim
behave mswin
This script makes vim behave more like other text editors. It's Vim with bicycle training wheels. You will be able to select text by using the arrow-keys in combination with shift, copy and paste with <CTRL+C> and <CTRL+V>, save with <CTRL+S> etc. Sadly it also uses some bindings, like <CTRL+Y>, which have, by default in vim, a different function thus making those default commands unavailable. While this script is very useful, my goal has always been to learn the real vi-shortcuts so in the end it should be possible to disable the script. You don't keep your training wheels either do you? And a few days ago I learned how to copy/paste from the global clipboard, which I believe was the last shortcut I was missing, so as of yesterday I have disabled the script. Now I hope I don't crash on my face because of the missing wheels :).
Another nice trick I found is to change the color of the statusline depending on the current status. When I'm in normal mode, my statusline is gray, the default for the Mustang colorscheme. But while I'm in insert mode the statusline turns green. To configure this add the following lines to your .vimrc:
" first make sure the statusline is always shown
set laststatus=2
" then define two autocommands
au InsertEnter * hi StatusLine term=reverse guibg=#005000
au InsertLeave * hi StatusLine term=reverse guibg=#444444
Please not that this configuration only works for gVim, not the terminal version. But it is possible to adapt it for the terminal version as well.
Oh and just as a reference, here are some of the shortcuts I use to replace most of the shortcuts in other editors:
- w: move to the next word (replaces <CTRL+Right Arrow>)
- b: move to the previous word (replaces <CTRL+Left Arrow>)
- de: delete the next word (replaces <CTRL+DELETE>)
- db: delete the previous word (replaces <CTRL+BACKSPACE>)
- viw: select entire word (replaces <CTRL+SHIFT+Right Arrow>) Note: keep pressing 'w' to select additional words
- "+p: paste from the global clipboard (replaces <CTRL+V> in case you want to paste text from another application)
- "+y: copy to the global clipboard (replaces <CTRL+C> in case you want to copy text to another application)
- "+d: cut to the global clipboard (replaces <CTRL+X> in case you want to cut text to another application)
I'm also using some very useful plugins to help me code, and I have some nice config-settings in my .vimrc, but i'll show these in another blogpost.
Comments
There are no comments.