A while ago Dave Flanders asked me to blog about more interesting things like “libraries, frameworks an development evironments”. So i looked at that list and thought ” where can I give the reader the most bang for their buck”. The answer was development environments. I’ve used a few IDEs in my time. Eclipse, NetBeans, Visual Studio, Borland C++, Turbo Pacal and i have found most of them to be reasonable, more or less usuable and often a touch bloated. In the last few years i have got to grips with a development evironment that rips the pants off those others. So today im going to tell you about my development evironment; Vim.
Vim or Vi is full screen command line text editor. To those of you unfamiliar with the concept that means it’s text based and controlled only by the keyboard. Why is Vim good? most programming languages with the exeption of a few really grizzley microsoft ones like Visual basic and visual foxpro store their source files as text. This means you can edit them with any text editor e.g notepad or Vim. For web app development this is perfect. Vim edit your source files, save and press refresh and bingo you can see your changes right there. What Vim offered me was a way out. It meant that every time i wanted to use a new language that would often just do some modifications in or use very little i didnt need a whole new editor. I didnt have to waste time working out what all the keyboard short cuts and so forth were because they were the same what ever language i was writing in.
The one quirk of Vim which puts most people off is that it isnt like any other editor. It has modes. The two common modes are Normal mode and Insert mode. In normal most of the letter keys provide shortcuts to do other things e.g. dd is delete line. :w is write (save). i is enter insert mode. In insert mode you type as you would in say notepad or another editor and press esc to return to normal mode.
Normal mode means Vim has a vast about of keybindings available to it. Keys can also be strung together. As discussed above dd is delete is delete line, 3dd is delete 3 lines, dw is delete the word under the cursor. once deleted (or yanked [copy] use y) these things go into a buffer. From the buffer you can do many things. u (undo) to put it back, p (put) to put (paste) it somewhere new. So far nothing i have told you is news. Source is text, editors edit text, this edit lets you move around the document deleting copying and pasting stuff. Big whoop… now for some really good stuff:
di” – delete everything inside the quotes im in.
da) – delete eveything in the brackets in including the brackets
any combination off di or da and any piece of paired punctuation ),},”,], etc
~ – change the case of everthing selected
# – find the next instance of the word the cursor is on in the text
:s/regex/repace/ – regex substituions
Vim also gives you syntax highlighting for every different programming language under the sun and auto complete for lots of lanugages most of which is much more advanced than you would get in any IDE (even eclipse). Its installed on almost every server (except windows ones but you can still get Vim for windows) this means if you at a confernce/business trip/the pub and someone says “hey ive found a bug” or “it would be cool if your code did this”. you say “lend me your laptop” and ssh to your server make your changes and show them straight away. Not say “ill email you when i get back to the office”. This gets you big props.
But the best thing of all is that Vi looks hard. both hard as in difficult to learn (making you look clever) and hard as in kill an entire SWAT team with your bear hands (making people think you mean business). It still gives me a kick everytime i do something a bit nifty in Vim, while i watch Marcus across the bay fumbling for the mouse. Have a google around and find out about Vim. It’s a really steep learning curve but once you get over that youll never look back.