sublime text 2 - json 格式化程序

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34896840/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 18:14:32  来源:igfitidea点击:

sublime text 2 - json formatter

jsonsublimetext2indentationsublime-text-plugin

提问by user2342558

I'm using SublimeText2.

我正在使用SublimeText2

How to reindent Jsoncode with a shortcut?

如何Json使用快捷方式重新缩进代码?

I've already installed packageControland it works.

我已经安装了packageControl并且可以使用。

I already tried JsonReindentpackage but it has not a shortcut by default and i don't know its command name.

我已经尝试过JsonReindent包,但默认情况下它没有快捷方式,我不知道它的命令名称。

I already have this command (from my previous sublimetext2 on another pc, where it works fine):

我已经有了这个命令(来自我之前在另一台电脑上的 sublimetext2,它工作正常):

// JSON reindent
{ "keys": ["ctrl+shift+j", "ctrl+shift+j"], "command": "json_reindent" },

But here it doesn't work.

但在这里它不起作用。

Can you help me, please?

你能帮我吗?

Thanks.

谢谢。

采纳答案by MattDMo

If you look at the source, the name of the sublime_plugin.TextCommandsubclass is SublimeJsonReindentCommand. Per the conventions for command names, the resulting command is named sublime_json_reindent. Simply change your key binding to:

如果查看源代码sublime_plugin.TextCommand子类的名称是SublimeJsonReindentCommand. 根据命令名称约定,生成的命令被命名sublime_json_reindent。只需将您的键绑定更改为:

{ "keys": ["ctrl+shift+j", "ctrl+shift+j"], "command": "sublime_json_reindent" },

and you should be all set.

你应该准备好了。

回答by pigfly

I have come across this issue too. I tried to figure it out by install jsFormat as follows:

我也遇到过这个问题。我试图通过如下安装 jsFormat 来解决这个问题:

  1. Open Package Controll panel command+shift+p(mac), install package.
  2. Install jsFormat.
  3. Edit the shortcut for the jsformat: sublime text preferences, package settings, jsFormat

  4. Choose Key-Binding user, then edit

    [
      {
        "keys": [
          "command+l"
        ],
        "command": "reindent"
      },
      {
        "keys": [
          "ctrl+shift+s"
        ],
        "command": "auto_save"
      }, 
      {
        "keys": [
          "ctrl+alt+f"
        ],
        "command": "js_format"
      }
    ]
    
  5. So next time when you try to format json code, just use ctrl+alt+f.

  1. 打开包控制面板command+ shift+ p(mac),安装包。
  2. 安装jsFormat
  3. 编辑 jsformat 的快捷方式: 崇高的文本首选项,包设置,jsFormat

  4. 选择 Key-Binding 用户,然后编辑

    [
      {
        "keys": [
          "command+l"
        ],
        "command": "reindent"
      },
      {
        "keys": [
          "ctrl+shift+s"
        ],
        "command": "auto_save"
      }, 
      {
        "keys": [
          "ctrl+alt+f"
        ],
        "command": "js_format"
      }
    ]
    
  5. 所以,下一次,当你尝试JSON格式代码,只需使用ctrl+ alt+ f

That's all.

就这样。

Hope this will help you.

希望这会帮助你。

Cheers

干杯

回答by Ar No

Install this packages via CMD + SHIFT + P > Install package > Search for Pretty JSON and install.

通过 CMD + SHIFT + P > Install package > Search for Pretty JSON 安装这个包并安装。

enter image description here

在此处输入图片说明

And then turn ugly json via CMD + CTRL + J (OSX) CTRL + ALT + J (Windows/Linux) in pretty JSON!

然后通过 CMD + CTRL + J (OSX) CTRL + ALT + J (Windows/Linux) 在漂亮的 JSON 中变成丑陋的 json!

Source is on GitHub. Credit

源在GitHub 上信用

回答by ecamur

I am using Linux OS. I found the solution first installing the package controller then Pretty JSON package.

我正在使用 Linux 操作系统。我找到了首先安装包控制器然后Pretty JSON 包的解决方案。

  1. Install the package controller for sublime here

  2. Install Pretty JSON packages via CMD + SHIFT + P > Install package > Search for Pretty JSON and install. Details are here.

  1. 此处安装 sublime 的包控制器

  2. 通过 CMD + SHIFT + P > 安装包 > 搜索 Pretty JSON 并安装来安装 Pretty JSON 包。详细信息在这里