Sublime Forum

Add "File: save without formatting"

#1

I usually want Prettier to format my files on save, but sometimes I don’t, and it’s really difficult and slow to save a file when that is the case.

Here’s how I discovered this issue: https://youtu.be/3MzPwY6kotU?t=1274

Here is a feature suggested by chatgpt:

Option 2: Save Manually (Without Prettier)

  1. Open the Command Palette : Press Ctrl+Shift+P (Windows/Linux) or Cmd+Shift+P (Mac).
  2. Type “Save” and choose File: Save Without Formatting if you have a command installed that supports this. Otherwise, proceed with disabling the plugin manually as shown above.
0 Likes

#2

But that depends “how” you format your file. If you format using a LSP, you would need to change the LSP setting lsp_format_on_save.
For Prettier that depends on which package you are using: https://packagecontrol.io/packages/JsPrettier uses the setting auto_format_on_save.

The Package https://packagecontrol.io/packages/Prettierd%20Format has a Prettierd: Save without formatting command

1 Like

#3

Thank you! That’s what I was looking for. Also excited to try prettierd.

I gave it a shot, but hit some errors: https://news.pub/?try=https://www.youtube.com/embed/sdxeLDc2O9k?si=TsLAInXmla9XRDa5

0 Likes

#4

Hmm, I’ve just tried prettierd on MacOS, installed the Homebrew package https://formulae.brew.sh/formula/prettierd (prettierd 0.25.3) and after that the Sublime package you linked to, and everything is working without me doing anything at all. It even works with LSPs, which have “format on save” enabled (Typescript, CSS, JSON, …).

To check, what is the real problem, you should take a look at the “Console”, an MacOS the keybinding is

control + `

There you should see an error message. If that doesn’t help, you can type sublime.log_commands(True) in the input field of the console, save the file and type sublime.log_commands(False) - there is much going on in the console, so do as little in Sublime Text as possible.

Btw. the prettierd executable is a bit special. It takes the content of the file to format on stdin and the name to save the formatted file to as argument. So

cat FILENAME | prettierd FILENAME

is the command to format file FILENAME.

0 Likes

#5

And using the Homebrew Prettier package https://formulae.brew.sh/formula/prettier#default and the JSPrettier Sublime Package https://packagecontrol.io/packages/JsPrettier everything works too. You could try if your problem with both packages/foramtters is path related. If have not tried installing prettier(d) using npm.

0 Likes