How to indent several lines at once


#1

Hi! I am wondering if there is any way to indent multiple lines of code at once—for example, when adding a div element around several lines of code that have already been written (the previous code becoming the content of this new element). It is a pain to add spaces one line at a time.


#2

Having a text editor nearby is a must. File > New.

Paste in the lines of code you wish to add indentation to. They should all have the same indentation level or greater. Every line must have at least one level of indentation.

Run a quick scan for mixed tabs and spaces, change them all to spaces.

Ctrl+H
Find:  (type a single press of the tab key)
Replace with: '  ' (two space characters)

Now examine the code and find the lines with the most indentation. Copy the indentation spaces only.

Ctrl+H
Find: (the indentation should be here)
Replace with: (an equal number of % characters, plus 2)

Eg.

Replace,

'        ', with,
'%%%%%%%%%%'

That’s four levels of indentation, as an example. Working up from the deepest to the top of nesting repeat the replacement procedure. Once that’s done,

Ctrl+H
Find: %
Replace with: [SPACE]

#3

This is a CodeMirror. Here documentation.


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.