How to fix pasted code formatting on Mac
You can do this with Note My, and here is how to get the structure back when a paste lands as a wall of run-together statements — every step in order, and what to set before you start.
Pasted code goes wrong in two ways, and they need different fixes. Sometimes the indentation is simply gone — every line flush left, or the leading spaces turned into something odd. Sometimes it is worse: several statements squashed onto a single line, so there is no line structure left to indent at all.
Both are fixable in Note My. The second is the interesting case, because most tools that call themselves formatters only adjust the leading whitespace of lines that already exist.
Why pasted code arrives as one long line
Three things collapse code on its way to the clipboard.
The source was styled text. A chat transcript, a wiki page or a slide renders code as rich text, where line breaks are paragraph attributes rather than characters. They do not always survive the trip.
The line endings do not match. Text written on Windows separates lines with a carriage return and a line feed; older Mac text may use a lone carriage return. An editor that recognises only the line feed shows you one very long line.
The code genuinely was on one line. Minified JavaScript, a one-liner from a shell history, statements written with semicolons to save space. Nothing has been lost; it needs unpacking.
All of this happens on your Mac. Nothing is uploaded, there is no account to make, and the code you paste never leaves the machine.
Paste is always plain text
⌘V never pastes styled text. Whatever the clipboard carried arrives as characters — the code, its spaces and its tabs — and nothing else. There are no fonts, sizes or colours to strip afterwards.
That narrows the problem: anything wrong came in with the code itself. Here is what to expect.
| What the clipboard carried | What lands in your document |
|---|---|
| Styled text from a browser, a chat or a document | The characters only. Nothing to strip afterwards. |
| Tabs and spaces in the indentation | Exactly as they were, until you ask for a re-indent. |
| A very large block of code | Our large-file engine keeps the window usable, with a progress sheet you can cancel. |
| No line breaks at all | One long line, for now. The re-indent below unpacks it. |
Set the language before you re-format
A re-indent follows the conventions of the language you are working in, so the first thing to get right is which language the document is set to. Paste into a brand-new, empty tab and our advanced language identifier sets it for you, quietly, with no sheet in the way. Paste into a tab that already has content and you get an accent dot on the status bar's Identify pill instead — a nudge, not an interruption.
Click that pill to open the Language Inspector. It states "Identified programming language: X", offers an override pop-up, and waits for Confirm or Cancel.
A document that arrived as Plain Text is one choice away from a proper re-indent: set the language yourself from the pop-up and carry on. CSS is the one to watch — a pasted stylesheet is usually happiest set by hand, so glance at the pill before you reach for Indent rather than after.
Re-indent, and unpack the statements that share a line
Our indentation engine does two jobs for you. It puts braces, blocks and statements at the correct depth using your brace style and width, and it splits statements sharing a line onto lines of their own. That second job is what turns a run-together paste back into readable code.
The toolbar Indent button is your way in. The braces glyph sits within reach of whatever you are reading, and one click opens the Indentation sheet with every control for the job in one place.
-
Click Indent in the toolbar
The braces glyph opens the Indentation sheet. Nothing in your document changes at this point — the button opens a sheet, it does not act.
-
Confirm the language
The sheet's picker offers a global default plus fifteen languages, and changing it snaps the other controls to whatever you have stored for that language. Swift, C, C++, JavaScript, TypeScript, Go, Kotlin, Rust, PHP, CSS, Java, Python, Ruby, Shell and HTML each have their own settings, kept separately, so the choices you made for one language are waiting the next time you work in it. Pick the one your code is actually written in and the layout follows that language's own conventions.
-
Choose a brace style and a width
Two brace styles: same-line, the default, and next-line. Indent width defaults to 4, and the sheet accepts 1 to 12. Spaces are the default rather than tabs. Two language locks behave differently: Go is locked to tabs, on by default, and Python is locked to four spaces, off by default.
-
Read the preview as you set the controls
The preview card redraws the moment you change something, showing a compact
if <condition> { … }specimen laid out in the brace style and width you have just picked. It is the quickest way to see what those settings look like in practice before you commit to them. -
Save first, then press Apply
Press ⌘S before you apply. The whole document is laid out in one pass, and a saved file gives you a clean way back whenever you want one: File ▸ Reload from Disk (⌘R) sets the reformatted text aside and reads the version on disk, exactly as you saved it.
When a comment has swallowed real code
A paste that lost its line breaks can leave a single-line comment sitting in front of live code, so everything after the marker is commented out. In the Indentation sheet, turn on Recover damaged comments before you apply.
It splits the line where the comment ends and the code begins — // Preserve state let x = 1 let y = 2 becomes three lines, the comment on the first. The code it rescues comes out indented along with everything else.
The checkbox is off by default, and it is deliberately cautious. It works on the single-line comments that cause the trouble, and an ambiguous line is left exactly as it was — you will not find a real comment turned into live code. Documentation markers — ///, //!, /**, /*! — are always left alone, and block comments are re-flowed inside their markers, never un-commented.
Comment recovery covers thirteen languages: Swift, C, C++, JavaScript, TypeScript, Java, Kotlin, Rust, Go, PHP, Python, Ruby and Shell. In HTML and CSS, comment text comes back exactly as you wrote it, ticked or not.
Check the result
Indentation guides mark each level of depth, which makes a wrong one obvious at a glance. They are on by default; if the file in front of you has none, the toolbar Guides toggle turns them back on. Ten guide styles are available in Settings ▸ Guides — Dots is the default, with Color Dots, Dashed, Thin, Medium, Thick, Rail, Beam, Accent and Spectrum alongside it.
The status bar is the other quick check. Watch the Lines counter: a paste that arrived as one line reads 1 before you apply, and something sensible afterwards. The Occ counter is useful here too — select an identifier and it tells you how many times it occurs.
Colour is worth a glance too. If our syntax engine is picking out keywords, strings and comments as you would expect, the language is right. If the document is one flat colour, go back to the Identify pill.
Clear what the paste brought with it
Copied code often carries characters you cannot see: zero-width characters, non-breaking spaces where ordinary ones belong, smart quotes a compiler will reject, mixed tabs and spaces in the indentation. Our hidden-character scanner puts the answer in the status bar's hidden-characters pill — green Clean, orange "N hidden", or red "N hidden · D risky" — so you know before you compile.
Two commands in the toolbar Clean menu cover the two cases:
- Clean AI Copy/Paste Markers — one click, no dialogue. It removes only artefacts that cannot change how your text renders, reads or indents; anything needing judgement is counted and reported rather than touched. A toast says which: "No hidden copy/paste markers found." or "Cleaned N hidden marker(s). Your text was not rewritten."
- Clean Invisible / Special Characters… — the Review All sheet, for when you want to see every finding first. Twenty-one categories, four presets with Code-safe as the default, and a findings table of line, column, code point, category, action and risk. Our cleanup rules touch nothing you have not agreed to.
Line endings are only ever tidied in one direction: stray Windows line endings are brought into line with the rest of the file, and nothing is converted the other way on your behalf. To change them deliberately, use File ▸ Line Endings. Cleaning pasted text automatically is a setting, and it is off by default, so a paste lands untouched until you ask for something. Our cleanup rules work entirely on your Mac: nothing is uploaded, and the code you paste never leaves the machine.
What you stay in control of
A re-indent is something you ask for, and every part of it is yours to set.
- When it happens. A paste lands exactly as it arrived and stays that way until you press Apply.
- Your settings, per language. Brace style and indent width are held separately for each language, so the choices you made for Swift are still there the next time a Swift document is in front of you.
- Your own conventions. Semicolons in JavaScript, pointer spacing in C, and trailing commas in Swift and Python all start out set to preserve, so a re-indent lays your code out rather than restyling the way you write it.
- The whole document at once. One pass covers the file end to end, however long it is, so you are never walking through it block by block.
- A dependable way back. Save before you apply, and File ▸ Reload from Disk (⌘R) hands you the file on disk, whole.
- Everything on your Mac. No account, no sign-in, nothing uploaded. The code you paste never leaves the machine.
Troubleshooting
I clicked Indent and nothing happened
The button opens the Indentation sheet; the document changes only when you press Apply. If Apply produced no visible change, your code already matched the settings you chose — try a different indent width and apply again to see the sheet reach the document. An empty document has nothing to lay out yet.
It re-indented, but the structure is wrong
A re-indent always gives you something back rather than refusing, so a document with unbalanced braces still comes back laid out, following the braces exactly as they stand. Check that the language picker is set correctly and that the paste is complete — an unclosed brace takes everything below it to the wrong depth. Set the picker to the language you are actually working in: each of the fifteen carries its own stored brace style and width, and the layout follows the conventions of the one you choose.
Nothing was unpacked — it is still one line
Check the language first. Splitting statements apart follows the conventions of the language the document is set to, so choose one from the Identify pill or the sheet's picker and apply again. If it is still one line, the paste may genuinely be a single statement.
A very large paste is taking a moment
There is no size cap on a re-indent, so even a very large document is laid out whole rather than in pieces — give it a moment on a big file and the finished text comes back in one go. A Large File badge in the status bar tells you our large-file engine is carrying the document, so very big files stay open and workable.
Getting back the text you pasted
Save before you apply and the way back is a single command: File ▸ Reload from Disk (⌘R) sets the reformatted text aside and gives you the version on disk. If the paste was never saved, paste it again — the clipboard still holds the original. Our auto-recovery safety net is there for crashes and power cuts, so a saved copy is the thing to have in hand before any whole-document change.
Comment recovery in HTML and CSS
In HTML and CSS, comment text comes back exactly as you wrote it. For the thirteen languages comment recovery covers, tick Recover damaged comments before you apply — the checkbox lives in the Indentation sheet rather than in Settings, and it starts off, so a document is only ever changed when you ask.
The indentation looks right but the compiler still complains
Look for invisible characters. A non-breaking space or a zero-width character inside an identifier is invisible in every editor and fatal in most compilers. Open the hidden-characters pill, or run Clean ▸ Clean Invisible / Special Characters… over the whole document.
Frequently asked questions
How do I re-indent a document?
Click Indent in the toolbar. The braces glyph opens the Indentation sheet, where you confirm the language, choose a brace style and a width, then press Apply to lay out the whole document in one pass.
Will pasting bring fonts and colours in with the code?
Paste is always plain text. Styled text from a browser, a chat or a word processor arrives as characters only — the code, its spaces and its tabs — with no fonts, sizes or colours to strip afterwards.
Can I re-indent with tabs instead of spaces?
Yes, in the Indentation sheet. Spaces are the default and the width defaults to 4, with a range of 1 to 12. Go has a tabs lock that is on by default; Python has a four-space lock that is off by default.
Does re-indenting change my code, or only the whitespace?
Mostly whitespace, but not only: statements sharing a line are split apart, and brace placement follows the style you pick. With comment recovery on, a line where a comment marker swallowed real code is split too. Save before you apply, and File ▸ Reload from Disk is the dependable way back to the version on disk.
Why did my pasted code get the wrong language?
A run-together paste is the case most likely to land on the wrong language, or to stay as Plain Text. Set the language yourself — from the Identify pill, or from the picker in the Indentation sheet — and then re-indent. Colour is the quickest confirmation that you have it right.