Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Toggle autoformat feature and/or documentation #170

Closed
rkulla opened this issue Feb 3, 2019 · 3 comments
Closed

Toggle autoformat feature and/or documentation #170

rkulla opened this issue Feb 3, 2019 · 3 comments

Comments

@rkulla
Copy link

rkulla commented Feb 3, 2019

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!

@mitermayer
Copy link
Member

I believe this functionality should be part of release/1.x as it make sense to be able to disable autoformat and enable it.

@airblade
Copy link

For a quick one-off bypassing of Prettier you could do :noautocmd w to save the buffer.

@mitermayer
Copy link
Member

release/1.x is already merged to master

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants