在PhpStorm或其他Jetbrains IDE中保存时重新格式化代码 [英] Code reformatting on save in PhpStorm or other jetbrains ide

查看:222
本文介绍了在PhpStorm或其他Jetbrains IDE中保存时重新格式化代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何设置代码在保存时自动重新格式化?

How can I set up that the code is reformatted automatically on saving?

所以我不必总是按 Ctrl + Alt + L .

So I don't always have to press Ctrl + Alt + L.

推荐答案

实际上是可能的.
这个想法是记录一个非常简单的宏,该宏选择所有行( Ctrl + A ),格式( Ctrl + Alt + L ),取消选中所有(向上和向下箭头)并保存文件(Ctrl + S),然后将此宏绑定到 Ctrl + S .

Actually it is possible.
The idea is to record a very simple macro that selects all the lines (Ctrl+A), formats (Ctrl+Alt+L), deselect all (Up and Down arrow) and saves a file (Ctrl+S), and bind this macro to Ctrl+S.

免费的Ctrl + S更改全部保存"的键盘快捷键

  1. 打开文件>设置;
  2. 搜索键映射"并打开它;
  3. 搜索全部保存",然后双击操作全部保存";
  4. 选择删除Ctrl + S";
  5. 再次双击全部保存",然后选择添加键盘快捷键";
  6. 选择"Ctrl + Alt + Shift + S"作为第一笔划.
  7. 确认并退出设置.

记录宏

  1. 编辑>宏>开始宏录制
  2. Ctrl + A ,然后按 Ctrl + Alt + L ,然后是向上箭头,然后是向下箭头,最后是 Ctrl + Alt + Shift + S
  3. 单击页面右下角的停止"按钮,停止录制宏.
  4. 给该宏起一个类似格式化并保存"的名称
  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"

将Ctrl + S分配为格式化并保存"

  1. 打开文件>设置;
  2. 搜索键映射"并打开它;
  3. 搜索格式化并保存",然后双击格式化并保存"操作;
  4. 选择添加键盘快捷键";
  5. 选择"Ctrl + S"作为第一笔划.
  6. 确认并退出设置.

最后,享受PhpStorm!

Finally, enjoy PhpStorm!

这篇关于在PhpStorm或其他Jetbrains IDE中保存时重新格式化代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆