编辑器或扩展程序,可以自动缩进二维表格如表格

问题描述

我正在寻找一种编辑器或插件(最好是VS Code),该编辑器或插件可让我自动格式化以下数组:

const lines = [
    [ "step-1","step","step-1","",`["1"]` ],[ "r","repeater","r",`[]` ],[ "mycheckBox__1[]","input","mycheckBox[]","__1",[ "myradio__1","myradio",[ "mytext__1","mytext",`[""]` ],[ "myurl__1","myurl",[ "myemail__1","myemail",[ "myselect__1","myselect",[ "mymultiselect__1[]","mymultiselect[]",[ "myfile__1","myfile",[ "mymultifile__1[]","mymultifile[]",[ "mycheckBox__2[]","__2",[ "myradio__2",[ "mytext__2",[ "myurl__2",[ "myemail__2",[ "myselect__2",[ "mymultiselect__2[]",[ "myfile__2",[ "mymultifile__2[]",[ "r_count","r_count",[ "root-mycheckBox[]","root-mycheckBox[]",[ "root-myradio","root-myradio",[ "root-mytext","root-mytext",[ "root-myurl","root-myurl",[ "root-myemail","root-myemail",[ "root-myselect","root-myselect",[ "root-mymultiselect[]","root-mymultiselect[]",[ "root-myfile","root-myfile",[ "root-mymultifile[]","root-mymultifile[]",[ "step-2","step-2",`["2"]` ],];

像这样更具可读性:

const lines = [
    [ "step-1",`[]`    ],`[""]`  ],];

我一直在寻找一些在线工具,但没有找到。虽然有一些扩展名可以格式化CSV文件,但要先将我的代码转换为有效的CSV文件,然后在“查找”和“替换”中添加方括号,会有些麻烦。

因此,目前,如果它们不是太大,我仍将手动按这样的数组进行制表。在我的代码编辑器中拥有自动格式化工具会很酷。

解决方法

我在您的代码上尝试了该扩展名,并且效果很好:Smart Column Indenter

make columns out of code demo


此扩展贡献命令,例如extension.smartColumnIndenter.indentN,默认情况下绑定到键绑定: Ctrl + I Ctrl + N ,因此您可以使用它或重新绑定它,而不是像在演示中一样使用上下文菜单。

,

CudaText编辑器(免费)现在具有插件,它是根据此问题编写的。

  • 菜单“插件/插件管理器/安装”
  • 找到“ CudaExt”插件
  • CudaExt插件将提供菜单项“选定行中的插件/ Cuda-Ext /对齐/对齐逗号分隔的列”

plugin

请注意,在您的示例中,它不对齐最后的]括号,因为它适用于任何语法。某些语法可以在行尾允许op[ind]之类的内容,因此它不会对齐]括号以免破坏代码。