Skip to content

bagohart/multiply-divide.vim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Multiply-Divide.vim

This Vim plugin provides actions for multiplication and division of the number under the cursor or the next number in the current line.

What does it do?

Like built-in <C-a> and <C-x>, but with multiplication and division!

Mappings

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)')

Usage

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).

Requirements

Developed and tested on Neovim 0.9.1. 100% Vimscript and no fancy stuff, so it should work on Vim8+, too.

Credits

Based on an implementation by romainl. I just polished it a little to add the following features:

  1. Support for floating point numbers
  2. Remember the last count
  3. Dot-repeatable
  4. Search restricted to the current line

About

Vim plugin: multiply or divide number under cursor or next number with or by count

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published