这些动词称为运算符(请参阅参考资料:h operator).如果要构建自己的运算符,必须使用该'operatorfunc'设置然后执行g@.vim文档最好解释如何执行此操作,请参阅(:h :map-operator)以下是vim文档中的示例:
nmap <silent> <F4> :set opfunc=CountSpaces<CR>g@
vmap <silent> <F4> :<C-U>call CountSpaces(visualmode(), 1)<CR>
function! CountSpaces(type, ...)
let sel_save = &selection
let &selection = "inclusive"
let reg_save = @@
if a:0 " Invoked from Visual mode, use '< and '> marks.
silent exe "normal! `<" . a:type . "`>y"
elseif a:type == 'line'
silent exe "normal! '[V']y"
elseif a:type == 'block'
silent exe "normal! `[\<C-V>`]y"
else
silent exe "normal! `[v`]y"
endif
echomsg strlen(substitute(@@, '[^ ]', '', 'g'))
let &selection = sel_save
let @@ = reg_save
endfunction
Run Code Online (Sandbox Code Playgroud)
如果你想要另一个例子,请参阅Tim Pope的评论插件.
获得更多帮助
:h operator
:h :map-operator
:h 'opfunc'
:h g@
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
454 次 |
| 最近记录: |