我刚刚为我的 :Man 查看器创建了这个。它在导航时跟踪“位置列表”窗口中的当前项目:
function! s:visibleLoc()
return len(filter(getwininfo(), {i,v -> v.loclist}))
endfunc
function! s:followLine()
let curLine = line(".")
if (exists("b:lastLine") && b:lastLine == curLine) || 0 == s:visibleLoc()
return
endif
let b:lastLine = line(".")
let ent = len(filter(getloclist("."), {i,v -> v.lnum <= curLine}))
if ent < 1 || (exists("b:lastEntry") && b:lastEntry == ent)
return
endif
let b:lastEntry = ent
let pos = [ 0, curLine, col("."), 0 ]
exe "ll ".ent
call setpos(".", pos)
endfunc
au CursorMoved <buffer> call <SID>followLine()