golines not working on save
Currently, these lines of code is not enough to run GoFmt on save which runs golines which formats long lines of code.
When I run :GoFmt, golines runs and lines are being formatted.
local format_sync_grp = vim.api.nvim_create_augroup("GoImport", {})
vim.api.nvim_create_autocmd("BufWritePre", {
pattern = "*.go",
callback = function()
require('go.format').goimport()
end,
group = format_sync_grp,
})
require('go').setup({
max_line_len = 80, -- max line length in golines format, Target maximum line length for golines
})
How is it possible to run golines properly on save?
you may need to config goimport='golines'
Now I use gopls, golines and golangci_lint separetely configured on Lazy and Mason.
I was using command = 'GoFmt' and not the callback block and also didn't have the golines configuration. I added both (and removed command = 'GoFmt') and now my Golang code gets auto-formatted on save! Thanks to both of you!
Just to help future readers: it's goimports='golines' now (plural goimports and NOT goimport).
(Also, now as in: 2024-APR-02.)