How can you indent multiple lines all at once?

Following the principles of white-spacing and indenting, if I needed to wrap multiple already written lines in a new tag/element, how do I add additional indentation to all those lines simultaneously?

This is very late, but for anyone who comes across this: You can indent multiple things by selecting everything you want to indent, and then press [Tab].

(this is also the reason i prefer always using [Tab] instead of [spacebar] for indenting)

115 Likes

That’s really helpful, thanks!

1 Like

Great tip. I had the problem when I copied an example to my existing text but could not indent them to fit in at once. This tip is good. Thanks.

2 Likes

Oh man…
What a helpful tip!!
Thanks

1 Like

wow, exactly what I needed
thank you

Thanks for this awesome tip.

I discovered this today before we got to this question, mostly because I didn’t want to tab each row individually. By trial I selected all the rows and hit tab and Wahlah!

If you prefer using [spacebar] to indent your code rather than using [tab], you can select multiple lines by holding the [alt] key and clicking on the beginning of each line you want to indent. Then, you can press [spacebar] and all the selected lines will be affected.

18 Likes

select the lines you want to indent and press ‘tab’ for forward indent and ‘shift+tab’ for backward indent

5 Likes

omg it moves! thank you!

1 Like

thanks @zormus as a newbie i found this extremely helpful!

There are also shortcuts that can be useful for formatting code in Codecademy editor:

  1. Select lines above/below cursor: Ctrl + Shift + up/down arrow
  2. Duplicate line: Shift + Alt + up/down arrow
    • You can also select a few lines and then use this shortcut to duplicate some bigger parts of your code!
  3. Multiple cursors (two shortcuts for this one):
    • Alt + click left mouse button in the place you want to set an additional cursor
    • Alt + Ctrl + up/down arrow (put a cursor above/below current one)

I hope these shortcuts will speed up your work with code :wink:

14 Likes

Discovered this article right after doing it line by line :joy:. Anyways, good to know for the future. Thanks!

1 Like

But I used to read about a topic here on the forum that discourages using tab as it renders differently on different browsers. I can’t find that post so I’ll just attach this one.
https://discuss.codecademy.com/t/indentation-error/369771?u=amateurjunior

In many code editors, you can select all of the lines of text you want to indent with the cursor and then on the keyboard type the ctrl and ] keys together, or on a mac it’s cmd and ]. Likewise, you can outdent by selecting the text and typing the ctrl and [ keys together or on a mac cmd and [.

2 Likes

Awesome, saves a lot of time!

I highlighted a section of code then hit the space bar and it deleted everything I had highlighted. Is there a way to un-delete what I lost.

This helped a load. Thanks!

I found that the highlighting and [Tab] suggestion worked fine, but elsewhere in the comments was a suggestion for highlighting lines using Alt and pressing space bar twice - this didn’t work for me. By trial and error I found that if you click on the first line you wish to indent and hold CTRL and SHIFT you can increase the size of the cursor to encompass multiple lines using the up or down arrow keys. If you then push the space bar it will indent all the lines encompassed by the large cursor. You can do this from white space, i.e. the first cell of the text editor or the least indented (i.e. the first) line of code… To remove the large cursor simply click anywhere in the editor.