Keyboard-Shortcuts

是否可以將“2M”綁定到 w3m 中的單個鍵?

  • September 7, 2020

按下啟動第一個外部瀏覽器,M第二個。雖然很容易將內置命令綁定到另一個鍵,但是否可以將第二個鍵綁定到另一個鍵?w3m``2``M``EXTERN

而不是使用extbrowser(在 ~/.w3m/configs 中)。你必須使用奇怪的熱鍵,很難記住每個人做了什麼 2M, 3M, 4M …等或 2-Esc-Shift-M, 3-Esc-Shift-M, 4-Esc-Shift-M .. 。ETC。您也僅限於 9 個

您可以在鍵盤映射文件中綁定熱鍵($EDITOR ~/.w3m/keymap

繼承人一些例子:

# EXTERN_LINK = under cursor
# EXTERN      = current page

# yank url to clipboard
keymap  yy      EXTERN_LINK 'tmux set-buffer'
keymap  YY      EXTERN      'tmux set-buffer'
keymap  yx      EXTERN_LINK 'printf %s | xsel -b'
keymap  YX      EXTERN      'printf %s | xsel -b'

# open url in gui browser
keymap  xw      EXTERN_LINK '$BROWSER'
keymap  XW      EXTERN      '$BROWSER'
keymap  xn      EXTERN_LINK '$BROWSER_PRIVATE'
keymap  XN      EXTERN      '$BROWSER_PRIVATE'

# macros for smart search
keymap  sd      COMMAND "TAB_GOTO https://duckduckgo.com/lite/; NEXT_LINK; GOTO_LINK"
keymap  sg      COMMAND "TAB_GOTO https://google.com; GOTO_LINE 6; NEXT_LINK; GOTO_LINK"
keymap  se      COMMAND "TAB_GOTO https://stackexchange.com; GOTO_LINE 7; NEXT_LINK; GOTO_LINK"
keymap  sw      COMMAND "TAB_GOTO https://en.m.wikipedia.org/wiki/Main_Page; GOTO_LINE 18; NEXT_LINK; GOTO_LINK"

使用宏切換設置:例如,點擊**\n將隱藏/顯示行號。更多選項$ w3m -show-option**

keymap  \\\?    COMMAND "HELP; SEARCH ^User-Defined; CENTER_V"            # show user custom hotkeys binding
keymap  \\\f    COMMAND "HELP; SEARCH ^Input Line Editing Mode; CENTER_V" # show field hotkeys binding
keymap  \\\c    COMMAND "SET_OPTION color=toggle ; RESHAPE"
keymap  \\\u    COMMAND "SET_OPTION mark_all_pages=toggle ; RESHAPE" # Treat URL-like strings as links in all pages
keymap  \\\l    COMMAND "SET_OPTION display_link_number=toggle ; SET_OPTION show_lnum=toggle ; RESHAPE" # toggle hinting mode / line numbers
keymap  \\\h    COMMAND "SET_OPTION display_link_number=toggle ; RESHAPE" # toggle hinting mode
keymap  \\\n    COMMAND "SET_OPTION show_lnum=toggle ; RESHAPE"           # toggle line numbers
keymap  \\\b    COMMAND "SET_OPTION display_borders=toggle ; RESHAPE"     # toggle table borders
keymap  \\\i    COMMAND "SET_OPTION display_image=toggle ; RELOAD"        # toggle image display
keymap  \\\e    COMMAND "SET_OPTION user_agent='' ; RELOAD"               # empty user agent
keymap  \\\A    COMMAND "SET_OPTION user_agent='Opera/9.80 (S60; SymbOS; Opera Mobi/SYB-1107071606; U; en) Presto/2.8.149 Version/11.10' ; RELOAD"

如果比簡單的單行更複雜,您甚至可以編寫腳本

# yank page title
keymap  \\\y    EXTERN_LINK ~/.w3m/cgi-bin/yanktitle_cursorurl.cgi  # yank title (cursor url)

例如:$EDITOR ~/.w3m/cgi-bin/yanktitle_cursorurl.cgi

#!/usr/bin/env sh
# DESC:   yank page title to X11 clipboard and tmux clipboard
# DEPEND: w3m wget gawk (xsel or tmux)

# get url from w3m envoriment variables (e.g !env | less)
# URL="$W3M_URL"            # current page url
URL="$W3M_CURRENT_LINK"   # current link on cursor

# yank page title
TITLE=$(wget -qO- "$URL" | gawk -v IGNORECASE=1 -v RS='</title' 'RT{gsub(/.*<title[^>]*>/,"");print;exit}')
printf "%s" "$TITLE" | xsel -b
printf "%s" "$TITLE" | tmux load-buffer -

引用自:https://unix.stackexchange.com/questions/58466