当使用omap或onoremap声明映射时,我希望能够处理运动将是blockwise,linewise或standard的情况.
例如,让我们考虑以下块:
abcd efgh ijkl mnop
光标位于字母f上.假设我将K的运算符映射定义为:normal! vjl(转到字母k).
onoremap K :normal! vjl<cr>
有趣的是,当我运行dvK,dK,d ^ VK时我分别得到了
abcd abcd abcd el el eh mnop mnop il mnop
但是当我运行dVK它不起作用时,我和dvK完全一样.
我尝试使用visualmode()(映射定义为@ = visualmode()< cr> jl< cr>但这不起作用.看来当你使用v,V时,这个函数的返回值不会立即受到影响CTRL-V处于操作符挂起模式.
有人有线索吗?
谢谢
我已经写了一些关于运算符挂起映射的答案.在
one of them1中,我根据文档概述了应该处理各种情况(char,line,block wise选择)的函数的大纲:
g@{motion} Call the function set by the 'operatorfunc' option. The '[ mark is positioned at the start of the text moved over by {motion},the '] mark on the last character of the text. The function is called with one String argument: "line" {motion} was |linewise| "char" {motion} was |characterwise| "block" {motion} was |blockwise-visual| Although "block" would rarely appear,since it can only result from Visual mode where "g@" is not useful. {not available when compiled without the |+eval| feature}
以下是使用< F4>:>计算空格数的示例
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
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。