中只输入括号后缩进一个额外的标签

中只输入括号后缩进一个额外的标签

本文介绍了Sublime Text 3 在 javascript 中只输入括号后缩进一个额外的标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在,我正在 Sublime Text 中使用 ReactJS 开发一个项目.每当我在括号之间按下 Enter 键时,它就会跳到另一行并添加一个额外的空格.举个例子:

Right now, I am working on a project using ReactJS in Sublime Text. Whenever I hit enter in between the parentheses it would break to another line and add an extra space. Here's an example:

初始启动

光标在中间,然后我回车:

The cursor is in the middle, then I hit enter:

当前结果

然后它会在之后添加这个额外的缩进.导致我浪费时间并修复它.

Then it adds this extra indent afterwards. Causing me to waste time and fix it.

想要的结果

这是我按回车后想要的结果:

This is my desired result after hitting enter:

先谢谢你!

推荐答案

打开 Preferences ->Key Bindings-User 并添加以下内容:

Open Preferences -> Key Bindings-User and add the following:

{ "keys": ["enter"], "command": "insert_snippet", "args": {"contents": "\n\t$0\n"}, "context":
    [
        { "key": "setting.auto_indent", "operator": "equal", "operand": true },
        { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
        { "key": "preceding_text", "operator": "regex_contains", "operand": "\\($", "match_all": true },
        { "key": "following_text", "operator": "regex_contains", "operand": "^\\)", "match_all": true }
    ]
}

如果文件以前是空的,请在键绑定周围添加方括号 [ ] 并保存.如果文件有其他自定义键绑定,请将其粘贴在开头括号 [ 之后的开头,并确保在其后添加逗号 , 以确保文件是有效的 JSON.

If the file was previously empty, add square brackets [ ] around the key binding and save. If the file has other custom key bindings, paste it at the beginning just after the opening bracket [, and make sure you add a comma , after it to make sure the file is valid JSON.

这篇关于Sublime Text 3 在 javascript 中只输入括号后缩进一个额外的标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 10:58