解决方法
这些动词称为运算符(参见: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
如果你想要另一个例子,请看看Tim Pope的commentary plugin.
获得更多帮助
:h operator :h :map-operator :h 'opfunc' :h g@
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。