Today I Learned

A Hashrocket project

Use Vim counts for small arithematic calculations

In CSS land you often need to increment/decrement a pixel value. You can use <C-a> for incrementing and <C-x> for decrementing value but what if you want to move faster or increment by a specific number?

Counts for the rescue!

Every motion in vim can be preceded by a count, and as it turns out so does increment/decrement:

body {
  height: 1827px;

Say I want to increment the padding by 344. I can either:

  • replace the 1827 with 2171 after using my calculator.
  • Press <C-a> 344 times
  • Or alternatively 344<C-a>

You can also set a mapping to increment/decrement by 10.

Credit: Practical Vim by Drew Neil

Every developer at Hashrocket is a Vim expert. Check out our development environment, Dotmatrix, and if you are in Chicago, come to the monthly Vim Chicago Meetup hosted at our Chicago office.