How can I multiply or divide value under the cursor by a repeat count?

cmaster - reinstate monica

I know that it is possible to increment/decrement an integer by a repeat count using the <repeat-count><ctrl>-a and <repeat-count><ctrl>-x commands.

Now I was wondering whether there are analogous commands for multiplication and division. And if there is no such command, how can I implement this in my own .vimrc?

romainl

Here is a quick and dirty attempt:

function! Multiply()
    " save count
    let cnt        = v:count1

    " save register v
    let old_reg    = getreg("v")

    " select the number under the cursor
    call search('\d\([^0-9\.]\|$\)', 'cW')
    normal v
    call search('\(^\|[^0-9\.]\d\)', 'becW')

    " yank it into register v then reselect
    normal "vygv

    " change the selection with the yanked number multiplied by the count
    execute "normal c" . @v * cnt

    " restore register v
    call setreg("v", old_reg)
endfunction

nnoremap <F5> :<C-u>call Multiply()<CR>

Now, press 5<F5> to multiply the number under the cursor by 5.

If you want to do it without mappings/functions:

v{motion}c<C-r>=<C-r>"*5<CR><Esc>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

How can I set while repeat count per second?

From Java

How can I multiply row under certain condition with R?

From Dev

How can I sort a Guava Multiset on entry value and count?

From Dev

How can I show a count of rows from an ng-repeat?

From Dev

How can I multiply only the cells that contain value?

From Dev

VIM , how to show the count of occurrence the current match pattern under cursor?

From Dev

Divide and Multiply value-of-select in XSLT

From Dev

How can I count a specific value in group_by in pandas?

From Dev

How can multiply a value I enter in an excel cell by a constant number, with result on appearing on same cell?

From Dev

How can I make this repeat?

From Dev

How can I divide bitsets?

From Dev

How to get the count of the word under cursor in Vim quickly?

From Dev

How can I multiply two arrays in Ruby?

From Dev

How can I reset a variable count in ng-repeat?

From Dev

How can I multiply a string in the C language?

From Dev

How can I set while repeat count per second?

From Dev

How can I multiply table?

From Dev

how to divide the result of the cursor in python

From Dev

Why can't I multiply a hash value?

From Dev

How can i get the count of JSON keys present under the array?

From Dev

How can I repeat matrix?

From Dev

How can I make this repeat?

From Dev

How can I divide the partitions?

From Dev

How can I divide bitsets?

From Dev

How can I enable default value display under Django CharField

From Dev

How can I choose the highest number in a row, and multiply it automatically with a value in the same column?

From Dev

How can I set the value of a variable inside a ng-repeat?

From Dev

How can I increment an Angular ng-repeat function value?

From Dev

How can I multiply std::tuple to some value?

Related Related

  1. 1

    How can I set while repeat count per second?

  2. 2

    How can I multiply row under certain condition with R?

  3. 3

    How can I sort a Guava Multiset on entry value and count?

  4. 4

    How can I show a count of rows from an ng-repeat?

  5. 5

    How can I multiply only the cells that contain value?

  6. 6

    VIM , how to show the count of occurrence the current match pattern under cursor?

  7. 7

    Divide and Multiply value-of-select in XSLT

  8. 8

    How can I count a specific value in group_by in pandas?

  9. 9

    How can multiply a value I enter in an excel cell by a constant number, with result on appearing on same cell?

  10. 10

    How can I make this repeat?

  11. 11

    How can I divide bitsets?

  12. 12

    How to get the count of the word under cursor in Vim quickly?

  13. 13

    How can I multiply two arrays in Ruby?

  14. 14

    How can I reset a variable count in ng-repeat?

  15. 15

    How can I multiply a string in the C language?

  16. 16

    How can I set while repeat count per second?

  17. 17

    How can I multiply table?

  18. 18

    how to divide the result of the cursor in python

  19. 19

    Why can't I multiply a hash value?

  20. 20

    How can i get the count of JSON keys present under the array?

  21. 21

    How can I repeat matrix?

  22. 22

    How can I make this repeat?

  23. 23

    How can I divide the partitions?

  24. 24

    How can I divide bitsets?

  25. 25

    How can I enable default value display under Django CharField

  26. 26

    How can I choose the highest number in a row, and multiply it automatically with a value in the same column?

  27. 27

    How can I set the value of a variable inside a ng-repeat?

  28. 28

    How can I increment an Angular ng-repeat function value?

  29. 29

    How can I multiply std::tuple to some value?

HotTag

Archive