Indentation and Whitespace
- Indenting
- New lines
- Brackets and quotes
- Re-indenting
- Tabs or spaces
- Line endings
- .editorconfig
- Tidying when you save
Indenting
To indent or outdent lines, select them and choose Text ⟩ Shift Right (command ]) or Text ⟩ Shift Left (command [). You do not need to select whole lines: any line that is partly selected is shifted, and with nothing selected, the line the cursor is on.
With text selected, tab and shift tab do the same.
With nothing selected, tab inserts a tab, or the spaces that stand for one. At the start of a line, it takes the cursor straight to where the line belongs under the lines around it.
New lines
Pressing enter starts a new line with the indentation it should have: the same as the line before, or a step further in after an opening brace or tag. Between a pair that has just been opened, such as { and }, it opens the pair out, with the cursor on an indented line between them.
Three commands in Text ⟩ Text start a line in other ways:
- New Line Below (command enter) starts a new line under the current one, wherever in the line the cursor is, without breaking the line
- New Line Above (shift command enter) starts one above it
- Indent New Line (control enter) starts a new line indented a step further. If any characters follow the cursor, they move to a line of their own beneath it.
So if you have <div>|</div> (the pipe is the cursor) and press control enter you get:
<div>
|
</div>
Brackets and quotes
When you type an opening bracket or quote, Espresso types the closing one for you, and when you then type the closing one yourself, it steps over the one that is there. Deleting an opening bracket that has nothing in it yet deletes its partner too. Select some text and type a bracket or quote to wrap the selection in the pair.
Which characters pair up depends on the language. In HTML text, for instance, an apostrophe is left alone, while inside a tag quotes come in pairs.
Re-indenting
Espresso can lay code out again from its structure:
- Text ⟩ Re-Indent Selection and Text ⟩ Re-Indent All correct the indentation of the selection or the document
- Text ⟩ Re-Indent with Spacing… also lets you choose where spaces and new lines go, using an example
- Text ⟩ Delete and Re-Indent (command delete) deletes the selection and tidies what is left around it
When you open a document that has been minified, a bar at the top offers to re-indent it so that it is easier to read and edit.
Tabs or spaces
Espresso decides how a document is indented from, in order:
- An .editorconfig file, if one applies to the document
- The document itself. If its lines are already indented in one clear way, Espresso carries on in that way. You can turn this off with Use a file's own indentation when it is clear in the Text Editing preferences.
- What you have chosen for the document's language
- The Text Editing preferences
To see or change the indentation of the document in front, use the View ⟩ Indentation menu. Choose Tabs or Spaces, and a width of 2, 3, 4 or 8. For tabs, the width is how wide a tab is shown.
Choose View ⟩ Indentation ⟩ Use for This Language to have every document of this language start out with these choices. Choose it again to take that back.
Changing these does not change the text that is already in the document. To convert a document's existing indentation, use Text ⟩ Convert / Strip ⟩ Spaces To Tabs… or Tabs To Spaces….
Line endings
Espresso keeps the line endings a file already has. The View ⟩ Line Endings menu shows which they are: Unix (LF), Mac Classic (CR) or Windows (CRLF). Choose another to convert every line ending in the document.
New documents get the line endings chosen in the Text Editing preferences.
.editorconfig
If your project has an .editorconfig file, Espresso follows it, ahead of its own preferences. These properties are understood:
indent_style,indent_sizeandtab_widthend_of_lineinsert_final_newlinetrim_trailing_whitespace
Tidying when you save
Two options under When Saving in the Text Editing preferences tidy a document each time it is saved:
- Remove spaces from the ends of lines. Markdown documents are left alone, because two spaces at the end of a line mean a line break there.
- End the file with a line ending
Both are off to begin with, and an .editorconfig file that says otherwise for a file wins.