Sublime 工具自带代码格式化的功能,但在某些场景下格式化代码后并不是我们想要的代码格式,且是点击保存ctrl+s才触发的格式代码事件,so,为关闭点击ctrl+s格式代码,我们需要改命令 save 的默认快捷键源码

1.查看ctrl+s快捷键的command(命令)

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。

Preferences -> Key Bindings - Default:命令save

sublime自动格式化方法 随笔 第1张

 

2.安装 PackageResourceViewer 插件

Ctrl+Shift+P -> Install Package  -> PackageResourceViewer

安装后可看 PackageResourceViewer README.md 说明 :

"reindent_on_save": ["css", "SCSS", "html", "Js"]

You can specify file types which you want to be reindented on save (reindented保存指定文件类型)

`PackageResourceViewer: Open Resource`:

Command to open the resource. If saved, the correct directory structure will be created in the `Packages` folder. This command will only be displayed if the `single_command` setting is true.

`PackageResourceViewer: Extract Package`:

Command to extract a package to the `Packages` directory. This command is only available in ST3.

sublime自动格式化方法 随笔 第2张

#命令操作:Ctrl+Shift+P -> PackageResourceViewer: Open Resource

sublime自动格式化方法 随笔 第3张

#点击PackageResourceViewer: Open Resource会弹出安装过的插件:

sublime自动格式化方法 随笔 第4张

#选择 Reindent on save,弹出命令 save 的源码设置:

sublime自动格式化方法 随笔 第5张

#打开 ReindentOnSave.py,前面有提到设置 reindent_on_save 可以保存指定的文件类型,所以这里把这里改成 False,这样再操作 ctrl+s 时就不会自动格式代码了

 sublime自动格式化方法 随笔 第6张

 

3.将 reindent 格式化命令改成其他快捷键

在 Preferences -> Key Bindings - User 下加代码:keys 的值可改成其他

1 2 3 4 5 6 7 {   "keys" : [ "ctrl+shift+r" ],   "command" "reindent" ,   "args" : {      "single_line" false      } }

 在 Edit -> Line -> Reindent 可查看快捷键的设置

扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄