Hi guys, first of all thank you for your time and effort, I really appreciate it :)
Is it possible to auto format files, on save, without the need to add the "@format" tag?
Hi @tugorez, thank you for your message. You can achieve your desired behavior by adding to your .vimrc one of the bellow strategies:
Running before saving sync:
let g:prettier#autoformat = 0
autocmd BufWritePre *.js,*.json,*.css,*.scss,*.less,*.graphql Prettier
Running before saving async (vim 8+):
let g:prettier#autoformat = 0
autocmd BufWritePre *.js,*.json,*.css,*.scss,*.less,*.graphql PrettierAsync
Running before saving, changing text or leaving insert mode:
```vim
" when running at every change you may want to disable quickfix
let g:prettier#quickfix_enabled = 0
let g:prettier#autoformat = 0
autocmd BufWritePre,TextChanged,InsertLeave .js,.json,.css,.scss,.less,.graphql PrettierAsync
Will close this issue, but feel free to comment on it if you have any further questions around it.
@mitermayer Thank you very much
This info should be documented. The doc says its default format on auto save, but only when I declared this config explicitly on my .vimrc it has worked.
@wellyal it will only autoformat if the pragma format exists on the file example:
/**
* @format
*/
const b = 2;
That will auto format upon saving, however if you try on a file with:
const b = 2;
it won't auto format, notice its missing the pragma format
@wellyal does that clarifies your question ? I believe the above is described on the README, if you think its not clear enough feel free to submit a Pull Request with a more descriptive information and I will happily merge it.
Is it possible to implement a strategy similar to other editors' Prettier plugins, where formatting is done automatically without pragma if
package.json defines prettier as a dependency and/or.prettierrc file in one of the parent directoriesFor me, that would remove the need for a pragma completely.
Hi, any idea why it's not working on .ts and .tsx files?
let g:prettier#autoformat = 0
autocmd BufWritePre *.ts,*.tsx,*.jsx,*.js,*.json,*.css,*.scss,*.less,*.graphql PrettierAsync
It can format Typescript file when I press <Leader>p but it doesn't want to auto format on save (only for .ts and .tsx, the others work well).
Most helpful comment
Hi @tugorez, thank you for your message. You can achieve your desired behavior by adding to your
.vimrcone of the bellow strategies:Running before saving sync:
Running before saving async (vim 8+):
Running before saving, changing text or leaving insert mode:
```vim
" when running at every change you may want to disable quickfix
let g:prettier#quickfix_enabled = 0
let g:prettier#autoformat = 0
autocmd BufWritePre,TextChanged,InsertLeave .js,.json,.css,.scss,.less,.graphql PrettierAsync