vscode-jetbrains-keybindings
vscode-jetbrains-keybindings copied to clipboard
Save without formatting keymap
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
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
- Navigate to Preferences | Languages & Frameworks | Javascript | Prettier
- Toggle off
On Save
Create Macro
- From within any file, select Edit | Macros | Start Macro Recording
- Press your
Reformat with Prettier
hotkey combination mentioned above (mine was already set up for Option + Command + Shift + P) - Press Command + S for a typical save without Prettier
- Turn off Macro Recording by selecting Edit | Macros | Stop Macro Recording
- Name your Macro (I named mine
Save + Prettier
)
Create Hotkeys
- Navigate to Preferences | Hotkeys
- In the search bar, type in Save to bring up all your options for saving
- You will see the normal save labeled
Save All
and currently mapped toCommand + S
- You will also see your new Macro under the folder called Macros
- Select your new Macro and Add a hotkey map to it of
Command + S
- You will be asked if you want to remove the binding from where it currently is mapped (normal save), hit yes
- 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!