最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Auto indent method chaining in Sublime Text 3 - Stack Overflow

programmeradmin2浏览0评论

As I type the following javascript code (exact keystrokes):

myObject
.doSomething()
.doSomethingElse();

I'd expect it to automatically bee the following...

myObject
    .doSomething()
    .doSomethingElse();

... as would any other programmer, right?

How do I enable this, and why isn't it enabled by default?

As I type the following javascript code (exact keystrokes):

myObject
.doSomething()
.doSomethingElse();

I'd expect it to automatically bee the following...

myObject
    .doSomething()
    .doSomethingElse();

... as would any other programmer, right?

How do I enable this, and why isn't it enabled by default?

Share Improve this question asked Nov 24, 2014 at 3:46 eye_meweye_mew 9,1637 gold badges34 silver badges52 bronze badges 1
  • I am searching for this feature as well. Have you found anything? – japrescott Commented Mar 12, 2015 at 15:21
Add a ment  | 

2 Answers 2

Reset to default 13 +125

You can use Sublime Code formatter with support JavaScript/JSON Beautifier, this link will show you how to usage this plugin.

Or another way is to insert your code inside Key Bindings - User file:

{"keys": ["alt+shift+f"], "mand": "reindent", "args": {"single_line": false}}

This happens because sublime's smart_indent is not smart enough.

You can fix indentation post factum using code formatter plugin like JsFomat.

Or preventively indent first chained method call. Following lines will have same level of indentation. This solution can be slightly improved by creating new key binding:

    {
        "keys": ["alt+enter"],
        "mand": "insert",
        "args": {"characters": "\n\t"}
    }

Press alt+enter instead of enter, tab for newline to have extra indentation.

发布评论

评论列表(0)

  1. 暂无评论