Golang has a tool that's called 'gofmt' which formats your code. I'm using the vim-go
plugin which fires the 'gofmt' tool every time when I save a file.
Golang uses tabs for indention. I marked the tabs as [ ]
in the following examples.
Here's a problem which I've run:
I have the following code:
func main() {
[ ]if true {
[ ][ ]do.Something()
[ ]}
}
I need to comment the if
clause.
So, if I comment it like the following(I'm using nerd-commenter
):
func main() {
//[ ]if true {
//[ ][ ]do.Something()
//[ ]}
}
Gofmt formats it to:
func main() {
[ ]//[ ]if true {
[ ]//[ ][ ]do.Something()
[ ]//[ ]}
}
If I do this:
func main() {
[ ]//if true {
[ ][ ]//do.Something()
[ ]//}
}
Gofmt formats it to this:
func main() {
[ ]//if true {
[ ]//do.Something()
[ ]//}
}
I need to comment the if
clause like the following:
func main() {
[ ]//if true {
[ ]//[ ]do.Something()
[ ]//}
}
Then Gofmt won't change the commented block. How I can do this?