问题
I'm using VS Code and for formating my code I use a formatter 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?
回答1:
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.
You will need to use the formatting in combination with an alignment plugin like this: 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.
来源:https://stackoverflow.com/questions/47472907/editor-config-how-to-align-the-code