This happens when `formatOnSave` in vs code is enabled and you are not using the imported package in your code.
The `formatOnSave` being enabled removes the unused imports.
To avoid the problem, you either disable `formatOnSave` or use the imports correctly.
Sometimes, when you know that you are using the imports just check if the functions of that package are spelled correctly while you are using them.
When you save below code, the `fmt` import is removed becase, `println` is misspelled and the editor thinks you are not really using the `fmt` package.
Change it to capital `P`. The import is not removed when saving.
package main
import "fmt"
func main() {
fmt.println("hello world")
}