website icon indicating copy to clipboard operation
website copied to clipboard

FAQ or Cookbook -- Less Chop/Scroll (instead of wrapping) super-long-lines

Open n1vux opened this issue 1 year ago • 0 comments

re https://github.com/beyondgrep/ack3/issues/234 and 325 (and ack2 rollover)

Better workaround for minified JS multi-screenful-lines that aren't properly named as ${file}.min.js so as ignorable, or that needs to be searched because one doesn't have the source JS, and other similarly very-very-long-line files that actually want to be searched :

Ack --pager='less --chop-long-lines -iR' will frequently hide the match instead of centering, but at least only uses one line for the many-thousand-char line with a match (or several). This Less Chop mode allows arrow-key and emacs scrolling, and provides reverse video > affordances at ends of lines to show which lines are cropped/scrollable. This is abbreviable as less -S. ack-234-scroll-right-1 ➔➔ ack-234-scroll-right-2

This option can be put this in ${HOME}/.ackrc as a default.

In $HOME/.ackrc, might want to include less option -F aka --quit-if-one-screen so that it DWIMishly emulates ack --nopager when vertical scroll isn't needed.

To try this out in a POSIX shell,

ACK_PAGER_COLOR='less -FSiR'  ; export ACK_PAGER_COLOR

less ... -F or --quit-if-one-screen Causes less to automatically exit if the entire file can be displayed on the first screen. -S or --chop-long-lines Causes lines longer than the screen width to be chopped (truncated) rather than wrapped. That is, the portion of a long line that does not fit in the screen width is not displayed until you press RIGHT-ARROW. The default is to wrap long lines; that is, display the remainder on the next line. See also the --wordwrap option. --wordwrap When the -S option is not in use, wrap each line at a space or tab if possible, so that a word is not split between two lines. The default is to wrap at any character.

n1vux avatar May 01 '24 20:05 n1vux