Vimメモ : vim-expand-regionでビジュアルモードの選択領域を拡大/縮小
インストール
NeoBundleの場合は下記行をvimrc
に追加。
NeoBundle 'terryma/vim-expand-region'
使い方
デフォルトでは
+
キーを押せば選択領域の拡大、_
キーを押せば選択領域の縮小ができる。キーマッピングを変更したい場合は下記設定を
vimrc
に追加。
map K <Plug>(expand_region_expand) map J <Plug>(expand_region_shrink)
設定変更
デフォルトの設定は以下のようになっているが、g:expand_region_text_objects
を編集すれば選択領域の対象とするテキストオブジェクトを追加/削除することができる。
" デフォルト設定(vimrc記述時は下記コメント部分を削除すること) let g:expand_region_text_objects = { \ 'iw' :0, \ 'iW' :0, \ 'i"' :0, \ 'i''' :0, \ 'i]' :1, " Support nesting of square brackets \ 'ib' :1, " Support nesting of parentheses \ 'iB' :1, " Support nesting of braces \ 'il' :0, " 'inside line'. Available through https://github.com/kana/vim-textobj-line \ 'ip' :0, \ 'ie' :0, " 'entire file'. Available through https://github.com/kana/vim-textobj-entire \ }
ここで数値の1
はネストされたものを対象とするかどうかを表す。例えば、'ib' :1
ならネストされた括弧一つずつに対して拡大/縮小していくが、'ib' :0
なら一番外側の括弧を対象とする。
また、il
の行選択とie
のファイル全体選択は別プラグインのインストールが必要なので、使いたい場合は下記行をvimrc
に追加(NeoBundleの場合)。
NeoBundle 'kana/vim-textobj-user' NeoBundle 'kana/vim-textobj-line' NeoBundle 'kana/vim-textobj-entire'
その他、特定のファイルタイプに対して指定したい場合は、g:expand_region_text_objects_{ft}
のように指定する。以下はRubyの場合の例。
" Rubyの場合の設定例(vimrc記述時は下記コメント部分を削除すること) let g:expand_region_text_objects_ruby = { \ 'im' :0, " 'inner method'. Available through https://github.com/vim-ruby/vim-ruby \ 'am' :0, " 'around method'. Available through https://github.com/vim-ruby/vim-ruby \ }
- 作者: DrewNeil,新丈径
- 出版社/メーカー: KADOKAWA / アスキー・メディアワークス
- 発売日: 2014/01/28
- メディア: Kindle版
- この商品を含むブログ (3件) を見る