vscode-jetbrains-keybindings icon indicating copy to clipboard operation
vscode-jetbrains-keybindings copied to clipboard

Save without formatting keymap

Open CaiqueCoelho opened this issue 4 years ago • 1 comments

I'm using prettier in my projects and sometimes I need to save a file and run prettier code format on save and sometimes I just want to save without format the code.

VSCode has suport keymap for save with formatting (CTRL + S) and save without formatting(CTRL + K), in this extension we already have a keymap for CTRL + K for Commit to VCS, but we dont have any keymap for save without formatting, so I can't find a way to save my files without formating on save.

My proposal is to create a shortcut to save without formatting, jetbrains keymap does not have support for this shortcut, so we would have to create a different shortcut, is this possible?

Reference: https://code.visualstudio.com/updates/v1_28#_save-without-formatters https://resources.jetbrains.com/storage/products/intellij-idea/docs/IntelliJIDEA_ReferenceCard.pdf

CaiqueCoelho avatar Dec 21 '20 21:12 CaiqueCoelho

I was able to find a workaround to this lack in JetBrains.

With the Prettier package, you are able to use a HotKey for Reformat with Prettier (mine was already set up for Option + Command + Shift + P). Using this we can set up a Macro in order to create two options of Save and Save with Prettier.

Steps

Turn Off Prettier On Save

  1. Navigate to Preferences | Languages & Frameworks | Javascript | Prettier
  2. Toggle off On Save

Create Macro

  1. From within any file, select Edit | Macros | Start Macro Recording
  2. Press your Reformat with Prettier hotkey combination mentioned above (mine was already set up for Option + Command + Shift + P)
  3. Press Command + S for a typical save without Prettier
  4. Turn off Macro Recording by selecting Edit | Macros | Stop Macro Recording
  5. Name your Macro (I named mine Save + Prettier)

Create Hotkeys

  1. Navigate to Preferences | Hotkeys
  2. In the search bar, type in Save to bring up all your options for saving
  3. You will see the normal save labeled Save All and currently mapped to Command + S
  4. You will also see your new Macro under the folder called Macros
  5. Select your new Macro and Add a hotkey map to it of Command + S
  6. You will be asked if you want to remove the binding from where it currently is mapped (normal save), hit yes
  7. Go back to Save All (normal save without Prettier) and assign it to a different hotkey (I used Command + Option + S)

With the following steps, you now have Prettier running as well as a save happening when you do Command + S, and you have a backup option of running a save without Prettier.

Hope this helps!

Mat-Longinow avatar Jul 25 '22 19:07 Mat-Longinow