linux - Can less wrap lines like fmt does?
2014-07
Like most people I use less
as my terminal pager. Occasionally I view files consisting of very long lines of plain or marked-up text. By default less
folds these lines at the terminal window edge. That is, words get broken at the last column, making the text difficult to read. Is there any way of getting less
to instead wrap the lines at word boundaries, the same way that fmt
or Emacs visual line mode does?
I am aware that I could simply pipe the input through fmt
before viewing it, though that requires me to know my terminal width in advance. I was hoping there was some way of getting less
to nicely wrap lines, and to automatically reformat them when the terminal window is resized.
Excerpt from the less man page:
-S or --chop-long-lines
Causes lines longer than the screen width to be chopped rather than folded.
That is, the portion of a long line that does not fit in the screen width
is not shown. The default is to fold long lines; that is, display the
remainder on the next line.
Does less
have an incremental search?
I'm on xubuntu.
Unfortunately the less
pager does not have this functionality. The only search options available are /
for a forward search, and ?
for a backward search.
You can use view
(vim
in read only mode) as a replacement for less.. vim has incremental search, just add:
set incsearch
to your .vimrc
I added incremental search to less and pushed it to a fork on GitHub.