Hatena::Groupvimperator

KBDANOIA - やぬすさん別宅

 | 

2010-11-27

percent encode された形で URL を yank する

| 23:15 | はてなブックマーク -  percent encode された形で URL を yank する - KBDANOIA - やぬすさん別宅

ascii 文字が含まれている URL の site で "y" を押すと URL として使えない形で yank されてしまう、という問題があってこれを何とかしたかった。たとえば "http://ja.wikipedia.org/wiki/英語" みたいなやつね。

なんで避けたいかというかこれをそのまま entry とか誰かさんとこの comment とか掲示板とかに貼っつけてもうまいこと anchor 打ってくれないんだよな。

というわけで以下の mapping を定義してみた。

nnoremap y :javascript util.copyToClipboard(buffer.URL);<CR>:echo "Yanked " + util.readFromClipboard();<CR>

まぁちょっと定義した command がチラつくけど大丈夫だ問題ない。

元ネタは http://vimperator.g.hatena.ne.jp/famnet/ 。適当に英語でも書いてみたよ -> http://vimperator.g.hatena.ne.jp/janus_wel/20101127/1290866954 。あじゃじゃしたー > id:famnet さん。

Yank URLs in the form of percent encoded

| 23:09 | はてなブックマーク -  Yank URLs in the form of percent encoded - KBDANOIA - やぬすさん別宅

In some websites that have URLs with non-ascii characters (generaly as item names, queries etc), we get invalid URLs, such as "http://ja.wikipedia.org/wiki/英語", by hitting "y" key.

We wanna avoid this form of URLs when we post blog entries, comments in someone's site, some bulletin boards and so on, because those are correctly not anchored with <a> tags by websites.

So let's define below mapping to sort out this issue.

nnoremap y :javascript util.copyToClipboard(buffer.URL);<CR>:echo "Yanked " + util.readFromClipboard();<CR>

This mapping is just a bit awkward since <rhs> commands come and go when executing, but I think this is useful.

The source is http://vimperator.g.hatena.ne.jp/famnet/ (in Japanese).

トラックバック - http://vimperator.g.hatena.ne.jp/janus_wel/20101127
 |