我知道可以使用<repeat-count><ctrl>-a
和<repeat-count><ctrl>-x
命令通过重复计数递增/递减整数。如何在光标下乘以或划分重复次数?
现在我想知道是否有乘法和除法的类似命令。如果没有这样的命令,我怎样才能在我自己的.vimrc中实现这个功能?
我知道可以使用<repeat-count><ctrl>-a
和<repeat-count><ctrl>-x
命令通过重复计数递增/递减整数。如何在光标下乘以或划分重复次数?
现在我想知道是否有乘法和除法的类似命令。如果没有这样的命令,我怎样才能在我自己的.vimrc中实现这个功能?
这里是一个快速和肮脏的尝试:
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>
现在,按5<F5>
由5
乘光标下的数字。
如果你想这样做没有映射/功能:
v{motion}c<C-r>=<C-r>"*5<CR><Esc>
如果你问内置正常命令,NO,没有。但是你可以编写函数/映射来完成它。举一个例子,并显示你想要什么 – Kent