This Vim plugin provides actions for multiplication and division of the number under the cursor or the next number in the current line.
Like built-in <C-a>
and <C-x>
, but with multiplication and division!
No mappings are created automatically. Add your own. I use:
nmap <Leader><C-a> <Plug>(multiply)
nmap <Leader><C-x> <Plug>(divide)
or using init.lua
:
vim.keymap.set('n', '<Leader><C-a>', '<Plug>(multiply)')
vim.keymap.set('n', '<Leader><C-x>', '<Plug>(divide)')
It works almost exactly like the built-in <C-a>
and <C-x>
In normal mode, type [count]<Leader><C-a>
to multiply the number under the
cursor (or the next number in the current line) with [count]
.
It supports both integer and floating point numbers, and is dot-repeatable
without requiring vim-repeat.
A notable difference to the built-in <C-a>
and <C-x>
is that using <C-a>
without a [count]
adds 1
, but since multiplication with 1
is a NOOP, the
action for <Plug>(multiply)
in this case reuses the previous [count]
. The
same applies to <Plug>(divide)
.
Developed and tested on Neovim 0.9.1
. 100% Vimscript and no fancy stuff, so it
should work on Vim8+, too.
Based on an implementation by romainl. I just polished it a little to add the following features:
- Support for floating point numbers
- Remember the last count
- Dot-repeatable
- Search restricted to the current line