Vimでブラウザ検索を楽にする
概要
Vim
のプラグインopen-browser
を使ってVim
の中にいる時のブラウザ検索と楽にすることをまとめる。
open-browserについて
本家:https://github.com/tyru/open-browser.vim に以下のように書かれている
Open URI with your favorite browser from your most favorite editor.
主な機能
- 検索する単語まで移動して
gx
を押す
デフォルトのブラウザが立ち上がって(ornew tab
で)、カーソルの下にあった単語を検索してくれる。 - カーソルの下にある
url
に移動してgx
を押す
上記同様、url
のページを開いてくれる。 Vim
外の単語をブラウザ検索
下記コマンドで検索できる、コマンドはタグ補完で入力を短袖できる。
:OpenBrowserSearch <検索ワード>
手順
プラグインをインストール
$ cd ~/.vim/plugged
$ git clone https://github.com/tyru/open-browser.vim
上記により、~/.vim/plugged
配下に、open-browser.vim
ディレクトリが作成される。
次に、.vimrc
ファイルに下記を追加する
call plug#begin('~/.vim/plugged') Plug 'tyru/open-browser.vim' call plug#end() " Search via plugin open-browser let g:netrw_nogx = 1 " disable netrw's gx mapping. nmap gx <Plug>(openbrowser-smart-search) vmap gx <Plug>(openbrowser-smart-search)
次に、.vimrc
を開いていている状態で以下のコマンドでプラグインをインストールしてからVim
を再起動する。
:PlugInstall
うまく行けば、これで上記機能が使えるはず。