Last active
September 17, 2023 10:11
-
-
Save romainl/97d79dfd522bd1c33c7fafb9ec08dc5d to your computer and use it in GitHub Desktop.
Multiply/divide by [count]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function! Multivide(divide) | |
let cnt = v:count1 | |
let old_reg = getreg("v") | |
call search('\d\([^0-9\.]\|$\)', 'cW') | |
normal v | |
call search('\(^\|[^0-9\.]\d\)', 'becW') | |
normal "vygv | |
if a:divide == 1 | |
execute 'normal "_c' . @v / cnt | |
else | |
execute 'normal "_c' . @v * cnt | |
endif | |
call setreg("v", old_reg) | |
endfunction | |
nnoremap <key> :<C-u>call Multivide(0)<CR> | |
nnoremap <otherkey> :<C-u>call Multivide(1)<CR> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey romainl, this is great!
I never knew I needed this, but now I use it all the time.
Therefore, I decided to polish it a little and publish it as a plugin:
https://github.com/bagohart/multiply-divide.vim
Thanks for this!