我有以下映射,允许粘贴从缓冲区缓冲区中的单词.(cpw =更改粘贴字)
nmap <silent> cpw "_cw<C-R>"<Esc>
我想做的是允许如下命令
cpiw(更改粘贴在word中 - >喜欢'iw'动作)
cpaw(更改粘贴一个单词 - >像'aw'运动一样)
对于任何运动{m} cp {m}
这是否可以允许在映射中,所以我不必为我想要使用它的每个动作编写nmap?
提前致谢.
编辑:错字修复.我的解决方案如下
在努力研究地图操作员之后,我成功地完成了一个完全符合我想要的功能.对于任何感兴趣的人,如下:
"This allows for change paste motion cp{motion}
nmap <silent> cp :set opfunc=ChangePaste<CR>g@
function! ChangePaste(type, ...)
silent exe "normal! `[v`]\"_c"
silent exe "normal! p"
endfunction
Run Code Online (Sandbox Code Playgroud)
编辑 - 可能更好的新版本.
"This allows for change paste motion cp{motion}
nmap <silent> cp :set opfunc=ChangePaste<CR>g@
function! ChangePaste(type, ...)
if a:0 " Invoked from Visual mode, use '< and '> marks.
silent exe "normal! `<" . a:type . "`>\"_c" . @"
elseif a:type == 'line'
silent exe "normal! '[V']\"_c" . @"
elseif a:type == 'block'
silent exe "normal! `[\<C-V>`]\"_c" . @"
else
silent exe "normal! `[v`]\"_c" . @"
endif
endfunction
Run Code Online (Sandbox Code Playgroud)