You can do the same in VSCode. 

    {
        "editor.codeActionsOnSave": {
            "source.organizeImports": "never"
        }
    }



On Nov 18, 2025, at 3:58 PM, Stephen Illingworth <[email protected]> wrote:


The other vim option is to use gopls directly through one of the lsp plugins. A really good lsp plugin is https://github.com/yegappan/lsp

With the basic gopls setup described in the plugin's readme, saving a file will not cause the imports to be reorganised, which fortunately is what the OP wants.

If you do want the effect of the goimports command every time save then you can do that too. I have this in my vimrc:

au Filetype go command! GoFormat :LspFormat
au Filetype go command! GoImports :LspCodeAction /Organize\sImports

function! s:goSave()
execute('GoFormat')
execute('GoImports')
endfunction

au BufWritePre *.go silent call s:goSave()

I'd be interested in hearing other people's vim/lsp/gopls setups.


On Tuesday, 18 November 2025 at 21:41:48 UTC David Finkel wrote:
On Tue, Nov 18, 2025 at 3:55 PM [email protected] <[email protected]> wrote:
I got a couple of good ideas from Will F. for coping with it.   Also, I tried Vim-Go.   Then I bit the bullet and bought Goland (not too pricey for a personal license). 

FWIW, with vim-go, you should be able to add this to your vimrc to disable auto-imports (or neovim's nvim/init.nvim):
let go_imports_autosave = 0


Goland had the same behavior (arghh) but after a long conversation with their chatbot, it came down to this: 

1) Go to Actions on Save in the settings, and disable two actions, Format Code and Optimize Imports.   2) When I want those things to happen, press option-cmd-L for Format Code, or ctrl-option-O for Optimize Imports. 

That solves it for me, for now.   Maybe writing it down will help someone else. 

On Tuesday, November 18, 2025 at 12:48:55 PM UTC-6 [email protected] wrote:
Hi.   I type 


and save, and VSCode deletes my line. 

I know why it's doing it.  I haven't yet used the library in my routine, and I have yet added the library to my go.mod file. 

But I want it to inform me of the problem, and leave it to me to fix it!  Not change my code without my permission.  (My Prius yanks the wheel when it thinks I'm about to hit something.  Not appreciated.) 

Is there some set of settings that will accomplish this?  I hate to abandon VSCode.  The Go team has put in a lot of effort to make it the best place to write Go code.  Thanks. 

Keywords:   VSCode autoformat format formatonsave 

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion visit https://groups.google.com/d/msgid/golang-nuts/8032f71e-d39a-4ce2-8d73-ed5c4dede9ean%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion visit https://groups.google.com/d/msgid/golang-nuts/59294495-bae3-4bca-b62a-65a33ce4e9aen%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion visit https://groups.google.com/d/msgid/golang-nuts/9961C13D-2DCB-4921-A750-6CDD56BAD33D%40me.com.

Reply via email to