Open VON0000 opened 1 week ago
BufWritePre
is called before the file is saved to disk. Ocamlformat operates on the old file and the edit!
overwrite any new change.
Did you find these instructions somewhere ?
This should work with BufWritePost
instead. Though, a dedicated formatter plugin for vim would work better as it will handle different languages and errors.
sorry for bothering you, but I have tried this one "autocmd BufWritePost .ml,.mli execute ':silent !ocamlformat % --inplace' | execute 'edit!'" It can store my change now but it could not format the code.
Is here an error? Having a nice display of the errors is hard to do in Vim, you'd probably have more luck with a formatter plugin. I do not have formatting-on-save in my setup so I cannot suggest a specific plugin.
There is no error or warning in terminal. I tried to print the log of vim. It seems that no log connected to ocamlformat is printed.
I also will try to find some formatter plugin for vim.
You can run :!ocamlformat % --inplace
, which should show the same errors if any.
:!ocamlformat % --inplace
works well in vim
i am running Linux Mint My ocaml version is 4.13.1 My ocamlformat version is 0.26.2 My vim version is 9.1
i add this to my vimrc ''' call plug#begin('~/.vim/plugged')
Plug 'rgrinberg/vim-ocaml'
call plug#end()
autocmd BufWritePre .ml,.mli execute ':silent !ocamlformat % --inplace' | execute 'edit!' ''' But after that, if i do sth like ':w' or ':wq', any new code i write that is not saved will be deleted. And the file is saved as the last version before coding.
ocamlformat works well in terminal.