前言

w3m是一款命令行下的终端浏览器,与之相似的还有历史悠久的lynx。但是w3m对中文的支持更友好,并且可以显示图片,也有类似于vim的键绑定。虽然图形界面的浏览器有丰富的特性,但是终端浏览器也有占用资源少、没有广告等的优势。尽管现在的网页有十分丰富的ccs特性,终端浏览器并不能显示,但服务于基本的搜索需求已经足够了。

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 (xterm, rxvt or something like that). Moreover, w3m can be used as a text formatting tool which typesets HTML into plain text.

安装

由于w3m内置的图像查看w3mimgdisplay需要libImlib2库,如果没有的话就不能显示图像。所以需要pacman -S w3m imlib2,因为在图形界面中imlib2是默认安装的。

注意,没有imlib2,w3m并不会报错,只是无法显示图像,如果没有显示图像的需求可以不安装,同时如果开启了ranger的w3m图像预览,ranger在遇到图片的时候报错/usr/lib/w3m/w3mdisplay: error while loading shared libraries: libImlib2.so.1: cannot open shared object file: No such file or directory

使用

作为一款终端浏览器,虽然他也支持鼠标操作,但是主要依靠键盘,所以我们先简要熟悉一下它的按键。

快捷键

Page/Cursor motion

key effect
**SPC,C-v ** Forward page
**b,ESC v ** Backward page
**l,C-f ** Cursor right
**h,C-b ** Cursor left
**j,C-n ** Cursor down
**k,C-p ** Cursor up
**J ** Roll up one line
**K ** Roll down one line
^,C-a Go to the beginning of line
$,C-e Go to the end of line
**w ** Go to next word
W Go to previous word
> Shift screen right
< Shift screen left
. Shift screen one column right
, Shift screen one column left
g,M-< Go to the first line
G,M-> Go to the last line
ESC g Go to specified line
Z Move to the center line
**z ** Move to the center column
**TAB ** Move to next hyperlink
C-u,ESC+TAB Move to previous hyperlink
[ Move to the first hyperlink
] Move to the last hyperlink
key effect
**RET ** Follow hyperlink
a, ESC+RET Save link to file
**u ** Peek link URL
i Peek image URL
I View inline image
ESC+I Save inline image to file
: Mark URL-like strings as anchors
ESC+: Mark Message-ID-like strings as news anchors
**c ** Peek current URL
= Display information about current document
C-g Show current line number
C-h View history of URL
F Render frame
M Browse current document using external browser (use 2M and 3M to invoke second and third browser)
ESC+M Browse link using external browser (use 2ESC M and 3ESC M to invoke second and third browser)

File/Stream operation

key effect
**U ** Open URL
V View new file
@ Execute shell command and load
# Execute shell command and browse

Buffer operation

key effect
**B ** Back to the previous buffer
v View HTML source
**s ** Select buffer
E Edit buffer source
C-l Redraw screen
**R ** Reload buffer
S Save buffer
ESC+s Save source
**ESC+e ** Edit buffer image

Buffer selection mode

key effect
k,C-p Select previous buffer
j,C-n Select next buffer
D Delect current buffer
RET Go to the selected buffer

Bookmark operation

key effect
**ESC+b ** Load bookmark
**ESC+a ** Add current to bookmark
key effect
**/,C-s ** Search forward
**?,C-r ** Search backward
n Search next
N Search previous
C-w Toggle wrap search mode

Mark operation

key effect
C-SPC Set/unset mark
ESC p Go to previous mark
ESC n Go to next mark
Mark by regular expression

Miscellany

key effect
! Execute shell command
H Help (load this file)
**o ** Set option
C-k Show cookie jar
**C-c ** Stop
C-z Suspend
**q ** Quit (with confirmation, if you like)
Q Quit without confirmation

Line-edit mode

key effect
C-f Move cursor forward
C-b Move cursor backward
C-h Delete previous character
C-d Delete current character
C-k Kill everything after cursor
**C-u ** Kill everything before cursor
C-a Move to the top of line
C-e Move to the bottom of line
C-p Fetch the previous string from the history list
C-n Fetch the next string from the history list
TAB,SPC Complete filename
RETURN Accept

w3m还贴心地为lynx的用户准备了一套按键,详见w3m manual

以上快捷键我已经加粗标注了常用的(不过是我常用的,要考虑到我还不熟悉w3m)。

使用参数

w3m还给出了许多可用的附加参数以特定的方式启动,详见w3m manual#Options

我自己在使用过程中会用w3m -o auto_image=0 bing.com0代表不显示图片,1代表显示图片。因为有时候,特别是使用framebuffer并且使用tmux分屏的时候,图片的位置会出问题,而且加载图片需要时间。

配置

w3m的用户配置文件位于~/.w3m/中,其中~/.w3m/keymap需要用户自己创建,会覆盖原有的快捷键,~/.w3m/config和在w3m中按o配置的一样,但是在w3m中修改要记得按[OK]保存。