Vim commands for improved productivity

Introduction

I would like to des­cri­be my fa­vou­ri­te Vim co­m­man­ds that I use on a dai­ly ba­sis, in or­der to sha­re so­me tips that could help you if you are new in this edi­to­r, or ­to im­pro­ve your ex­pe­rien­ce even if you use it.

  • J : Use­ful when or­ga­ni­zing co­de, this wi­ll join the li­ne be­low to the cu­rrent one.
  • ci) (“­chan­ge in­si­de ‘)’): Ac­tua­ll­y, the clo­sing bra­cket could be chan­ged by any other thin­g (­like ‘]’, ‘}’, etc.). This wi­ll era­se eve­r­y­thing wi­thin the bra­cke­ts and set you in in­sert mo­de (­the c could al­so be chan­ged for d for exam­ple if you just want to de­le­te). Agai­n, this is ­ve­ry use­ful when re­fac­to­ring co­de, if you want to chan­ge the pa­ra­me­ters of a func­tion de­fi­ni­tio­n, or whate­ver is in a blo­ck, etc.
  • (s­elect so­me co­de wi­th vi­sual mo­de and then) zf : wi­ll fold the se­lec­ted co­de. zd for un­fol­din­g.
  • % : alo­ne or along wi­th so­me other ope­ra­to­r, is use­ful for ope­ra­ting wi­th ma­tchin­g ­bra­cke­ts in the co­de. It wi­ll ma­tch the clo­sing bra­cket of the one you ha­ve the cur­sor in.
  • C or D : if you want to chan­ge or de­le­te from the cu­rrent po­si­tio­n up to the end of the li­ne, res­pec­ti­ve­l­y.
  • t, (or any other cha­rac­ter ins­tead of co­m­ma) wi­ll point you until that cha­rac­te­r. ­The good about this, is that is po­s­si­ble to chain it wi­th other co­m­man­d­s, for exam­ple: “ct,” wi­ll chan­ge all the con­tent un­til the next co­m­ma.
  • < or > wi­ll in­dent the co­de fo­llo­wing the “a­rro­w” di­rec­tio­n (ac­cor­ding to what is set in shi­ftwi­dth).
  • = Au­to­ma­ti­ca­lly in­den­ts co­de (u­se­ful when hi­gh­li­gh­ting co­de in vi­sual mo­de).
  • w, e or b wi­ll point you to the next wor­d, to the end of the wor­d, or back to the pre­vious wor­d, res­pec­ti­ve­l­y. The ni­ce thing about the­se ope­ra­tors is when they wo­rk ­com­bi­ned wi­th other­s, for exam­ple:
    • cw wi­­ll chan­­ge the next word.
    • db wi­­ll de­­le­­te the pre­­vious wo­r­­d.
  • { or } for mo­ving up or do­wn th­rou­gh pa­ra­gra­phs, res­pec­ti­ve­l­y.

In addi­tio­n, no­te that you do not need to know all po­s­si­ble co­m­man­d­s, jus­t ­tho­se that wi­ll help you wi­th your nor­mal ac­ti­vi­tie­s. This means that is could be enou­gh wi­th a sma­ll ­sub­set of all the fea­tu­res (the list I wro­te is ve­ry short in­dee­d). And this is pre­ci­se­ly the idea be­hind this pos­t: to show ho­w ­so­me few co­m­man­ds applied in the ri­ght con­tex­t, mi­ght make you edit fas­te­r.

All in all, Vim is a great edi­to­r, fu­ll of ama­zing fea­tu­res. Lear­ning it is ac­tua­lly wor­th it, in the sen­se that you wi­ll get an ama­zing pro­duc­ti­vi­ty in re­turn (you’­ll ty­pe and edi­t ­co­de fas­te­r).