Writing code
In a file whose language it knows, the editor colors the text, matches and closes brackets, comments lines out, marks the other uses of a name, lays JSON and XML out and folds blocks away.
At a glance
| Key | Action |
|---|---|
| ⌘\ | The matching bracket |
| ⇧⌘\ | Select what the brackets hold |
| ⌘/ | Comment or uncomment |
| ⌥⌘P | Reformat |
| ⌥⇧⌘P | Minify |
| ⌥⌘[ | Fold or unfold here |
| ⌥⇧⌘[ | Fold everything to this depth |
| ⌥⇧⌘] | Unfold everything |
Colors and languages
Text is colored by its language — keywords, strings, comments and numbers each have a color — and
the header names the language. The editor decides it the way the viewer
does: from a file type of your own that names one, then the
file’s name, and only when the name says nothing, from the first lines — a mode line, a #! line, or
<?xml. Forty-nine languages are known.
Language…, in the View menu, colors the file as another language or as none. Tick Always color .go files like this to keep the choice for every file with that ending; a file with no ending has nothing to keep it for, so the box is gray.
- The colors follow what you type: opening a comment or a string recolors the lines after it, down to where it closes. In a big file they arrive a moment after the text.
- In a file with no language, the text is plain. Closing brackets, commenting, marking names and laying out need a language; matching brackets and folding work without one.
Brackets
The bracket at the cursor, or the one just before it, is marked together with its partner. One with no partner is marked in red.
- Round, square and curly brackets, each kind matched on its own, so a stray one of one kind does not upset the others.
- In a file with a language, a bracket inside a string or a comment does not count. In a plain file, every one does.
- ⌘\ goes to the partner, and pressed again comes back. Away from any bracket, it goes to the closing bracket of the block the cursor is in.
- ⇧⌘\ marks what the nearest pair around the cursor holds. Each further press widens it: the brackets too, then what the next pair out holds, and so on.
- A partner more than a million characters away is not looked for, and nothing is marked.
As you type
- An opening bracket or a quote brings its closer, with the cursor between; typing the closer steps over it, and Backspace straight away takes both. Close brackets as they are typed turns this off, and its entry says where a closer is not put in.
- Enter after an opening bracket starts the next line one level further in. Between a pair —
{}— it also puts the closer on a line of its own below, at the old indent. - A closing bracket typed on a line of nothing but spaces takes one level off the line.
All three need a language. Typed over a marked block, or into a column block, a bracket or a quote goes in on its own.
Comments
⌘/ comments out the line the cursor is on, or every line the block reaches. Pressed again, it takes the comments off.
- The markers are the language’s own. Where it has comments that run to the end of the line —
//,#,--— each line gets one, at the shallowest indent of the lines so the code still lines up, and blank lines are left alone. JSON is commented with//. - A block only partly commented is commented whole first, so a second press puts every line back.
- Where the language only has comments with an opening and a closing marker, as HTML, CSS and XML do, the block — or the line — is wrapped in one. A column block wraps each line on its own.
- One press is one step of undo, and the block stays marked.
- In a file with no language the header says no language to comment in; Diff has no comments, and says so.
Other uses of a name
While the cursor is on a name and nothing is marked, every other use of that name on screen is marked
— in the picture on the editor’s page, the other uses of count.
- Whole names only, capitals as written:
countis not part ofcounter. - Not in strings or comments, and only in a file with a language.
- Mark other uses of a name turns it off.
Laying a file out
⌥⌘P lays JSON or XML out one level to an indent. ⌥⇧⌘P does the opposite, putting it on as few lines as it allows.
- It lays out the marked block, where there is one and it reads as the language on its own — one object out of a large file — and the whole file where there is not. The block stays marked.
- An indent is the one the editor writes: a tab, or spaces, as the settings say.
- Only the whitespace between the pieces moves. Strings keep their escapes, numbers the way they were typed, comments their place. XML keeps its attributes in their order with their quotes, and an element with text in it is left exactly as it is inside.
- Text that does not read as the language is not touched: the header says where it stopped — not JSON at line 12, column 4.
- Any other language says so — Go is not laid out here. A column block is refused.
- It is one step of undo, and the line endings, the encoding and a missing last line break are kept.
Folding
A block folds away to its first line, with a marker saying how many lines are hidden. Where the block ends on a line of its own — a closing brace, an end tag — that line folds too and shows after the marker, so the block reads as one line.
- ⌥⌘[ folds the innermost block the cursor is in, or opens the fold the cursor is on.
- ⌥⇧⌘[ folds every block as deep as the one the cursor is in, so the blocks beside it close and what holds them stays open. Outside any block, it folds the top level.
- ⌥⇧⌘] opens every fold.
- A click on the arrow beside a line number, or on the marker, folds or opens that block.
The rule beside the numbers points down where a block can fold, points right in yellow where one is folded, and has a small tick where a block ends. The block the cursor is in is drawn a shade brighter along it, from first line to last.
What a block is depends on the language:
| Language | A block is |
|---|---|
| Most | What a pair of brackets holds, across lines — not counting brackets in strings or comments |
| YAML, Python, XML | A line and the lines under it indented further, as well as brackets |
| Markdown | A heading, down to the next heading at its level |
| None | A line and the lines under it indented further |
A block has to hide at least one line. The folds are found again a moment after you stop typing.
- ↑, ↓ and the page keys step over a fold. Finding, going to a line, undo and jumping to a bracket open the fold their target is in.
- Changing a hidden line, or joining a fold’s first line to the next, opens the fold first, so nothing changes out of sight. A column block reaching across a fold opens it too.
- Folding only changes what is shown. It is no step of undo, a save writes every line, and the folds are gone once the file is closed.