vimtricks.wiki Concise Vim tricks, one at a time.

How do I decrement a number under the cursor?

Answer

<C-x>

Explanation

The <C-x> command decrements the number under or after the cursor by 1. It is the counterpart to <C-a> for incrementing.

How it works

  • <C-x> finds the nearest number and subtracts 1
  • Works with decimal, hex, octal, and binary numbers
  • Accepts a count: 5<C-x> subtracts 5

Example

retries = 3

Pressing <C-x> changes it to:

retries = 2

Tips

  • <C-a> is the increment counterpart
  • 100<C-x> subtracts 100
  • Numbers can go negative
  • Useful for adjusting array indices, port numbers, and counters

Next

How do you yank a single word into a named register?