Disable Word Wrap with nw / nowrap in Bash
Long lines in log files, scripts, or configs can get really annoying when they wrap across the screen in less. I wanted a quick way to view files without word wrapping, so I wrote a couple of Bash functions:
# ~/.bashrc
function nw() { less -S "$@"; } # 'nw' = no wrap
function nowrap() { less -S "$@"; }
Both do the same thing - it’s just a naming preference.
What It Does
The -S flag in less tells it not to wrap long lines. Instead of spilling onto the next line, long lines will now scroll horizontally when you press the right arrow key.
Usage Examples
For Files:
nw macros.txt
This runs:
less -S macros.txt
Great for config files, scripts, and CSVs where you want to preserve line structure.
For Pipelines:
grep ERROR logfile.txt | nw
Still disables line wrap, even when you're piping output directly to it.
Why I Use It
Makes reading long CSVs or logs easier
Prevents line breaks that make code harder to follow
Great when reviewing code with long comments or scripts
Bonus Tip
Want to make it permanent in less without needing a function? Add this to your ~/.bashrc or ~/.profile:
export LESS='-S'
But I prefer using nw as an opt-in. Most files look better with wrapping, but when I don’t want it, I really don’t want it.