TweetVim で URL のタイトルを展開してツイートする
最近書いてみてみたけどなかなかに便利だった。
これと同じように neosnippet で URL を展開してツイートする事ができます。
[スクリプト]
" vimrc 等にグローバル関数として用意しておく function! WebPageTitle(url) if a:url !~ '^https\?:\/\/.*$' return "" endif let body = webapi#http#get(a:url).content let enc = matchstr(body, '<meta[^>]\+content=["''][^;"'']\+;\s*charset=\zs[^;"'']\+\ze["''][^>]*>') if len(enc) == 0 let enc = matchstr(body, '<meta\s\+charset=["'']\?\zs[^"'']\+\ze["'']\?[^>]*>') endif if empty(enc) let enc = matchstr(body, 'charset=["'']\zs[^"'']*\ze["'']') endif return iconv(matchstr(body, '<title>\zs.*\ze<\/title>'), empty(enc) ? 'uft-8' : enc, &enc) endfunction
[スニペット]
# TweetVim のツイートバッファを開いたあとに # :NeoSnippetEdit # で開かれたファイルに記述する snippet link options word `WebPageTitle(getreg("*"))` - `getreg("*") =~ '^https\?:\/\/.*$' ? getreg("*") : ""`