Sublime Forum

Auto-indentation on Sublime 2?

#1

New user (attempter?) on ST2, seeing it as a possible alternative to TM. Still evaluating. Some questions:

  1. Auto indent on copy-paste does not seem to work? Take the following JS:
var f = function() {
  var a = 1;
};
var q = 2;

Now cut and paste the “var q = 2;” line to sit just below the “var a = 1;” What I want is:

var f = function() {
  var a = 1;
  var q = 2;
};

But I get

var f = function() {
  var a = 1;
var q = 2;
};
  1. Is there any way to select a chunk of text and just auto-indent the whole thing? E.g. if I have
    var f = function() {
      var a = 1;
 var q = 2;
     };

I should be able to select it all, hit some menu item or command, and get automatically:

var f = function() {
  var a = 1;
  var q = 2;
};

Any way?

  1. Auto-comment doesn’t work cleanly? If I create a comment
/*
 */

And then go to the end of the first line and hit enter, I expect to get

/*
  *
  */

But instead I get:

/*

*/

So I manually have to tab over and enter the * ?

0 Likes

#2

For the first issue (paste while keeping indentation): the shortcut key is Ctrl+Shift+V

For the second issue (automatically adding a leading * inside docblocks), you should have a look at my DocBlock plugin: github.com/spadgos/sublime-jsdocs#readme It does that and a heap more. All the info is in the readme.

0 Likes

#3

Hmm, Ctrl-Shift-V (or Cmd-Shift-V) works better, but it still gets the indentation wrong.

  1. Regular paste: keeps the original indentation, which makes no sense (not even sure why this is the default). E.g. if I cut/copy from where indent level is 1 to where it should be 4, it puts in the pasted line with indent level 1. Default should not be this.
  2. Indent paste: tries to align to the new indent level, but still gets it off by one level about half the time, depending on if you paste it at the same line as an indent-changer or before… E.g.
// copy this 
var a = 1;

if (true) {
  q = 5;
  // if you paste it here, it works
}  // if you paste it here, it gets confused by the } and thinks it should be back one, when really it should be indented

It messes it up

0 Likes

#4

Bump?

0 Likes

#5

PHP auto-indent has been broken for the last several updates.

typing the following:

    public function foo() {

and then hitting enter will produce the following:

    public function foo() {

}

The same problem happens for if, else, while, foreach, switch, etc.

0 Likes

#6

So I am not alone here, eh? I like a lot of what ST2 offers, the price is slightly steep. I even managed to get jslint working the way I want it in ST2. But So much of what we do is indenting, I cannot buy it unless auto-indenting works correctly.

0 Likes

#7

@mattsawyer77 can you check if you have auto_indent:false specified in either your User/Base File.sublime-settings or PHP/PHP.sublime_settings (if existing) ?

0 Likes

#8

@vitaLee I have auto_indent:true in my base file settings, don’t have a PHP.sublime_settings anywhere…should I?

FYI the auto-indentation is happening, just not correctly. Here is perhaps a more specific example:

if($something) {
    if($somethingElse) {
        if($anotherThing) { // here is where I hit enter
        
    } // and here is the bracket auto-inserted/indented one level less than it should've been
    } 
}
0 Likes

#9

it’s not necessery to have PHP.sublime_settings. you can create it yourseld and define settings applicable just for php files.
i got your problem and tested both your exmaples and can confirm i dont have your problem. it indents properly (how you expect it) for me.
maybe it’s related to some package you installed.
as i read in other thread you can try to nail the conflicting package (if any) by moving them one by one from the package folder till it indents ok for you.

EDIT: just realised you’re probably talking about the latest dev builds. i personally stick to official releases and am using 2165.

0 Likes