How do I increment and decrement dates, times, and other structured sequences in Vim?
Answer
<C-a> / <C-x> (vim-speeddating)
Explanation
vim-speeddating (by Tim Pope) extends Vim's built-in <C-a> and <C-x> increment/decrement operators to understand dates, times, roman numerals, and other ordered sequences. With the plugin, pressing <C-a> on 2024-01-31 advances it to 2024-02-01 — correctly rolling over month and year boundaries.
How it works
<C-a>on a recognized sequence — increments it (date forward, time later, etc.)<C-x>on a recognized sequence — decrements it- Supported formats include:
- Dates:
2024-01-15,January 15, 2024,15 Jan 2024,2024/01/15 - Times:
12:00,12:00:00,23:59 - Days/months:
Monday,January - Roman numerals:
XIV - Ordinals:
1st,2nd,3rd
- Dates:
- Vim's built-in
<C-a>/<C-x>still works for plain integers; vim-speeddating takes over only when a structured format is detected
Install with: Plug 'tpope/vim-speeddating'
Example
With the cursor on the date in:
Deadline: 2024-01-31
Press <C-a> → 2024-02-01 (month rolls over correctly)
Press <C-x> → 2024-01-30
With the cursor on Monday: <C-a> → Tuesday
Tips
- Use a count:
7<C-a>on a date advances it by 7 days - Works in Visual mode too: select a column of dates and press
g<C-a>to increment each by a sequential amount (1, 2, 3…) - vim-speeddating respects leap years and varying month lengths automatically
- Combine with macros to generate date sequences: record a macro that moves down a line and
<C-a>-increments the date