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

How to cancel the auto format when i save? #311

Open
niming175 opened this issue Aug 17, 2021 · 1 comment
Open

How to cancel the auto format when i save? #311

niming175 opened this issue Aug 17, 2021 · 1 comment

Comments

@niming175
Copy link

niming175 commented Aug 17, 2021

How to cancel the auto format when i save?
when i save the code , i didn't want it to auto format; How am i to set the config

@jakerobers
Copy link

jakerobers commented Oct 15, 2021

Try checking your config file for the g:prettier#autoformat variable. If you see:

let g:prettier#autoformat = 1

Try to either set this value to 0, or remove the line entirely (vim-prettier defaults the value to 0).


I was brought here on an unrelated note. I noticed that my cursor moves to the front of the line (functional equivalent of ^) whenever I save. It was getting annoying that I was losing my cursor position. This only seems to be occurring on my linux computer. My mac appears fine.

If you're looking for a "fix", you can remove the augroup Prettier.

diff --git a/plugin/prettier.vim b/plugin/prettier.vim
index 3326f26..64eeef3 100644
--- a/plugin/prettier.vim
+++ b/plugin/prettier.vim
@@ -172,7 +172,3 @@ nnoremap <silent> <Plug>(PrettierCli) :PrettierCli<CR>
 nnoremap <silent> <Plug>(PrettierCliVersion) :PrettierCliVersion<CR>
 nnoremap <silent> <Plug>(PrettierCliPath) :PrettierCliPath<CR>
 
-augroup Prettier
-  autocmd!
-  autocmd BufWritePre *.js,*.jsx,*.mjs,*.ts,*.tsx,*.css,*.less,*.scss,*.json,*.graphql,*.gql,*.markdown,*.md,*.mdown,*.mkd,*.mkdn,*.mdx,*.vue,*.yml,*.yaml,*.html,*.php,*.rb,*.ruby,*.xml noautocmd | call prettier#Autoformat()
-augroup end

Note that this will break autoformat functionality when you set let g:prettier#autoformat = 1. I personally only use :Prettier and do not rely on any auto formatting.

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

No branches or pull requests

2 participants