How to Add a Prefix or Suffix to Every Line
Wrap every line in a list with the same opening and closing text. Five common patterns: HTML lists, markdown bullets, JSON arrays, SQL IN clauses, CSV column. The browser shortcut for any of them is one paste.
The five patterns
Most prefix/suffix needs fall into one of five shapes:
| Goal | Prefix | Suffix | Wrapper |
|---|---|---|---|
HTML <ul> | <li> | </li> | <ul>...</ul> |
| Markdown bullet list | - | (none) | (none) |
| JSON string array | " | ", | [ ... ] |
| SQL IN clause | ' | ', | (...) |
| CSV column with constant first column | row, | (none) | (none) |
The Prefix & Suffix tool handles all five. Paste the lines, type the prefix and suffix, copy the result. Add the wrapper manually before pasting into the destination.
Worked example — building a SQL IN clause
Source list:
alice
bob
carol
dave
Want:
WHERE name IN ('alice', 'bob', 'carol', 'dave')
Steps:
- Paste the list into the Prefix/Suffix tool.
- Set prefix to
'(single quote). - Set suffix to
',(single quote, comma). - Toggle on "no trailing separator on last line."
- Copy the output:
'alice', 'bob', 'carol', 'dave' - Paste between the parentheses of your
IN ( ... )clause.
Total time: ~5 seconds for any list size.
Worked example — building an HTML list
Source list of book titles. Want a clean <ul>.
- Paste into the Prefix/Suffix tool.
- Prefix:
<li> - Suffix:
</li> - Copy. Wrap manually with
<ul>...</ul>at top and bottom.
For more complex HTML output (anchors, classes, data attributes), put the full HTML wrapper in the prefix:
- Prefix:
<li class="book"><a href="/books/ - Suffix:
">view</a></li>
If your input is just slug-style identifiers, the output is a complete linked list ready to paste.
Worked example — JSON string array
Source list:
red
green
blue
Want:
["red", "green", "blue"]
Two ways:
Quick way (one-line array): use prefix ", suffix ",, "no trailing separator," then on output: replace newlines with spaces, wrap with [ and ].
Multi-line array (more readable): use prefix ", suffix ",, then add [ at the top and ] at the bottom in your text editor:
[
"red",
"green",
"blue"
]
For a real JSON parser, the trailing comma in the last line is invalid. The "no trailing separator" toggle handles this:
[
"red",
"green",
"blue"
]
The cleanup step everyone forgets
Three traps that bite if skipped:
- Empty trailing line. If the input has a blank line at the end, the prefix/suffix gets applied to it, producing
"",in the output. The tool's "skip empty lines" toggle prevents this. - Trailing comma on the last item. JSON parsers reject this. SQL parsers reject this. The "no trailing separator" toggle is the fix.
- Quoting characters that need escaping. If your data contains the same character as your prefix/suffix (e.g., a single quote in the data when you're using single quotes as the prefix), you'll produce broken syntax. Pre-process to escape: replace
'with''for SQL, or escape"with\"for JSON.
Beyond the basic pattern
For more complex line wrapping (different prefix per line, conditional prefix, regex-based wrapping), drop to a programming editor with multi-cursor support (VS Code, Sublime, JetBrains IDEs) or a regex-aware find-and-replace tool. The Find & Replace tool with regex enabled can do conditional and pattern-based wrapping.
For the broader reference on list operations, see List Operations: The Complete Guide. For sorting before wrapping, see How to Sort Lines Alphabetically. For format conversion, see Format List for SQL/JSON/HTML.
Frequently asked questions
How do I remove a trailing comma from the last line in a JSON array?
The TextKit Prefix/Suffix tool has a 'no trailing separator' toggle that handles this automatically. Manually: after the prefix/suffix pass, find/replace the final comma with nothing. The TextKit tool is faster — one toggle does it.
Can I prefix only some lines?
Not with a pure prefix/suffix tool. Use a regex find-and-replace on the line patterns you want to match. The Find & Replace tool with regex enabled handles selective prefixing.
What if my prefix or suffix contains special characters?
It just works — prefix/suffix tools treat the input as literal text, not patterns. Special regex characters, HTML entities, and quote marks all pass through as-is.
Why do I need a tool when I can just type the prefix in front of every line?
Speed. Twenty lines hand-edited takes a minute. Two thousand lines takes two minutes with a tool, two hours by hand. Past about ten lines, the tool wins on time.
Can I do this in VS Code without a separate tool?
Yes — multi-cursor mode (Cmd+D / Ctrl+D to add cursors at every line start) lets you type the prefix once and have it appear on every line. Works for up to a few hundred lines before performance degrades.
Keep reading
Written by the TextKit team. We build the tools we write about — try the Prefix & Suffix tool used in this post.