I hit ⌘D⌘R, you won't believe what happened next!

OK, so you know the contents has almost nothing to do with the pseudo-clickbait-y title, right ? Well, actually it has: this is about the single most useful command in Drupal development. Guess which ?

Keep calm and flush cache

If you've done any Drupal development in the last ten years or so, you have probably noticed that the single most often used command in your work process is clearing the cache, be it in the Drupal UI at admin/config/development/performance (or its earlier incarnations), or hopefully with drush cr in Drupal 8 or drush cc all in earlier versions.

The thing is, while you probably switched from the web UI to Drush years ago, it's still a minor annoyance to have switch to a terminal, press the ▲ / ↵ combo and switch back to PhpStorm. Or switch view from the editor to the Terminal view. Isn't there a better way ?

You bet there is: as soon as I asked myself I knew it had to be easy, so let's see how it's done in PhpStorm in three steps:

create an external tool

map a key to it

trick: there's no third step, it's already done

drush cr in PhpStorm 2016.3

Here is in detailed form how to implement the two steps above. Note that these instructions assume that (a) you are working in a Drupal 8 project opened one level above the Drupal docroot, as is typical in Composer-built projects, (b) Drush is local to the project, as it probably should. Adjust according to your actual situation.

Choice

Value

Notes

Open tool dialog

macOS: PhpStorm / Preferences / Tools / External Tools / "+"

Linux: File / Settings / Tools / External Tools / "+"

Name

Drush CR

Or whatever...

Description

Keep calm and flush cache!

...fits your fancy

Group

External tools

Although the widget looks like a selector, you needn't stick to existing groups, but may create one just by
typing its label.

Synchronize files after execution

Checked

If you haven't excluded sites/default/files you may be interested in the changes wrought by the command. Otherwise, keep unchecked to reduce IDE work.

Open console

Checked

You normally want to see if something happens during the flush. Don't worry: only one console gets used for all calls to the tool.