VIM映射未完全重复

VIM映射未完全重复,vim,macros,keymapping,Vim,Macros,Keymapping,为了快速注释代码行,我在vimrc中添加了以下行: augroup cmnts autocmd FileType c, cpp, javascript nnoremap <buffer> <leader>c I//<esc>j autocmd FileType python nnoremap <buffer> <leader>c I#<esc>j augroup END augroupcmnts auto

为了快速注释代码行,我在vimrc中添加了以下行:

augroup cmnts
    autocmd FileType c, cpp, javascript nnoremap <buffer> <leader>c 
I//<esc>j
    autocmd FileType python nnoremap <buffer> <leader>c I#<esc>j
augroup END
augroupcmnts
autocmd文件类型c、cpp、javascript nnoremap c
I//j
autocmd文件类型python nnoremap c I#j
螺旋端
我的期望是,当我用一个数字重复映射时,会对该数量的行进行注释,但它只是多次添加注释字符


例如,在Python中,当我键入Hc(H是我的引导键)时,它会注释三行,但当我键入3Hc时,我会在当前行的开始处得到##。

要进行计数,您将切换到使用
:normal
Ex命令。对于ruby/python,如下所示:

nnoremap <leader>c :normal I# <CR>
nnoremap c:normali#
另外,vim知道大多数语言和文件类型的注释字符串。因此,您不必明确告诉每种语言使用什么作为注释字符串,而是使用如下内容:

nnoremap <leader>c :call CommentLine()<CR>
function! CommentLine()
    let comment_character = split(&commentstring, '%s')
    exec 'normal I' . comment_character[0] . ' '
endfunction
nnoremap c:调用CommentLine()
功能!评论行()
让comment_character=split(&commentstring,'%s'))
执行“正常I”。注释字符[0]。'
端功能