vimtricks.wiki Concise Vim tricks, one at a time.

How do I make Vim wrap long lines at word boundaries instead of mid-word?

Answer

:set linebreak

Explanation

By default, when wrap is enabled, Vim wraps long lines at the window edge — which can split words in the middle. Setting linebreak tells Vim to wrap only at word-boundary characters (spaces, hyphens, etc.), keeping words intact and making prose and documentation much more readable.

How it works

  • :set linebreak (abbreviated :set lbr) enables word-boundary wrapping
  • Lines are still stored as a single long line in the file — no actual newlines are inserted
  • Wrapping occurs at characters listed in the breakat option (default: !@*-+;:,./?")
  • Works only when wrap is also on (:set wrap is the default)
  • :set nolinebreak reverts to character-level wrapping

Example

Without linebreak, a long paragraph might display as:

This is a very long line that will be broken right in the middl
e of a word when it reaches the window edge.

With :set linebreak:

This is a very long line that will be broken right in the
middle of a word when it reaches the window edge.

Tips

  • Pair with :set showbreak=↪\ to display a visual indicator at the start of soft-wrapped lines
  • Add :set breakindent so wrapped continuation lines are indented to match the start of the logical line — essential for code or Markdown
  • For writing prose, combine all three: :set wrap linebreak breakindent
  • To navigate by visual lines (rather than logical lines) when wrapping is on, use gj and gk instead of j and k

Next

How do I visually select a double-quoted string including the quotes themselves?