Closed bjt-user closed 6 months ago
Vim-go formats Go code with the formatter of your choice (see :help g:go_fmt_command
) on save (see :help g:go_fmt_autosave
). All the formatters provide the same style; that of gofmt
. While semicolons are optional in Go, the community consistently uses gofmt
's style.
https://go.dev/doc/effective_go#semicolons tells us
Idiomatic Go programs have semicolons only in places such as for loop clauses, to separate the initializer, condition, and continuation elements. They are also necessary to separate multiple statements on a line, should you write code that way.
You may be interested in reading https://go.dev/blog/gofmt, too, to learn about gofmt
; it's been standard in the community for years now.
One of the Go Proverbs is Gofmt's style is no one's favorite, yet gofmt is everyone's favorite.
Thank you for the explanation @bhcleek .
What did you do? (required: The issue will be closed when not provided)
I wrote a go program with a semicolon at the end of a statement:
Then I saved the file.
What did you expect to happen?
Since semicolons are optional I would expect them to remain in the code when the author/programmer wants to use them.
What happened instead?
The semicolon disappeared.
Configuration (MUST fill this out):
vim-go version:
I guess 1.28.
master
branch was cloned on 2024-04-13.vimrc
you used to reproduce:Vim version (first three lines from
:version
):Go version (
go version
):Go environment
gopls version