readfile()
을 사용하면 줄 번호를 읽고 해당 줄 번호와 일치하는 정규식 (예 : \%42l
)으로 변환 할 수 있습니다. 강조 표시는 :match
또는 matchadd()
을 통해 수행 할 수 있습니다.
다음은이 모든 사용자 정의 :MatchLinesFromFile
명령에 응축입니다 :
":MatchLinesFromFile {file}
" Read line numbers from {file} and highlight all those
" lines in the current window.
":MatchLinesFromFile Remove the highlighting of line numbers.
"
function! s:MatchLinesFromFile(filespec)
if exists('w:matchLinesId')
silent! call matchdelete(w:matchLinesId)
unlet w:matchLinesId
endif
if empty(a:filespec)
return
endif
try
let l:lnums =
\ filter(
\ map(
\ readfile(a:filespec),
\ 'matchstr(v:val, "\\d\\+")'
\ ),
\ '! empty(v:val)'
\)
let l:pattern = join(
\ map(l:lnums, '"\\%" . v:val . "l"'),
\ '\|')
let w:matchLinesId = matchadd('MatchLines', l:pattern)
catch /^Vim\%((\a\+)\)\=:E/
" v:exception contains what is normally in v:errmsg, but with extra
" exception source info prepended, which we cut away.
let v:errmsg = substitute(v:exception, '^Vim\%((\a\+)\)\=:', '', '')
echohl ErrorMsg
echomsg v:errmsg
echohl None
endtry
endfunction
command! -bar -nargs=? -complete=file MatchLinesFromFile call <SID>MatchLinesFromFile(<q-args>)
highlight def link MatchLines Search
매우 nive.Thanks! – user1871021