Small little Adobe Brackets tweak - remove Smart Indent

This post is more than 2 years old.

This may come as a shocker, but I'm really particular about my editor settings. I'm sure no one else is, but I get pretty darn picky about my editor and how it behaves. One issue I've had with Brackets is a feature called "Smart Indent."

Smart Indent will automatically indent your cursor after you hit enter on a block expression. Not sure if "block expression" is the best term, but basically, if you enter a conditional, like if(x), or if you enter a HTML tag that wraps other tags, like <table>, Brackets will indent your cursor one "block" over after you hit enter.

This bugs the heck out of me. While I do use indentation, I don't always use it. So for example, I don't like to indent my HEAD or BODY blocks. It feels silly to me to have one pair of HTML tags at the left gutter and nothing else. I'll not indent TR blocks inside of TABLE tags either, but I do indent the TDs.

Basically - my rule is - and I try to be consistent here - that if the wrapping block has nothing else in it but one main child, I don't see much point in indenting over the text.

When I type in Brackets, I constantly find myself having to hit backspace to return the cursor to where I want it. After a while I begin to see red and start wondering if therapy is in order.

Turns out though it is pretty easy to correct. If you go into the source code and find editor/Editor.js, you can see the following block where the CodeMirror object is instantiated:

I checked the CodeMirror docs and found that I could pass a setting, smartIndent:false, to disable this.

And that's it. To be clear, when I hit enter, the cursor still indents to where the last line began. It isn't flush against the left gutter.

There is no "Preferences" UI yet for Brackets. I could make this an extension, but since I assume I'm probably in the minority when it comes to this preference and the modification is so small, I wouldn't bother creating one.

Raymond Camden's Picture

About Raymond Camden

Raymond is a senior developer evangelist for Adobe. He focuses on document services, JavaScript, and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA https://www.raymondcamden.com

Archived Comments

Comment 1 by jeff posted on 8/23/2012 at 12:00 AM

So are you using Brackets as your everyday editor? Is it stable/feature complete enough for that? I'm fascinated by the idea of Brackets and would love to give it a try if it's close.

Comment 2 by Raymond Camden posted on 8/23/2012 at 12:22 AM

Not yet - no. I'm using it from time to time - writing extensions - etc. My main editor is still Sublime Text 2.

Comment 3 by Sha posted on 3/23/2013 at 5:50 PM

You'll need to comment out this line: cm.indentLine(cm.getCursor().line); around line 1836 in function called newlineAndIndent.

Comment 4 by Raymond Camden posted on 3/23/2013 at 11:00 PM

That must be new. Thanks.

Comment 5 by ACR posted on 2/20/2014 at 1:19 PM

Any idea for Brackets v36?

Comment 6 by Raymond Camden posted on 2/20/2014 at 4:49 PM

Eh? This hack probably still works. There is a new way to handle preferences in Sprint 36 (see their blog), but this preference isn't supported yet.

Comment 7 by rkn posted on 6/26/2014 at 1:02 PM

A bit old post but if someone finds this now, this is how to do it:

Go to Debug->Open Preferences File and add the same setting (but in json mode), for example, this is my preferences file (brackets.json):

{
"debug.showErrorsInStatusBar": false,
"linting.collapsed": true,
"closeBrackets": true,
"smartIndent": false
}

Comment 8 by Raymond Camden posted on 6/26/2014 at 6:05 PM

Yep - preferences are *much* easier to do now. :)

Comment 9 by Danny Santos posted on 2/24/2016 at 2:25 PM

Hey, I have an annoying problem in that Brackets actually removes my indentation. I'll indent to where I want to be and start typing and the whole line will move right back up to the margin! Even for someone who isn't particularly picky with their settings that would be really annoying! Don't suppose you have any insight on how to fix that?

Cheers

Comment 10 (In reply to #9) by Raymond Camden posted on 2/24/2016 at 2:49 PM

Sorry, never seen that one before. To be honest, I don't use Brackets much. I'd file a bug report.

Comment 11 (In reply to #10) by Danny Santos posted on 2/24/2016 at 2:52 PM

Ok, thanks for the reply