guonaihong / config.lua

私有lunarvim配置文件,为方便clone,设置为public
Apache License 2.0
0 stars 0 forks source link

3. 自动让goimport 和gofmt生效 #3

Open guonaihong opened 1 year ago

guonaihong commented 1 year ago
  1. 需要在config.lua里面导入go.nvim插件
    
    {
    "ray-x/go.nvim",
    dependencies = { -- optional packages
      "ray-x/guihua.lua",
      "neovim/nvim-lspconfig",
      "nvim-treesitter/nvim-treesitter",
    },
    config = function()
      require("go").setup()
    end,
    event = { "CmdlineEnter" },
    ft = { "go", 'gomod' },
    build = ':lua require("go.install").update_all_sync()' -- if you need to install/update all binaries
    },
在ftplugin里面导入go文件的个性化配置文件
```lua
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,
})