我知道可以使用<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