0

I am working in a React (TypeScript) project. I am using LSP with Neovim and have TypeScript Server installed.

Right now, after I make a change, I have to run :Prettier followed by :w. I'm getting tired of doing this.

I thought LSP might have had a format on save feature, but I guess not since it isn't working.

How do I go about creating an auto-command that will run :Prettier each time I :w?

My config files can be found on GitHub.

1 Answer 1

5

We can use :h BufWritePre autocmd event.

augroup Prettier
  au!
  au BufWritePre *.tsx,*.ts,*.js,*.html,*.css  Prettier
augroup END

For explanation, see :h autocmd.

2
  • React TypeScript files have the extension .tsx but I want to run Prettier for .tsx, .ts, .js, .html and .css, what will this look like?
    – J86
    Oct 9, 2022 at 14:25
  • @J86 answer edited.
    – 3N4N
    Oct 9, 2022 at 14:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.