Closed satyrius closed 10 years ago
The :Fmt
command only format your current buffer, you have to run it on every file you want to format. The auto-fmt works the same way, it only formats the current buffer on save. You have to save every file to force auto-fmt.
Yes, I know how it works. But it looks like autocmd does not work on the first file. I do the following
# open vim editor
cd ~/devel/my_go_project && vim
# open first file using vim command mode
:e src/foo.go
# mangle formatting, save the file, nothing happens
# open another file
:e src/bar.go
# mangle formatting, save the file, Fmt works!
# them switch back to the first file
:b#
# try again to trigger autocmd by saving file, still not working
I fixed it by duplicating autocmd definition inside my .vimrc
autocmd FileType go autocmd BufWritePre <buffer> :keepjumps Fmt
But I cannot found the reason why it does not work from plugin.
That's weird, I never had this issue before.
My further experiment...
# close first buffer
:bd
# open first file again
:e foo.go
# now it works
Yeah, that's weird.
In you
vim-golang
plugin modification you have autoformating enabled forgo
filetypeBufWritePre
https://github.com/Blackrush/vim-gocode/blob/master/ftplugin/go/fmt.vim#L20.But for me it works in very strange way. Open two files
vim foo.go bar.go
, modify both (ugly code to be formatted) then save.Fmt
will be called beautocmd
for second file opened, but not for first. Note thatFmt
command exists for first file buffer, but does not called automatically. Any ideas why?