[英]Jump to the errors in the quickfix or location list for the current line in Vim (with Syntastic)
I started using the Syntastic plugin for Vim, which will run a syntax checker on the current buffer and then indicate any lines which have errors. 我开始使用Vim的Syntastic插件 ,它将在当前缓冲区上运行语法检查器,然后指出任何有错误的行。 I can open up the list of errors as as a location list using :Errors
, and then jump to the line of a given error by hitting Enter , which will jump to the line containing the error in my buffer. 我可以使用以下命令打开错误列表作为位置列表:Errors
,然后通过按Enter键跳转到给定错误的行,这将跳转到包含缓冲区中错误的行。
I want to know how I can do the opposite. 我想知道我怎么能做相反的事情。 I want to go from a line in my buffer that is marked with having a syntax error to the corresponding entry in the location list, so that I can read the full error message in the list. 我想从我的缓冲区中一行标记有语法错误的行到位置列表中的相应条目,以便我可以读取列表中的完整错误消息。 How can I do this? 我怎样才能做到这一点? I know that :ll [n]
will jump to the n
th error in the list, but often I will not know exactly which error number corresponds to the given line in the buffer. 我知道:ll [n]
将跳转到列表中的第n
个错误,但我常常不知道哪个错误号与缓冲区中的给定行相对应。 I cannot find a command that accepts a line number, rather than an error number, however. 但是,我找不到接受行号而不是错误号的命令。
You're right, there's no built-in way to find out which error is at or after the current cursor position, though that would often be useful. 你是对的,没有内置的方法可以找出当前光标位置或之后的错误,尽管这通常很有用。 I've written the QuickFixCurrentNumber plugin for that. 我为此编写了QuickFixCurrentNumber插件 。
With the g<Cq>
mapping, you can go to the item in the quickfix / location list for the current cursor position (or the next item after the cursor). 使用g<Cq>
映射,您可以转到quickfix / location列表中的当前光标位置(或光标后的下一个项目)。 It also offers [q
/ ]q
mappings to jump to previous / next errors while limiting the navigation to errors in the current buffer. 它还提供[q
/ ]q
映射以跳转到上一个/下一个错误,同时将导航限制为当前缓冲区中的错误。
I think that it's not possible, at least with default Vim commands or Syntastic. 我认为这是不可能的,至少使用默认的Vim命令或Syntastic。
But Syntastic actually echoes the error message associated with the current line in your command-line. 但Syntastic实际上回应了与命令行中当前行关联的错误消息。 This feature is enabled by default. 默认情况下启用此功能。
I just created this for my :Man viewer. 我刚刚为我创建了这个:Man viewer。 It tracks the current item in the 'locationlist' window when navigating: 它在导航时跟踪“locationlist”窗口中的当前项目:
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()
I tried to get this feature 'in' here which resulted in: 我试图在这里获得这个功能,结果是:
vim-loclist-follow: VIM-loclist遵循的:
https://www.vim.org/scripts/script.php?script_id=5799 https://www.vim.org/scripts/script.php?script_id=5799
https://github.com/elbeardmorez/vim-loclist-follow https://github.com/elbeardmorez/vim-loclist-follow
Nothing fancy, it just ensures the 'nearest' item is selected. 没什么好看的,只是确保选择“最近的”项目。 Works for me (™️) using either of my Syntastic, or now Ale, setups. 适合我(™️)使用我的Syntastic或现在的Ale设置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.