ray-x / go.nvim

G'day Nvimer, Joyful Gopher: Discover the Feature-Rich Go Plugin for Neovim
MIT License
1.91k stars 119 forks source link

feature request: :GoBuild respect autowrite #421

Open ruilya opened 5 months ago

ruilya commented 5 months ago

Is it possible to make :GoBuild respect autowrite setting? It would be rather convenient to write all unsaved buffers before building. Same goes for :GoTest.

Thank you.

kkrime commented 1 month ago

@ruilya this is my solution;


      vim.keymap.set("n", "<C-b>", function()
        -- loop though and save .go files only
        for i, buf_hndl in ipairs(vim.api.nvim_list_bufs()) do
          fileType = vim.fn.getbufvar(buf_hndl, "&filetype")
          if fileType == "go" then
            vim.api.nvim_buf_call(buf_hndl, function()
                vim.cmd('w')
            end)
          end
        end
        vim.api.nvim_command([[:GoBuild]])
      end, { silent = true, noremap = true })