vim自定义操作符,加行号
原创
©著作权归作者所有:来自51CTO博客作者fqbqrr的原创作品,请联系作者获取转载授权,否则将追究法律责任
加行号:
function! s:Seqno(type,...)
let i = line("'[")
let j = line("']")
for l in range(i,j)
execute l."s/^\\s*/\\0".(l-i+1).'. '
endfor
endfunction
function! s:ExeSeqno()
"获取SID"
let s:sid=matchstr(expand('<sfile>'), '<SNR>\d\+_')
"opfunc指向<SID>Seqno"
execute "set operatorfunc=".s:sid."Seqno"
return 'g@'
endfunction
//再定义一个函数,处理ss的场景,返回g@g@,直接运行,并作用于当前行
function! s:ExeSeqno2()
"获取SID"
let s:sid=matchstr(expand('<sfile>'), '<SNR>\d\+_')
"opfunc指向<SID>Seqno"
execute "set operatorfunc=".s:sid."Seqno"
return 'g@g@'
endfunction
vnoremap s :g/^\s*/ s//\=submatch(0).(line(".")-line("'<")+1).'. '<CR>
nnoremap <expr>s <SID>exeSeqno()
nnoremap <expr>ss <SID>exeSeqno2()
显示键列表