editors, guis, mice oh my

Someone asked me to blog about vi so here goes. He was probably only interested in my vimrc and maybe some vi tips. My vimrc is at the end so you can skip past my rantings if you wish.

I’ll spare you the old timer lecture on how awesome vi or emacs is and why you’re less than a real engineer for not using it. Rather I’ll suggest why you ought to be using a powerful editor and that you ought to be working on becoming an expert with it. And how you’re coding may be suffering because of using a weak editor, or from not being expertly proficient with a powerful editor.

The point is that I’m not going to preach that vi or emacs is the only editor you should be using. There maybe be hundreds of editors for all I know that, while they probably can’t come close to vi much less emacs, they may well be good enough for a person at a given time. Plus vi and emacs come along with their own set of baggage.

I still call it vi (correctly, that’s two syllables “v” “eye”) and always will. Most software is improved over time without having to add “m” to the end of it’s name. /bin/vi and /usr/bin/vim are separate binaries but if you notice the remaining /bin/vi is actually vim (albeit a much smaller, restricted version intended for single user mode). So when I say vi I’m talking about the vim that you are talking about.

Also I’d be remiss if while talking about vi I didn’t also discuss emacs, IDEs and the mouse and command line vs gui here.

As a software developer or software engineer you need to be able to sling the code around with great precision and speed. You need to be able to use powerful editor functionality very quickly. You need to be able to repeat mods many times through a file, across files, across directories, very quickly and accurately. You need to be able to save macros of common chores and be able to invoke them with a simple key chord. For instance I have vi macros to comment out code based upon the file extension currently being edited (perl/bash uses #s where as C++ and php files get //s all with the same key chord aka ctrl-x and ctrl-y to remove).

Your editor must have regular expression search and replace or you should close it right now and never open it again.

You need to have navigation by byte, word, line, sentence, block, page, {} and () matching.

You need to be able to set marks or bookmarks in your file(s) and be able to easily and quickly navigate to them.

You need to be able to undo/redo them quickly in a slightly different way. You need to be able to read in a chunk of code from another file right at a certain spot in the current file. You need to be able to capture the output of a command and paste it into your program quickly.

You need to be able to do all these things quickly, easily, accurately without thinking about it and usually without touching the mouse.

You need to be able to quickly do these things, try out some code, write and run a quick little test. My dirs are littered with short little test.sh’s, test.pl’s, test.c’s, test.cpp’s all over the place where I was doing a quick test or making sure how something works.

I’ve seen people while coding, think that a little code change is too big to try out, or to much editing to be worth the effort, or that it would just take too long to bang it out to be worth the test. That is a serious limitation and impedes your ability to produce good quality code. If you find yourself in that situation then I suggest you consider dedicating regular time towards advancing your editor skills. Powerful tools can be exactly that, very powerful and allow you to sling, toss, juggle and spin code around like no tomorrow. But that power doesn’t come for free. You have to learn how to use a powerful editor.

Maybe you play a musical instrument. If you’re any good at it then you know very well how much practice it took to get there. IMHO you should consider code editing as a skill set that you need to master. You’re not going to master the guitar or an editor in a weekend. It’s something that takes a long time and a lot of practice.

That’s not to say that you can’t get up to a functional proficiency in a short time period. Nor am I actually comparing the skills and talent of a virtuoso cellist to a vi master. (emacs would be different :-) Find some good tutorials, dedicate some regular time to it and before long you’re over the hump.

IDEs can be awesome, can be very useful and powerful. They excel at certain things like source browsing and debug stepping through source. What they often lack is a powerful editor. vi is a very powerful editor but emacs is a universe unto itself.

I’m not saying which editor/IDE you should use. I’m just saying hey, make sure it’s a good one.

<emacs is awesome rant> Emacs is IDE, editor, shell, OS, debugger, source browser, web browser, media browser and player, kitchen sink and the whole mansion, and all the elements of the periodic table rolled into one, and older than dirt with salt and/or sugar on top and a beer and whiskey back if you want it. If you ever have the opportunity to watch someone who really knows emacs, try to sit and watch them work for a few minutes. If you’re not careful you’ll be bitten. There’s probably some videos out there. </emacs is awesome rant>

But the most attractive thing about IDEs is their ease of use for beginners. Same situation for GUIs and the mouse. They’re all very attractive to, intuitive and easy for the new user. But they can get in the way of a power user. Advanced skill sets are hindered by the mouse. I have always made a point to learn and know plenty of keyboard shortcuts for the various desktops (Win, Mac, Linux) in order to avoid reaching over to the mouse. This may sound silly or trivial to some. But anytime you can use a key chord instead of reaching for the mouse you’re saving yourself time and effort. I’m not saying the mouse should go away. Not at all. There are many functions that are better served by the mouse or other pointing devices, like drawing for instance. And as I said, new users and most people for that matter need never advance beyond using a mouse and GUIs, and now touchscreens, thx Steve.

But as a top notch hot shot code slinger if you don’t see the value in powerful editors and command line skills then IMHO you might not be as hot as you think.

A favorite quote:

Linux supports the notion of a command line or a shell for the same reason that only children read books with only pictures in them.

Language, be it English or something else, is the only tool flexible enough to accomplish a sufficiently broad range of tasks.

Bill Garrett

and a word about why you should learn the shell

My idea for a better keyboard

My vimrc file. Of note is the auto backup. Every time I invoke vi on any file it makes a backup copy of it for me.
http://1mikemakuch.com/tmp/vimrc.html

A nice vi cheat sheet. This guy makes a vi plugin for MS Visual Studio which converts MSVS into a truly powerful IDE! :-)
http://www.viemu.com/a_vi_vim_graphical_cheat_sheet_tutorial.html

http://en.wikipedia.org/wiki/Editor_war

http://www.catswhocode.com/blog/100-vim-commands-every-programmer-should-know

Interesting thread about emacs:
http://edward.oconnor.cx/2009/07/learn-emacs-in-ten-years