16

I have been using w3m for a couple of weeks and am convinced that it is my preferred text browser - with one exception.

Is there any way to yank URLs to the clipboard without using the mouse?

I have looked through the manual and, using the default keybindings, there doesn't appear to be any documented way to do this.

Has anyone developed a script to work around this?

imz -- Ivan Zakharyaschev
  • 15,113
  • 15
  • 61
  • 123
jasonwryan
  • 71,734
  • 34
  • 193
  • 226

4 Answers4

16

Set the “External Browser” option to

sh -c 'printf %s "$0" | xsel'

You can use xsel -b to use the clipboard instead of the primary selection. An alternative to xsel is xclip (xclip for the primary selection, xclip -selection CLIPBOARD for the clipboard).

In ~/.w3m/config, that's the extbrowser setting.

Then press M to copy (yank) the URL of the current page, or ESC M to copy the URL of the link under the cursor.

You can use the second or third external browser for that instead; then the key combination is 2 M or 3 M or 2 ESC M or 3 ESC M.

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
  • I don't know if you cooked that up on the spot or it is a (little) known workaround, but it is both elegant & effective. Thank you. – jasonwryan May 03 '11 at 23:33
  • [I did.](http://chat.stackexchange.com/transcript/message/925205#925205) I hadn't realized this was so easy before your question spurred me into looking! Thank you. – Gilles 'SO- stop being evil' May 03 '11 at 23:43
  • Colour me impressed :) To put the finishing touches on, I mapped some more intuitive keybinds, (the functions are EXTERN & EXTERN_LINK) and now I am set... – jasonwryan May 04 '11 at 00:25
  • I think this won't work for magnet links, I am getting some Invalid directive errors. – Vignesh Oct 28 '18 at 19:13
  • Defining `extbrowser` ahead of time isn't required. If you run `2 ESC M` or `3 ESC M` when it isn't defined, it will prompt you for a command to run, which means you can run any program on the link. You could leave extbrowser 3 always open so as to have a command runner. – norcalli Apr 04 '19 at 10:26
1

If I understand correctly, you need a terminal emulator with a keyboard shortcut to paste test. For example, in Konsole you can do it with Ctrl-Shift-V.

Ramesh
  • 38,687
  • 43
  • 140
  • 215
minaev
  • 721
  • 1
  • 6
  • 8
  • 1
    Thanks minaev: that was a good suggestion. I installed http://www.jukie.net/bart/blog/urxvt-url-yank but, alas, while it works in my term - it doesn't work in w3m... – jasonwryan May 03 '11 at 10:25
1

Have you tried muennich/urxvt-perls? Awesome scripts that can let you select/open URLs, select/copy with keyboard, and handle copy/paste from clipboard. Awesome scripts!

rafi
  • 151
  • 5
0

you can yank url vim style, supports tmux,linux,macos,windows,android

$EDITOR ~/.w3m/keymap

# yank url to multiple clipboard (under cursor)
keymap  yy      EXTERN_LINK "url=%s ; printf "%b" "$url" > /tmp/clipbrd.txt ; printf "%b" "$url" | xsel -b 2>/dev/null ; printf "%b" "$url" | tmux load-buffer - ; printf '%s' "$url" | wl-copy 2>/dev/null  ; printf '%s' "$url" | clip 2>/dev/null ; printf '%s' "$url" > /dev/clipboard 2>/dev/null ; printf '%s' "$url" | pbcopy 2>/dev/null ; printf '%s' "$url" | termux-clipboard-set 2>/dev/null"

# yank url to multiple clipboard (current page)
keymap  YY      EXTERN "url=%s ; printf "%b" "$url" > /tmp/clipbrd.txt ; printf "%b" "$url" | xsel -b 2>/dev/null ; printf "%b" "$url" | tmux load-buffer - ; printf '%s' "$url" | wl-copy 2>/dev/null  ; printf '%s' "$url" | clip 2>/dev/null ; printf '%s' "$url" > /dev/clipboard 2>/dev/null ; printf '%s' "$url" | pbcopy 2>/dev/null ; printf '%s' "$url" | termux-clipboard-set 2>/dev/null"

usage: go to a link and press yy to copy url

gotbletu
  • 146
  • 1
  • 5