Block indent

#1

Is there a way to select a block of code and have all lines indent the same amount to the left or right?

#2

Don’t TAB and SHIFT-TAB do that?

4 Likes
#3

Also CMD+[ and CMD+] on OSX…

#4

And CTRL-[ and CTRL-] on non-macs

1 Like
#5

TAB only shifts the entire block.

#6

I don’t understand. Isn’t that what you asked for?

#7

If you want to align all the lines too, you can shift them all left first until they’re all at the left margin, then shift them all right to where you want them.

#8

For example if i have:

fields: {
            username: {
                validators: {
                    notEmpty: {
                        message: 'The username is required and cannot be empty'
                    }
                }
            },
            password: {
                validators: {
                    notEmpty: {
                        message: 'The password is required and cannot be empty'
                    }
                }
            },
            email: {
                // Initially, the validators of this field are disabled
                enabled: false,
                validators: {
                    notEmpty: {
                        message: 'The email address is required and cannot be empty'
                    },
                    emailAddress: {
                        message: 'The email address is not valid'
                    }
                }
            }

Each line is tabbed over 2, I would like to select the entire block and indent all lines at the same time.

#9

If you select the block and press Tab that will indent all the lines at the same time by one additional tab length.

2 Likes
#10

Indent right: press tab
indent left: shift tab

hope that helps

#11

Use Alt+Shift+Up/Down(arrow keys) to create multiple cursors, then add or delete space/tabs. You can also use Ctrl+click with mouse to create multiple cursors.
https://flight-manual.atom.io/using-atom/sections/editing-and-deleting-text/#multiple-cursors-and-selections

#12

You might be interested to know:

Ctrl-[ and Ctrl-] works very well for indent and outdent of a selected block of code.

#13

That is very helpful to know, thank you!

#15

Somewhat related, is there a way to indent out to the right from several lines, but all to the same location?

What I mean is, if you have several lines of multiple lengths like this

short_name |
rather_longer_name |

And the | symbols are your cursors, if you hit tab several times you get something like this

short_name                 |
rather_longer_name                 |

Is there something you can press to make it look like this:

short_name                              |
rather_longer_name                      |

The only way I can figure out how to do that is manually changing each one until they’re all lined up.