vim中创建可重复的映射

可以通过g@传递它们来创建可重复映射

function! s:insspace(...)
  if a:0
    execute 'normal' v:count1.'i '."\<esc>".'`['
  else
    " 安装"
    let &operatorfunc = matchstr(expand('<sfile>'), '[^. ]*$')
    return "g@\<space>"
  endif
endfunction

nnoremap <silent><expr> <space> <sid>insspace()

通常g@用于运算符,但通过使用g@<space>,可为实际操作.这里实际上调用了两次s:insspace函数,一次无参数,意思是"设置",它设置operatorfunc选项为自己(类似matchstr),然后由vim一个参数再次调用.

posted @ 2022-08-12 15:54  zjh6  阅读(27)  评论(0)    收藏  举报  来源