B
B
b4rret2020-03-14 12:55:29
phpstorm
b4rret, 2020-03-14 12:55:29

Does PHPStorm auto-format php code on save?

Is it possible to auto-format code in PHPStorm on save like VSCode does for JS files using Prettier? Suppose there is a line of code

$table->integer('some_field')->nullable()->references('id')->on('some_table')->onDelete('CASCADE')->someMethod()->antotherMethod();

It does not fit into 80 characters, the IDE needs to make it "beautiful")

Answer the question

In order to leave comments, you need to log in

2 answer(s)
B
bkosun, 2020-03-14
@b4rret

Use the Save Actions plugin or macros:

Free Ctrl+S changing keyboard shortcut for "Save all"
  1. open File > Settings;
  2. search for "keymap" and open it;
  3. search "Save All" and double click the action "Save All";
  4. select "Remove Ctrl+S";
  5. double click "Save All" again and select "Add Keyboard Shortcut";
  6. select "Ctrl+Alt+Shift+S" as first stroke.
  7. Confirm and exit from Settings.

Record the macro
  1. Edit > Macros > Start macro recording
  2. Press Ctrl+A, then Ctrl+Alt+L, then Up arrow, then Down arrow, and finally then Ctrl+Alt+Shift+S
  3. Stop recording the macro clicking on the Stop button on the bottom right of the page.
  4. Give this macro a name like "Format and Save"

Assign Ctrl+S to "Format and Save"
  1. open File > Settings;
  2. search for "keymap" and open it;
  3. search "Format and Save" and double click the action "Format and Save";
  4. select "Add Keyboard Shortcut";
  5. select "Ctrl+S" as first stroke.
  6. Confirm and exit from Settings.

https://stackoverflow.com/questions/12496669/code-...

I
Ilya, 2020-03-14
@New_Horizons

ctrl+alt+L

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question