vim自定义操作符,加行号

加行号:

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()

显示键列表

posted @ 2022-08-13 18:13  zjh6  阅读(28)  评论(0)    收藏  举报  来源