简体   繁体   English

编辑器配置-如何对齐代码

[英]Editor config - how to align the code

I'm using VS Code and for formating my code I use a formatter CTRL + SHIFT + I . 我正在使用VS Code,并且为了格式化我的代码,我使用了格式化程序CTRL + SHIFT + I It works fine, but I would like to be able to format my code to be align in this way: 它工作正常,但是我希望能够格式化我的代码以这种方式对齐:

before: 之前:

export const apiConfig = { protocol: 'https', url: 'www.example.com', timeoutSec: 15 }

after: 后:

export const apiConfig = { protocol: 'https', url: 'www.example.com', timeoutSec: 15 }

Any way to set it up? 有什么办法设置吗? Any specific setting for .editorconfig? .editorconfig是否有任何特定设置?

What you are asking for is impossible to easily achieve in one go within VScode and completely unrelated to .editorconfig , as it only governs rather basic features — by design. 您所要求的是不可能在VScode中轻松实现的,并且与.editorconfig完全无关,因为它只能控制相当基本的功能 -通过设计。

You will need to use the formatting in combination with an alignment plugin like this: https://marketplace.visualstudio.com/items?itemName=steve8708.Align 您将需要将格式与如下所示的对齐插件结合使用: https : //marketplace.visualstudio.com/items?itemName=steve8708.Align

If you feel adventurous, you may be able to hack together a solution which runs both commands in sequence at the push of a keyboard shortcut. 如果您喜欢冒险,则可以通过键盘快捷键按顺序找到同时运行两个命令的解决方案。 However, VScode is not as readily scriptable in this regard as for example Vim is. 但是,在这方面,VScode不像Vim那样容易编写脚本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM