Editors for coding?

So today’s post begins with a ques­tion: what edi­tor is your favourite? Do you have sep­a­rate edi­tors based on dif­fer­ent con­texts (eg. Net­beans for Java, Dreamweaver for sites), or do you tend to stick to a sin­gle Man Fri­day to ful­fill all your needs? Do you pre­fer IDEs or sim­ple text editors?

My answer for the above questions:

I love gVIM (graph­i­cal VIM). I’ve set it up to work over SSH in Win­dows (I work on a dif­fer­ent box and merely use my lap­top as a con­ve­nient inter­face), hid­den all menu bars and installed a colour theme pack of which I’m cur­rently using “Evening”. And I’ve started using VIM for every code related task I do. In defence of my choice, allow me to intro­duce some of the basic func­tion­al­ity included in VIM and some prac­ti­cal use cases: (Not intended as a tuto­r­ial, but a quick glimpse at the great func­tion­al­ity on offer)

  1. Sim­ple Edit­ing
    Typo­graph­i­cal errors are the programmer’s bane. And if they’re not shown as errors (occa­sion­ally the case with var­i­ous Javascript libraries), life becomes hell. Quick cor­rec­tion options in vim:

    • dw, dd, etc. Basi­cally, both for delet­ing and cut­ting text. dw deletes till the end of the line. d2w deletes 2 words. dd deletes the cur­rent line. Enter­ing %d on the com­mand line (i.e. using : ) deletes the full file. D deletes until the end of the cur­rent line. Con­sid­er­ing stan­dard equiv­a­lents, I’m always aston­ished by what I can accom­plish so quickly in VIM.
      I really tend to use d…d to quickly get rid of large chunks of com­mented code. Or sim­ply for mov­ing code around very very quickly.
    • r, rw, etc. d was for delete. r is for replace. Need I elab­o­rate?
      I tend to mis-type cer­tain words a lot. Really easy for me to just go over the offend­ing char­ac­ter and type in rx, where x is the new char­ac­ter I want to replace it by.
    • o, i, a, A, etc. Sin­gle key­presses for: 0: add a new line after cur­rent one and start edit­ing, O: add a new line before the cur­rent line and start edit­ing, a: start append­ing after cur­sor, i: start insert­ing before cur­sor, A: insert stuff at end of the cur­rent line.
      A is the for­get­ful programmer’s boon. Really use­ful for adding ; at the end of lines.
  2. Edit­ing over scp/ftp/etc.
    Vim comes with a spe­cial plu­gin (NetRW) that lets you quickly edit files over your pro­to­col of choice. I reg­u­larly use
    :e scp://<username>@<host>/path/
    to get a direc­tory list­ing of all the files in that path; choose your file and edit away.
  3. Search and replace
    Ever changed a vari­able at the last minute and had to change it? Eas­ily carry out reg­u­lar expres­sions over very sim­ply defined yet com­plex range of lines using /<pattern>/ or :s/<pattern>/<substitute>/flags. You can even carry out com­mands on match­ing por­tions. One of the most use­ful fea­tures I’ve used once I got the hang of it.
  4. Ranges
    Vim’s flex­i­bil­ity in terms of defin­ing ranges for substitution/deletion/anything you’d care to men­tion is amaz­ing. One of the fea­tures I most con­stantly use is ‘marks’ that allow you to mark cer­tain posi­tions to be eas­ily ref­er­enced later.
  5. Too many colour themes
    The amount of pos­si­ble colour themes avail­able is aston­ish­ing. And allows a UI freak like me to be com­pletely sat­is­fied with what I’m cod­ing in. And switch­ing quickly when I want to.
  6. Reg­is­ters
    Reg­is­ters allow you to cut/copy and store stuff in dif­fer­ent named “reg­is­ters and then paste where and when you want. Any­one who’s shuf­fled through var­i­ous files can eas­ily com­pre­hend the huge help this is.
  7. Buffers and Tabs
    Tabs are essen­tial to any decent pro­gram today. Buffers are tabs with­out the graph­i­cal inter­face indi­cat­ing their pres­ence. The best part is while using Vim in linux I tend to use
    gVIM –p *.php
    and other such com­mands to quickly open all files of  a sin­gle type in tabs in a sin­gle win­dow. Really makes find­ing the right file much much easier.
  8. Ses­sions
    Using :mkses­sion and :source allow you to quickly open all the files you had open the last time you sat down to work. And as you get to choose where the file con­tain­ing the ses­sion is saved, han­dling ses­sions becomes really sim­ple and easy.
  9. Abbre­vi­a­tions
    How many times do you find your­self using com­mon stuff like console.log() or error_log() while debug­ging? Just use the com­mand
    :ab cl console.log
    and every time you type cl( (fol­lowed by a space/newline/./(/etc.) it will be auto­mat­i­cally expanded. I imag­ine you can see the pos­si­bil­i­ties. Inter­est­ingly, abbre­vi­a­tions can be saved in ses­sions so if you don’t want to keep an abbr. around for a long time, or have some­thing spe­cific (such as a class name) just use and save it in the session.
  10. Key Map­ping
    Map keys to carry out your most often used commands.
  11. An awe­some com­mu­nity
    There are thou­sands of sites out there with point­ers on using VIM as well as an excel­lent Vim tips twiki. Be sure to check out the VIM tips twiki and this pre­sen­ta­tion on VIM for PHP pro­gram­mers by Andrei Zmievski to get a much bet­ter idea of what VIM is capa­ble of.

Also, for those of you who edit a lot of stuff on the web (using text boxes), install It’s all text to edit any text box’s con­tents using your favourite edi­tor (VIM, any­one?). This post was writ­ten in gVIM, opened via “It’s all text” on the excel­lent blog­ging plat­form pro­vided by Word­Press.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>