Don't Just Show Users the Code: Adding a Built-In Code Editor to Your Vibe Project
Embedding a code editor in your vibe project is a workbench, not a display: Monaco vs CodeMirror, lazy loading, highlighting, completion limits, diff views, tabs, sandbox tiers, mobile fallback, and a fictional funnel of 1000→620→380→210→150.

Three things first, so you read the right article. One: this is not about rich text editors — our site already has a guide on integrating rich text editors into vibe projects, and everything about writing articles, taking notes, and formatting belongs there. Two: this is not about real-time collaborative editing — our site already has a guide on that, and everything about several people editing one document at the same time belongs there. Three: this is not about AI code completion products, and it does not rank which completion model is smarter. This article is about one thing: embedding a code editor into your own product, so users can edit code, run it, and take the result with them without ever leaving your page. The whole article is told through one running fictional example: the example product is "Code Notebook", an app that lets users write short snippets of code in the browser and run them with one click; the example user is "A-Zhe", a university student who has just started learning JavaScript; every number, conversation, and scene in the example is fictional practice, included to make the ideas concrete — not a real product and not real events. The funnel numbers in the last section are a fictional sample too, used to do the math, not real data.
A-Zhe first opened Code Notebook on a Wednesday evening. He wanted to try a snippet that sorts an array of grades. The page had a single input box, like an oversized notepad: no line numbers, no colors, and when he mistyped a bracket the page just said "run failed". He copied the code to another editor, fixed it there, pasted it back, and after three round trips he left. The author of Code Notebook only realized later what had happened: the user did not fail at writing code — the product had never given him a place where writing code felt safe. Letting users look at code and letting users write code inside your product are two different things. The first is a display; the second is a workbench. A display only needs to look tidy. A workbench has to answer a different list of questions: can you spot a mistake the moment you make it, can you get back when you mess something up, is running the code safe, what happens on a phone, and will the thing you worked hard on still be there when you close the page. This article walks through those questions one by one.
First, decide what the editor is for
Before you build anything, decide what role the editor plays in your product, because that answer drives every tradeoff that follows. Code Notebook's answer is simple: it is where users practice. They write a short piece of JavaScript, hit run, and see the result right away. Its editor does not need to be a full professional tool; it needs three things: writing feels smooth, mistakes are obvious, and running is safe. Your product may be different: some people use an editor as a settings screen where users edit a JSON config; some use it as a template editor where users change variables in an email template; some build interview tools where the editor is the exam room. Those three editors look nothing alike, and copying someone else's feature list wholesale is how you go wrong.
A practical way to decide is to list the three things users do most often in the editor, and the three things they fear most. Code Notebook's three most common actions are writing a few dozen lines of code, hitting run, and saving code that works; its three biggest fears are losing code, crashing the page by running it, and not working on a phone. Once that list exists, the priorities write themselves: autosave and run isolation are must-haves, while extra language support and fancy themes can wait. If your product is for teams editing production configs, the fear list changes completely — "who just broke the production config" — and diff views and version rollback jump to the front of the queue. There is no standard editor, only the answer to "what are your users afraid of". Skip that question and every step after it gets bloated, until you have built a miniature development tool nobody loves.
There is another common trap: treating the editor as the whole product. A-Zhe comes to Code Notebook to practice, to get a snippet running — not to move house into your editor and live there. He writes it, runs it, saves it, and the task is done. No matter how good the editor is, it is still just the tool for completing the task, not the task itself. So do not stuff the editor with chat, a community, and leaderboards before the main road is paved. Pave the "write, run, save" road first. Once the main road is smooth, users come back on their own; if the main road has potholes, no garden you build beside it will get visitors.
Choosing: Monaco or CodeMirror
Embedding a code editor means choosing between two names: Monaco and CodeMirror. Monaco is the editor underneath VS Code, the most full-featured option; CodeMirror is much lighter, built like building blocks. Pick by what your product actually needs, not by reputation. Here is the short version, with reasons after: if you want something close to a complete development experience, with many languages, strong IntelliSense, and plenty of experienced users, pick Monaco; if you want a lightweight embed, a fast first screen, one or two main languages, and something that works on mobile, pick CodeMirror. Code Notebook picked CodeMirror, for reasons that follow.
The first real difference is bundle size. Monaco is a heavyweight: the full build runs to several megabytes, and even JavaScript alone needs careful on-demand loading and code splitting, or the first screen gets noticeably slow. CodeMirror 6 is modular by design — you take only what you use, the core is small, and language support is added one piece at a time. For a practice app like Code Notebook, a first-time visitor may only be curious and never touch the editor; if the page stalls for three seconds before the editor even appears, that visitor leaves. Size is not a vanity metric, it is a retention metric. But Monaco's weight buys real things: more mature language services, stronger IntelliSense, and a feel closer to VS Code. If your product is a heavyweight tool for developers, and your users will happily wait a few seconds for a better editor, that trade is worth making. The test is simple: are your users dropping by to write two lines, or did they come specifically to write code? The first group wants the light option; the second can afford the heavy one.
The second difference is language support. Monaco ships with syntax highlighting and basic language services for dozens of languages, ready out of the box; CodeMirror's language packages come from its ecosystem — mainstream languages are all covered, but obscure ones may need hunting down or writing yourself. Code Notebook's users write JavaScript, with occasional HTML and CSS, so three language packages are enough and CodeMirror is plenty. But if your product needs a dozen languages, each with decent completion and checking, Monaco's out-of-the-box coverage will save you a lot of work. Do not be dazzled by the "how many languages" number — count which ones your users actually write. Only when that number passes five does Monaco's advantage start to matter.
The third difference is mobile behavior, and it is the one most easily underestimated. A phone has a virtual keyboard, no physical arrow keys, and text selection done entirely by finger — all of it is hard on an editor. CodeMirror has done a lot of adaptation work here: it is light and touch-friendly. Monaco works on mobile too, but it is heavy and feels more like a desktop editor squeezed into a phone. Half of Code Notebook's visits come from phones, and that fact alone shaped the choice. On licensing, both are friendly: Monaco is MIT, CodeMirror is MIT, and neither charges you for commercial use the way some commercial editors do. One last warning: once you pick, switching is expensive, because highlighting, completion, themes, and shortcuts are all built around the choice. Spend half a day building a minimal prototype with each, let two or three real users write code for ten minutes in each, and then decide — that beats reading a hundred comparison articles.
The first-screen cost: load only the language packs you use
An editor's biggest hidden cost is not its features, it is its loading. Before the editor appears, the page has to download the editor's code. Monaco in full is several megabytes, and CodeMirror with a pile of language packs can swell past a megabyte too. When A-Zhe first opened Code Notebook on his dorm's slow network, the editor spun for four seconds before appearing, and he almost concluded the page was broken. You cannot fix this by hoping users' networks keep getting faster; you fix it with engineering.
The first move is lazy loading: only load the editor when the user actually needs it. Code Notebook's approach is to show a "Start writing code" button and a read-only code preview first, and only download the editor when the user clicks. That change cut hundreds of kilobytes from the first screen and made opening much faster. The logic is simple: not every visitor will write code, so let everyone see the page quickly, and let the people who want to write code wait one extra second — a good trade. If your product opens straight into the editor and cannot be split this way, fall back a step: load the core first, then load language packs asynchronously. Users can accept the editor frame and cursor appearing first with highlighting half a second late; they cannot accept a black screen while everything loads.
The second move is to load only the language packs you use. Code Notebook supports JavaScript, HTML, and CSS, so it bundles exactly those three. Beginners often grab "all languages" for convenience, and then users who only write JavaScript pay for the Python, Rust, and Go language packs too. Going one step further, load by user behavior: download the Python pack only when the user picks Python, and never download it otherwise. This matters most for multi-language products. The third move is caching and code splitting: put the editor's code in its own chunk so the browser caches it and the second visit needs no re-download. With a content delivery network, the math gets better still. Finally, measure the real numbers: on a 4G connection, on an ordinary Android phone, how many seconds from opening the page to typing the first character? Past three seconds, it is worth going back and cutting again.
Syntax highlighting and themes: legible first, pretty second
Syntax highlighting is the most visible thing in an editor, and the easiest to overdo. It has exactly one job: making the structure of the code visible at a glance. Keywords one color, strings another, comments another, matching brackets visible, mistakes underlined — that is enough. The classic beginner mistake is treating highlighting as decoration: the more colors the better, until every token has its own shade. The result is a screen like a paint palette, and the eyes tire first. The first theme in Code Notebook used seven or eight highlight colors, and A-Zhe's feedback was blunt: "It looks busy, and I can't read it." Cutting back to four main colors made the code clearer. The test is one sentence: can the user find the line they want to change within three seconds? If yes, the highlighting is good; if no, no amount of beauty helps.
Themes need both light and dark versions, and users should choose for themselves — do not decide for them. Some people like black text on white, some only use dark mode, and some switch with the time of day. More importantly, follow the system: if the user's system is in dark mode, open in dark mode the first time instead of making them dig through settings. Contrast is a hard requirement, not a taste question: comment text must not fade into invisibility, the selected line must be recognizable at a glance, and the cursor must be findable. There are free contrast checkers online; running one takes five minutes and is worth doing.
One thing is often overlooked: colorblind-friendliness. Roughly one in twelve men has some degree of color vision deficiency, and if your highlighting tells right from wrong using only red and green, those users cannot see it. The fix is simple: never let color be the only signal for important information. An error gets a red underline plus a small icon or a text hint; in a diff view, "deleted" and "added" get red and green plus a strikethrough and a plus sign. Bracket matching, current-line highlighting, and line numbers — those small features together make an editor you can actually read. Remember: highlighting is a tool, not decoration. Legible first, pretty second.
Autocomplete: lend a hand, don't grab the wheel
Autocomplete is the feature in an editor most likely to hurt with good intentions. Done well, a user types a few letters and saves half the keystrokes; done badly, every keystroke turns into a fight with a popup. Local keyword completion is the first tier, and the one to build first: suggestions based on variable names, function names, and keywords in the current file. This tier needs no network, costs nothing, and rarely goes wrong — and it covers most practice scenarios. A-Zhe types "con" while writing a for loop, "console" pops up, he hits Enter, done. The keys to local completion are speed and accuracy: suggestions must appear instantly, ranked by relevance, with irrelevant items kept out of the top spots; and pressing Esc must dismiss the popup without hiding the code.
The second tier is model-powered completion — the AI completion everyone talks about. It is far more capable and can guess whole blocks of code from context, but it costs far more too: money, network, latency, and occasionally wrong code. For a practice app like Code Notebook, AI completion is a nice-to-have, not a necessity. When to stop comes down to three lines: first, the cost line — completion calls must not cost more than the retention they bring, and practice users have little willingness to pay for completion; second, the latency line — if a suggestion takes more than a second to appear, the user has already typed it themselves, and slow completion is worse than none; third, the correctness line — if the model often suggests wrong code, users go from "let me check it" to "I don't trust it at all", and trust is hard to win back once lost.
My advice: get local completion right first, run it live for a while, and see whether users are actually complaining that completion "isn't smart enough" before deciding to plug in a model. If you do plug one in, give users a switch, and make it possible to turn it off. One more detail: the completion popup must not steal focus or jump out to block the code when the user only wants to type a bracket. Completion is the co-driver, not the driver — the wheel stays in the user's hands.
Diff view: make changes visible, and reversible
The diff view is what turns an editor from "you can write here" into "you can afford to change things here". Without a diff, users change code from memory, and when it breaks they have no idea which line caused it. Code Notebook's approach is to automatically compare the current version against the last version that ran successfully every time the user hits run, marking changed lines beside the line numbers — old on the left, new on the right. Once A-Zhe flipped a comparison operator in a sort function and the output came out scrambled; he opened the diff view, spotted the changed line at once, flipped it back, and it worked. Without that view, he would have spent ten minutes comparing two blocks of code line by line.
A diff built into a product needs to be friendlier than the ugly text comparison in a terminal. First, side-by-side beats top-and-bottom for readability: old on the left, new on the right, lines aligned, deleted lines in red with a strikethrough, added lines in green with a plus sign, and changed lines highlighted across the whole row. Second, give users accept and reject actions: if your product merges code from AI suggestions or templates, users need to decide line by line — "I'll take this change, not that one". Accepting everything at once looks efficient but pushes all the risk onto the user; confirming line by line hands control back to them. Third, a diff cannot be only for experts: the colored blocks beside line numbers and a summary like "3 lines changed, 1 deleted" let beginners understand what happened at once.
There is one more scenario people forget: the user wants to go back to yesterday's version that worked. Diffs and versions belong together — without versions, a diff can only compare against "the last one", never "the one before that". So once the diff is in, saving versions is the natural next step, covered in the saving section below. The conclusion to remember: a diff is not a debugging tool for developers; it is reassurance for every user — if you break it, you can see it, and you can get back.
Multi-file tabs and unsaved warnings: don't let users lose things
Users start with one file, and sooner or later they want a second. By his third week of practice, A-Zhe started pulling helper functions into another file, and if Code Notebook still had only one editing area, he would be copying and pasting between two files. Multi-file tabs exist for this: like browser tabs, a row of tabs at the top, click one to switch. A few details matter: tabs show file names, and an unsaved file gets a small dot on its tab; when there are too many tabs to fit, they should scroll horizontally instead of being squeezed invisible; and before closing a tab with unsaved changes, always ask first.
The unsaved warning — the dirty state — is the most important reminder in an editor, and also the easiest to make annoying. The principle is to warn only when something would actually be lost, and never to interrupt for nothing. If a user changed one character and closes the page, a warning is right; if they only clicked into the editor and changed nothing, do not show a confirmation dialog. Going further, autosave: when the user stops typing for two seconds, quietly save a draft to the browser's local storage, so it is still there next time they open the page. Autosave plus the little unsaved dot eliminates most lost-code accidents. But autosave is not a replacement for an explicit "Save" action: users need to know which copy is the official saved version they can share, and which is only a draft. Code Notebook's rule is that drafts autosave locally, while clicking "Save" writes to the account — the two are separate and do not interfere with each other.
Close confirmation has to cover every way out: closing a tab, closing the browser, hitting back, refreshing the page. Browsers have a built-in beforeunload event that shows a system confirmation dialog when a file has unsaved changes — a few lines of code with the most practical effect. Do not underestimate those few lines: every accidental close they block earns the product a little more trust. And the reverse is also true: if your product never warns, a user who loses code once will never put anything important there again.
Run button safety: three tiers of isolation, no shortcuts
The "Run" button is the most dangerous part of Code Notebook, and also the most underestimated. The user's code runs because you run it for them, and where it runs and what it can touch decides whether your product is safe. Never take the shortcut of running user code directly in the browser with eval. Eval runs with the current page's permissions: malicious code can read your page's data, send requests on the user's behalf, and crash the page. A-Zhe only writes sorting code, but your product has no idea what the next user will paste in. Set the safety boundary from day one, in three tiers — more capable, more expensive.
The first tier is a browser sandbox: run the user's code inside an isolated iframe, blocked from touching the parent page or sending arbitrary network requests. This is the cheapest tier, and it fits scenarios that only do pure computation — sorting, computing a factorial, drawing a simple shape. Code Notebook's first version was this tier: user code only computed, never touched the network or storage, and that was enough. The second tier is a WebAssembly sandbox: compile the code to WASM before running it, with better isolation and better performance — suited to products that want more languages without building a backend execution service. The third tier is isolated backend execution: user code is sent to your server, run in a disposable container, and destroyed afterward, leaving nothing behind. This is the safest tier and the most expensive: you have to manage timeouts, resource limits, and infinite loops that could fill up your servers.
Which tier to pick depends on what you let users run. Frontend exercises only: the first tier is enough. Reading files, calling APIs, running long tasks: you need the third tier. Whichever tier you choose, three bottom lines cannot be broken: first, there must be a timeout — an infinite loop must not be able to hang the browser or the server, and Code Notebook sets it at five seconds; second, resources must be capped — kill the run when memory or CPU goes over the limit; third, error messages must be friendly to the user — "line 3 is missing a bracket" is far more useful than a pile of stack traces. When a user hits Run, they expect to see a result, not your server configuration. Keep safety in the dark, and keep the experience in the light.
Mobile fallback: be honest on a small screen
Half the visits come from phones, but that does not mean half the users will write code on a phone. A-Zhe once tried editing a Code Notebook exercise on the subway: the virtual keyboard took half the screen, selecting text by dragging never landed where he wanted, and he gave up after three lines. That experience is not your fault; it is the phone's limitation — a small screen, no physical keyboard, and imprecise selection. So the mobile strategy should be honesty, not brute force.
Code Notebook's approach has two tiers: on a phone, the default is read-only mode — users can view code, hit run, and see the result, but heavy editing is discouraged; a plain line at the top says: "Editing code on a phone is awkward — we suggest continuing on a desktop, and your link is already saved." There is also a "keep editing anyway" entry that does not block people who insist on trying. Read-only mode is not laziness; it is respect for the user's time. On a phone, most users want to take a look or check something, not write a hundred lines. Do "view" and "run" well, leave "write" to the desktop, and mobile satisfaction goes up, not down.
A few concrete details: in read-only mode, keep line numbers and syntax highlighting, because the user is reading code; make the Run button big enough for a finger; let the result area scroll instead of being pushed off screen by the keyboard. If a user insists on editing on a phone, at least make the font size adjustable, keep auto-indent on, and stop auto-closing brackets from getting in the way. Finally, sync drafts between desktop and phone: the user glances at code on the subway, opens the laptop at home, and the code is still there — that is the real value of mobile.
Keyboard shortcuts and accessibility: don't lock people inside the editor
Editors are heavy keyboard territory, and shortcuts decide whether experienced users stay. Get the three basic groups right first: save, run, and search. Code Notebook uses Ctrl+S to save, Ctrl+Enter to run, and Ctrl+F to search — muscle memory users bring from other editors, so do not invent different combinations. The shortcut list should sit somewhere visible, ideally a question-mark button in the editor's top-right corner that opens the full list. Users do not need to memorize it; they need to find it.
More important than shortcuts is the Tab key trap. On the web, Tab normally means "move to the next focusable element", but inside an editor, users press Tab to indent. If your editor swallows Tab for indenting only, keyboard users can never Tab their way out again — this is a keyboard trap, one of the most serious accessibility failures. The correct approach: Tab indents inside the editor, but leave a way out — pressing Esc returns focus to the page first, so the next Tab moves on, or provide an explicit "exit editor" shortcut. Code Notebook's approach is Esc to leave edit mode, with a small hint line under the editor. Do not treat this as a minor detail: for people who only use a keyboard, it is the line between being able to use your product and not.
Accessibility also covers screen readers, focus management, and contrast: the editor area needs the right role labels, line-number changes should be readable, and every button needs a text label, not just an icon. Doing this is not about passing an audit — it is because some of your users genuinely need it. When shortcuts and accessibility are done well, users never notice them; when they are done badly, users leave on day one.
Saving, versions, and share links: let code outlive the page
When users finish writing code, they want two things: don't lose it, and let me show it to someone else. Saving has two layers: local drafts and official saves. Drafts autosave in the browser and survive closing the page; official saves live under the account and open on any computer. Users must be able to tell the two apart: a draft is a draft, a save is a save. Do not let users believe "it autosaved, so it is saved", then discover on another computer that it is gone — that disappointment is fatal. Versions are the natural extension of saving: every official save keeps a version, labeled with what changed, so users can jump back to any version at any time. A-Zhe's habit is to save a version at each small milestone — names like "sorting works" and "added dedup" — and browsing history reads like a diary.
Share links are what make code come alive. The pattern can follow gist: every saved snippet gets a short link, and opening the link shows the code and lets the viewer run it to reproduce the result. Links should come in two kinds: "view only", and "edit a copy of your own" — the second kind must fork into a new copy, never overwrite the original author's work. The expiry policy should be decided early and told to users upfront: are free share links permanent, do they get cleaned up after long inactivity, and is there a warning before cleanup? The most painful thing is not a link expiring — it is a link silently dying, so a user shares it with a friend and the friend opens a 404. Code Notebook's rule is written plainly: share links are permanent, but after a year with no visits there is an email reminder first, and cleanup happens only thirty days after that. The rule itself is not what matters — what matters is that the rule is written down, and kept.
Doing the math: the funnel tells you which section to fix first
The sections above are all about how to build; this section is about how to know what to fix first after launch. The numbers below are a fictional sample, used to demonstrate the method — not real data. Suppose Code Notebook gets 1,000 visits in a month: 620 people open the editor, 62.0%; 380 write their first line of code, 61.3% of the previous step; 210 run it successfully, 55.3%; 150 save or share, 71.4%. Overall, from visit to save or share, that is 15.0%. Checking the losses: 380 leave after the first step, 240 after the second, 170 after the third, 60 after the fourth, and 150 reach the end — 380+240+170+60+150 adds up to exactly 1,000.
The most useful part of this funnel is not the 15.0% total, but the conversion rate at each step. 62.0% opening the editor means the entry point is fine — most people are willing to try. 61.3% writing the first line means loading and highlighting are not scaring people away. 55.3% running successfully is the lowest step in the whole funnel, which means "wrote it but cannot run it" is the biggest leak. 71.4% saving or sharing is the highest step, which means once the code runs, users are very willing to keep it. If these numbers were real, the conclusion would be clear: fix the run success rate first — do not build new themes first, do not add new languages first. Then break down the run failures one by one: are the error messages unreadable, is the timeout too short, or is the sandbox blocking normal code? That is what a funnel is for: it does not tell you whether the product is good; it tells you where next week's effort should go.
Two warnings when doing this math. First, do not look only at the total — look at each step's conversion rate. A good-looking total can be propped up by heavy entry traffic hiding a collapse somewhere in the middle. Second, read the funnel numbers alongside user feedback: a low run success rate does not by itself say whether the code is hard to write or the editor is hard to use — the numbers do not answer that question; asking users and reading error logs does. Numbers are the map, not the answer.
Before launch, run through this checklist
An editor is not something you finish once; it is a workbench you keep polishing. But on launch day, at least get these things in place: the choice is made, language packs load on demand, light and dark themes both exist, local completion works, diffs are visible, unsaved changes trigger a warning, running has a sandbox and a timeout, phones get a read-only mode, the Tab key lets you out, and saving and share links work. A-Zhe's story is fictional, but the lesson in it is real: users do not stay because your editor has the most features; they stay because writing code here feels smooth, runs work, and nothing gets lost. Get those three things right first, and then think about smarter features. Embedding the editor is only the beginning — the moment a user writes their first line inside your product, hits run, and sees the result, your product stops being "a place that shows code" and becomes "a place where you can write code".
Comments (0)
Related articles
Flexbox lays things out in one direction at a time, and when it is done right, the nav bar, the card wall, and the cart rows all behave. This guide follows MDN's Basic concepts of flexbox, Aligning items in a flex container, and Controlling ratios of flex items along the main axis: the two axes, containers and items, direction and wrapping, free space, the three flex properties, alignment on both axes, and gaps and auto margins.
One order is one object: table, dishes, total, paid — all filed by label. This guide follows MDN's Working with objects, JSON, and Object references: object literals, dot vs bracket notation, adding and deleting properties, for...in with hasOwn, methods and this, getters and setters, references vs copies, Object.assign and friends, null-prototype objects, JSON's strict rules, and stringify and parse with their number-precision trap.
You already call functions every day; this guide names what you have been doing. Following MDN's Functions, Arrow function expressions, and Rest parameters: declarations versus expressions, parameters and arguments, default values, rest parameters, spread syntax, return values, arrow function shorthand, the this trap, callbacks, and scope.