適当な思いつきで書くブログ

UbuntuやPerlやJavaScriptやVimやZshやShellScriptやMySQLと戯れている中で適当な思いつきでやってみたことを書いています。

html2textを利用してVimからPHPマニュアルをサクっと開いてみる

ついカッとなってやった。マニュアルが見られればなんでもよかった。

  • html2text必須
nmap M :call RefsPhpMan()<CR>
function! RefsPhpMan()
  " let proxy = '--proxy http://proxy.com:8080'
  let proxy = ''
  let str = expand("<cword>")
  let word = substitute(str, '_', '-', 'g')
  let res = system('path=`curl -I ' . proxy . ' "http://jp.php.net/manual-lookup.php?lang=en&pattern=' . word . '" --silent | grep Location | awk "{print $2}" | sed -e "s/.*\/\([^\/]*\)/\1/g" | sed -e "s/\.php/.html/g"` ; curl --location --silent --use-ascii ' . proxy . ' "http://cs.unomaha.edu/local/php_manual/"$path | html2text -width 100 -style pretty | col -bfx')
  let res = substitute(res, '&gt;', '>', 'g')
  let res = substitute(res, '&lt;', '<', 'g')
  let res = substitute(res, '&quot;', "'", 'g')
  let res = substitute(res, '&amp;', '&', 'g')
  let res = substitute(res, '&mdash;', '―', 'g')
  echo res
endf

上記のソースを.vimrcか.vim/ftplugin/php.vimに貼り付けて、PHPの関数の文字の上にカーソルを合わせてMを押すと英語のマニュアルがサクっと開きます

  • 世の中にはもっといいプラグインがたくさんありますがw3mとか会社鯖だとインストールできないのでこんなことしました...
  • 日本語だと文字化けるので英語マニュアルページを開きました...(html2textの文字化け対策のパッチあるみたいです
  • let res = system()のあたりがもうなんかアレ...