I currently use this bit of vimscript I wrote in my vimrc file to toggle vim-prettier autoformat on/off:
""" Toggle vim-prettier auto formatting with <Leader>pr
nnoremap <leader>pr :call TogglePrettier()<cr>
" enable autoformatting by default
let g:prettier#autoformat=0
autocmd BufWritePre *.js,*.jsx,*.mjs,*.ts,*.tsx,*.css,*.less,*.scss,*.json,*.graphql,*.md,*.vue,*.yaml,*.html PrettierAsync
function! TogglePrettier()
if g:prettier#autoformat
let g:prettier#autoformat=0
autocmd BufWritePre *.js,*.jsx,*.mjs,*.ts,*.tsx,*.css,*.less,*.scss,*.json,*.graphql,*.md,*.vue,*.yaml,*.html PrettierAsync
else
let g:prettier#autoformat=1
autocmd! BufWritePre *.js,*.jsx,*.mjs,*.ts,*.tsx,*.css,*.less,*.scss,*.json,*.graphql,*.md,*.vue,*.yaml,*.html call clearmatches()
endif
endfunction
because I like to keep autoformat on by default but once in a while I like to turn it off temporarily, e.g., if i don't want a json string to be multiple lines, etc. This allows you to still type <Leader>p, by making a new map called <Leader>pr but i don't care if you choose another mapping or way of doing this all together.
I can see it being difficult to get all the variations of autoformating and different file extensions working so maybe just a documentation of how to do it would be enough. Love the plugin, thanks!
I believe this functionality should be part of release/1.x as it make sense to be able to disable autoformat and enable it.
For a quick one-off bypassing of Prettier you could do :noautocmd w to save the buffer.
release/1.x is already merged to master
Most helpful comment
I believe this functionality should be part of
release/1.xas it make sense to be able to disable autoformat and enable it.