[go-nuts] Re: VSCode keeps deleting my import line
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). 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 > > import "github.com/zalando/go-keyring" > > 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.
[go-nuts] VSCode keeps deleting my import line
Hi. I type import "github.com/zalando/go-keyring" 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/204f5c1e-d02d-4c67-a19c-d7a4497174fen%40googlegroups.com.
[go-nuts] Re: VSCode keeps deleting my import line
This is really similar to what Robert Engels said, and may be the same
thing. Anyway, this definitely works in VSCode to have the editor leave
your file along when you save to disk.
Ha! Problem solved. (And I am so embarrassed)In the documentation for
the extension, they document exactly how to disable the reformatting on
save.
Formatting and organizing imports are enabled by default. You can choose to
disable them by configuring the following settings."[go]": {
"editor.formatOnSave": false,
"editor.codeActionsOnSave": {
"source.organizeImports": false
}
}
I tried it, and it works.
On Wednesday, November 19, 2025 at 3:34:49 AM UTC-6 Stephen Illingworth
wrote:
> Having an unused import is a compilation error so it's generally good that
> editors do this (by calling goimports or using the gopls code action).
> Using the underscore notation is a good tip though.
>
> On Wednesday, 19 November 2025 at 09:18:31 UTC Brian Candler wrote:
>
>> I don't know anything about fancy editors, but I note that go.dev/play/
>> does the same (maybe for same underlying reason).
>>
>> You can prevent it by writing:
>>
>> import _ "github.com/zalando/go-keyring"
>>
>> (although you then have to remove the underscore later when you actually
>> want to use the module)
>>
>
--
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/889d5ed4-16d2-4b35-84c4-c8b9fc6b9138n%40googlegroups.com.
