You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have tried setting the vim.opt.expandtab and it worked, when I :retab the tabs just turn into spaces, but the biggest problem is that I think the go formatter is setting the indentation to tabs when I format on save. Is there a way to override this setting?
This is my go.nvim setup using lazy.nvim:
return {
"ray-x/go.nvim",
dependencies= { -- optional packages"ray-x/guihua.lua",
"neovim/nvim-lspconfig",
"nvim-treesitter/nvim-treesitter",
},
config=function()
require("go").setup()
-- Set tab and indentation options for Go filesvim.api.nvim_create_autocmd("FileType", {
pattern="go",
callback=function()
vim.opt_local.expandtab=truevim.opt_local.tabstop=2vim.opt_local.shiftwidth=2end,
})
localformat_sync_grp=vim.api.nvim_create_augroup("GoFormat", {})
vim.api.nvim_create_autocmd("BufWritePre", {
pattern="*.go",
callback=function()
require('go.format').goimports()
end,
group=format_sync_grp,
})
vim.keymap.set("n", "<leader>t", ":GoTest<CR>")
vim.keymap.set("n", "<leader>d", ":GoDebug<CR>")
vim.keymap.set("n", "<leader>ds", ":GoDebug -s<CR>")
vim.keymap.set("n", "<leader>db", ":GoBreakToggle<CR>")
end,
event= {"CmdlineEnter"},
ft= {"go", 'gomod'},
build=':lua require("go.install").update_all_sync()' -- if you need to install/update all binaries
}
The text was updated successfully, but these errors were encountered:
I would not expect there is a way to override this, as in Go the standard is to use tabs. This is enforced with go fmt, which automatically format the code using the defined language best practices.
Indentation
We use tabs for indentation and gofmt emits them by default. Use spaces only if you must.
To achieve what you want you should disable the default formatting provided by this plugin and never run go fmt or gofumpt. (goimports may also apply tabs but I didn't check)
Yeah, I was searching about this, and I have found it to be really frustrating, especially for people who don't like tabs as the default indentation. But anyways, thank you so much for replying!
I have tried setting the
vim.opt.expandtab
and it worked, when I:retab
the tabs just turn into spaces, but the biggest problem is that I think the go formatter is setting the indentation to tabs when I format on save. Is there a way to override this setting?This is my
go.nvim
setup usinglazy.nvim
:The text was updated successfully, but these errors were encountered: