w3m
w3m is a text-based web browser as well as a pager like more or less. With w3m you can browse web pages through a Terminal emulator window. Moreover, w3m can be used as a text formatting tool which typesets HTML into plain text.
目次
Installation
Usage
See w3m(1).
Configuration
w3m can either be configured using the in-browser settings menu or by directly modifying its configuration files.
Some of the more advanced options are not available using the settings menu, so it is recommended editing the configuration files themselves.
By default all configuration files reside in ~/.w3m
.
Tips and tricks
Vim keybinds
Replace ~/.w3m/keymap
with a custom configuration.
URL hints
w3m supports qutebrowser-like link navigation, simply navigate to your config file and change the following line from display_link_number 0
to display_link_number 1
.
And add keymap f COMMAND "RESHAPE ; LINK_BEGIN ; GOTO_LINK"
and keymap F COMMAND "RESHAPE ; LINK_BEGIN ; TAB_LINK"
to ~/.w3m/keymap
.
Using kittens image protocol
Users of the kitty terminal emulator may chose to use its own graphics protocol.
To do so simply change the following lines in ~/.w3m/config
:
inline_img_protocol 0 imgdisplay w3mimgdisplay
to:
inline_img_protocol 4 imgdisplay kitty
Searching
You can set wrap_search
to 1, to allow searches to jump to the top after they have hit the bottom of all matches within a page.
You can set ignorecase_search
to 1 to enable case insensitive searching.
Custom search engines
You can map keys to launch a CGI script that will capture your input and pass it onto a custom search engine, to do so first create a keybind inside ~/.w3m/keymap
to launch your script:
keymap s COMMAND "SET_OPTION dictcommand=file:///cgi-bin/omnibar_google.cgi ; DICT_WORD"
And place omnibar_google.cgi inside your ~/.w3m/cgi-bin
directory and giving it execute permission.
While the above script will return a Google result, you can use these kinds of scripts to search StackOverflow, GitHub, DuckDuckGo, Reddit and a bunch of other websites.
You can view similar scripts on GitHub.
Reader mode
Some webpages do not work well with w3m, be it because they use a lot of javascript or CSS to display most of their content. Very often you will have to scroll multiple pages just to get to the start of an article.
This can be mitigated by first passing the webpages through a reader mode program such as rdrview-gitAUR.
To do so add the following to ~/.w3m/keymap
:
keymap R COMMAND "READD_SHELL 'rdrview $W3M_URL -H 2> /dev/null 1> /tmp/readable.html' ; LOAD /tmp/readdable.html"
Redirect URLs
~/.w3m/siteconf
file is used to set some preferences depending on the website, such as: referrer and user agent.
It can also be used to redirect to lighter (both in terms of layout and bandwidth), more privacy respecting alternatives to websites.
In addition to this it can also be used to run certain CGI scripts.
~/.w3m/siteconf
url m!^https?://([a-z]+\.)?twitter\.com/! substitute_url "https://nitter.net/" url m!^https?://([a-z]+\.)?reddit\.com/! substitute_url "https://safereddit.com/" #url m!^https?://([a-z]+\.)?google\.com/! #substitute_url "https://duckduckgo.com/lite/" url m!^https?://([a-z]+\.)?imgur\.com/! substitute_url "https://rimgo.pussthecat.org/" url m!^https?://([a-z]+\.)?wikipedia\.com/! substitute_url "https://wl.vern.cc/" url "https://www.youtube.com/" exact substitute_url "file:/cgi-bin/video.cgi?" #substitute_url "https://yewtu.be/" url "https://stackoverflow.com/" exact substitute_url "https://ao.bloatcat.tk/" url "https://www.reuters.com/" exact substitute_url "https://neuters.de/" url "https://fandom.com/" exact substitute_url "https://breezewiki.pussthecat.org/" url "https://medium.com/" exact substitute_url "https://scribe.rip/" url "https://web.archive.org/" exact substitute_url "https://wayback-classic.net/"
Restore closed windows
Default w3m cannot reopen closed tabs, this can be added by binding the close tab button to echo the current URL of the tab to be closed to a text file, and binding another key to restore the latest URL added to the file, using a CGI script.
Inside ~/.w3m/keymap
add:
keymap d COMMAND "EXTERN 'echo %s >> ~/.w3m/RestoreTab.txt' ; CLOSE_TAB" keymap u COMMAND TAB_GOTO file:/cgi-bin/restore_tab.cgi
Then place the following file inside ~/.w3m/cgi-bin
and make it executable.
Opening magnet links
magnet.cgi can be used to make w3m auto open magnet links using Transmission.
Fingerprinting
Using tor
You can use torify(1) to route w3m traffic through tor.
$ torify w3m -v
User agent and headers
By default w3m uses its own user agent, meaning w3m users stand out amongst other users.
Fingerprint can be reduced by using a more generic user agent, language and http_accept header.
~/.w3m/config
user_agent Mozilla/5.0 (Windows NO 10.0; rev:91.0) Gecko/20100101 Firefox91.0 no_referer 1 cross_origin_referer 0 accept_language en-US,en;q=0.5 accept_encoding gzip, deflate accept_media text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Disable cookies
To disable cookies set use_cookie
to 0 in ~/.w3m/config
.
Disable cache
To disable cookies set no_cache
to 1 in ~/.w3m/config
.
Troubleshooting
Images flickering/causing lag
Unfortunately, sometimes w3m lags when trying to scroll past an image, to the point where the browser can become unresponsive for multiple seconds.
A solution to this is outright disabling images, but this breaks some websites (for example, hacker news relies on GIFs for comment indentation).
A more elegant solution would be to make a keybind to toggle images on or off, to do so add the following line to ~/.w3m/keymap
:
keymap i COMMAND "SET_OPTION display_image=toggle ; RESHAPE"