Errors in Go files seems to be different and cannot be navigated to by using :cn or :lne. Is there any other way to cycle through all errors in a buffer?
Are you sure it's not working? Which command are you using? I'll use it all the time without any single problem. This is what I have in my .vimrc
map <C-n> :cn<CR>
map <C-m> :cp<CR>
So you can use :cn and :cp. vim-go uses the quickfix window and any quickfix related mappings should work.
Yes, I run the command :cn<CR> and it only prints "E42: No Errors" even though there is a type error in the buffer. If I move the cursor to that line then the error message appear in vim status bar
Could you please paste the executed command and an example code? I would like to debug it in more detail.
Here is a sample code that I just open up in a new buffer:
package main
func main() {
var foo Bar
}
the line var foo Bar generates the error, but executing :cn<CR> prints E42: No Errors. Moving the cursor to that line prints undefined: Bar
@pengux what command are you executing ? (this is the third time I'm asking you :)) It works perfectlly for me. If there is only one single error, you need to call :cc, not :cn
@fatih Sorry, I thought you meant the :cn commands. I just save the buffer and in my vim settings, it should run the goimports command
:cc didn't work either btw. I first thought that some other plugins were eating the key mappings. But as I'm executing the command in the vim command line, it should not be interfered by other plugins, correct?
Ok just to be sure we are on the same page:
goimports as the fmt command ?goimports) and you can't jump to it.If that's the case then we need to look at fmt.vim. Btw can you execute :GoBuild and check if :cn works ?
@fatih That's correct. Using :GoBuild works as the quickfix window open up and the cursor is moved to the error automatically. Using :cn in the sample code does not work as you pointed out as there's only one error, but :cc works.
Alright, now at least I know where to look now :) Thanks for the report. Probably the quickfix window is not being correctly produced via fmt.vim, or goimports has a different output than gofmt. Anyway I need more time to look it up. In meanwhile you can disable showing errors when you save your file by adding the line:
let g:go_fmt_fail_silently = 1
to your .vimrc.
Great!
No, I rather see the errors and moving to it manually though :-)
I was curious and tried to debug the problem in fmt.go, and I don't think it is because of GoImports/GoFmt. Because if I change the error to be something like an syntax error, such as:
package main
import "fmt"
func main() {
var Foo Bar
By leaving out the closing bracket, GoImports reports the error correctly, the quickfix window is opened and I can navigate to the error.
So it must be some kind of compiler checking that don't populate the quickfix window correctly. What is run on save automatically with vim-go?
Found the cause and it's because of Syntastic syntax checking, so closing this...
@pengux What was the actual issue with syntastic? How did you correct it?
@elithrar I don't remember exactly, but I have these two lines in my .vimrc so maybe you can try it
let g:syntastic_always_populate_loc_list = 1
let g:syntastic_auto_loc_list = 1
Something else is going on... I don't have syntastic and have this same issue. Open to trying things to debug it.
@pengux Thanks for your comment. It solved my problem.
@vorstack-jeff did you get it working? I dont have syntastic and i have the issue aswell.
UPDATE. I am not that used to using the lists in vim. It turns out that there are two types of lists location lists and quickfix lists. cnext will not find the next error if your use a location list. Instead you will need to run lnext.
my .vimrc:
GoMetaLinterlocationlist, (about quickfix vs location list)It works, so maybe you can try it:
let g:go_metalinter_autosave = 1
let g:go_list_type = 'locationlist'
" turn to next or previous errors, after open location list
nmap <leader>j :lnext<CR>
nmap <leader>k :lprevious<CR>
I hope that helps :smile:
@modood Worked for me. Thank you.
Most helpful comment
my .vimrc:
GoMetaLinterlocationlist, (about quickfix vs location list)It works, so maybe you can try it:
I hope that helps :smile: