Is there a command in Vim to move the cursor to the next number? I know I can do
f2 to find the number 2 in the same line, but I'm looking for a more general number-jumping command.
Ctrl+A and Ctrl+X will both jump the cursor to the next number on the line.
However, the former will increment the number and the latter will decrement it. You don't want to make any changes, so you have the following options to quickly jump to the next number on the line.
To summarize the comments and make this a full answer:
The general search command is shortest:
/\d<Enter>. You can then repeat the search with
N, as usual. To skip to the next full number, not the next digit, use
If you don't want to clobber your search pattern, you can use the lower-level
search() function. As this is a lot to type, a mapping (defined in your
~/.vimrc) can be convenient:
:nnoremap <silent> <Leader>nd :call search('\d\+')<CR>
Unlike the built-in search commands, this doesn't yet support a
[count] to skip some numbers. A robust implementation would need several lines of Vimscript. Alternatively, you can use my CountJump plugin to generate mappings:
:call CountJump#Motion#MakeBracketMotion('', 'd', '', '\d\+', '', 0)
]d mappings that jump to the previous / next start of a number, with an optional