8

I'm looking for an option to wrap lines of rendered HTML in w3m when they reach a certain length, say 72 characters. By default the text spans the entire width of the window and reading becomes difficult. Here's a screenshot of how an article looks by default in fullscreen w3m:

w3m crappy long lines

In newsbeuter I was able to get the behavior I wanted easily with text-width 72. The same article with text nicely wrapped in newsbeuter:

newsbeuter nicely wrapped text

Is there a way to achieve this kind of line-wrapping at 72 characters in w3m?

The data for the views above is available at this url:

https://www.quirksmode.org/blog/archives/2017/05/why_the_politic.html

1
  • Have you tried anything or has your research pointed you in any specific or particular direction for any potential solutions for this problem? Commented May 11, 2017 at 21:41

3 Answers 3

5
+50

Run w3m with relevant options to dump formatted page to standard output, then pipe the standard output to less command. However, no such options in w3m configuration file.

Manual page w3m(1) has mentioned the following options.

   -dump  dump formatted page into stdout

   -cols width
          specify column width (used with -dump)

To set column width at 72, use those options like this:

w3m -dump -cols 72 [URL or filename]

Since -dump option produce standard output, you can't really do normal browsing (w3m will dump formatted page and exit). Pipe to less to browse the formatted page.

w3m -dump -cols 72 [URL or filename] | less

The last one-line command is all you need.

Normal browsing by w3m

Browse w3m article on Wikipedia using w3m

Formatted page browsing by w3m and less

Browse w3m article on Wikipedia using w3m with dump option and pipe to less

Notice that first-half of the page is wrapped nicely within the column width specified. The screenshots above are browsing this article: w3m on Wikipedia.

Remarks: The -dump option will remove the hyperlinks all together when producing the formatted page. If column width is the only criteria that you need, this option will suffice. Besides this, I am not aware of other ways to also preserve the hyperlinks.

3
  • 1
    Would it be possible to get the wrapping right by feeding the html through Newsbeuter to w3m?
    – dionys
    Commented Nov 13, 2017 at 13:48
  • @dionys I don't think so. Newsbeuter is an RSS/Atom reader, which display the contents from feed and not from HTML page itself. Like this RSS 2.0 feed of source include 'clean' content of articles, but not shown in RSS 1.0 nor Atom (also depends on blog setup).
    – user109256
    Commented Nov 14, 2017 at 16:23
  • Is it possible to set this every time you open w3m as a new standard width?
    – nilon
    Commented Jan 8, 2021 at 13:36
4

You could simply change the terminal's number of columns through stty, e.g., stty cols 72 and then run w3m <url>. That's what I do sometimes.

There are two problems with this, however:

  1. Even if you aliased w3m to stty cols 72 && w3m, you'd still have to reset the line width after your browsing session if you don't want it to stay at 72 columns. This could be automated through a little wrapper script, though.

  2. When you're in an X terminal, the stty setting will be void as soon as you resize the window. (I've tested this in xterm and urxvt.)

1
  • 1
    Howto reset stty when you quit w3m? Can we remap q in w3m? Commented Dec 29, 2019 at 11:04
2

You can use the 'read shell' command (default @ key) to set the width with the stty colls number command on the fly. It will open a new buffer but you can go back and the page will be render with the new width.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .