How do I put a register as true line list so embedded newlines stay split correctly?
Answer
:put =getreg('a', 1, 1)
Explanation
Most register pastes are character-oriented, but advanced edits often need to preserve exact line structure. :put =getreg('a', 1, 1) returns register a as a List of lines, then inserts those lines directly. This avoids subtle formatting surprises when a register contains embedded newlines, mixed linewise content, or text captured from scripts/macros.
How it works
getreg('a', 1, 1)reads registerawith two important flags- Second argument
1requests the raw form rather than display-transformed text - Third argument
1returns a List (one item per line) instead of one joined string :put =...evaluates that expression and inserts the result below the cursor
Using the list form gives you deterministic insertion semantics, which is valuable in automation or when registers were built programmatically.
Example
Assume register a contains multi-line content from a prior operation. Instead of relying on a plain "ap, run:
:put =getreg('a', 1, 1)
Result:
Each original register line is inserted as its own line, preserving boundaries
Tips
- Swap
'a'for any register name, including+or*when clipboard integration is enabled. - Combine with list transforms, e.g.
map(getreg('a', 1, 1), 'trim(v:val)'), before:put.