Configure Line Wrapping in Vim and Neovim
Line wrapping in Vim controls whether long lines display across multiple visual lines or extend beyond the window edge. This is purely visual—wrapping doesn’t modify your file. Understanding when to enable, disable, and configure wrapping is essential for different workflows.
Enable and Disable Wrapping
Enable soft wrapping to see long lines across multiple rows:
:set wrap
Use this when reading documentation, prose, or logs where horizontal scrolling gets annoying.
Disable wrapping to see lines extend past the window edge:
:set nowrap
This is better for structured data like CSV files, config files, or code where you need to see exact column positions and alignment.
Toggle between states instantly:
:set wrap!
Smart Wrapping at Word Boundaries
By default, wrap can break mid-word. To break only at word boundaries:
:set linebreak
This respects the breakat option (default breaks at space, tab, and some punctuation). Combine it with wrap for readable soft wrapping.
Add a visual indicator where lines break:
:set showbreak=↪\
The backslash-space adds padding after the indicator. Customize the character to your preference—common choices include ↪, ⋯, or >>>.
Hard Wrapping vs Soft Wrapping
Soft wrapping (wrap) is visual only and never changes your file.
Hard wrapping inserts actual line breaks and modifies your file. Set a hard wrap column:
:set textwidth=80
New text automatically breaks at 80 columns. Reformat existing paragraphs with:
gqip
This applies hard wrapping to the current paragraph. Use gq with other motions like gq5j (next 5 lines) or gq} (to the next blank line).
To prevent accidental hard wrapping, disable textwidth:
:set textwidth=0
Practical Configuration
Add these settings to your ~/.vimrc or ~/.config/nvim/init.vim:
set wrap
set linebreak
set showbreak=↪\
set textwidth=0
set sidescroll=1
set sidescrolloff=10
Breaking this down:
wrapandlinebreakenable soft wrapping at word boundariesshowbreakadds a visual cue for wrapped linestextwidth=0disables hard wrapping (safe default)sidescroll=1andsidescrolloff=10smooth horizontal scrolling when wrapping is off
For Neovim, use ~/.config/nvim/init.lua with Lua syntax:
vim.opt.wrap = true
vim.opt.linebreak = true
vim.opt.showbreak = '↪ '
vim.opt.textwidth = 0
vim.opt.sidescroll = 1
vim.opt.sidescrolloff = 10
Check Current Settings
View wrapping configuration anytime:
:set wrap?
:set linebreak?
:set textwidth?
:set showbreak?
The ? suffix displays the current value. Check sidescrolloff too if horizontal navigation feels jumpy.
Context-Specific Workflows
For editing markdown or prose files, enable these in a filetype plugin (~/.vim/ftplugin/markdown.vim):
setlocal wrap
setlocal linebreak
setlocal textwidth=0
For code files where column alignment matters, disable wrapping:
setlocal nowrap
For CSV or log files, disable linebreak so wrapped lines are easier to trace:
setlocal wrap
setlocal nolinebreak
Use :set wrap? frequently while working—switching between modes takes one keystroke and instantly changes your view.