|
| 1 | +# vim-expand-region |
| 2 | + |
| 3 | +## About |
| 4 | +[vim-expand-region] is a Vim plugin that allows you to visually select increasingly larger regions of text using the same key combination. It is similar to features from other editors: |
| 5 | + |
| 6 | +- Emac's [expand region](https://github.com/magnars/expand-region.el) |
| 7 | +- IntelliJ's [syntax aware selection](http://www.jetbrains.com/idea/documentation/tips/#tips_code_editing) |
| 8 | +- Eclipse's [select enclosing element](http://stackoverflow.com/questions/4264047/intellij-ctrlw-equivalent-shortcut-in-eclipse) |
| 9 | + |
| 10 | +<p align="center"> |
| 11 | + <img src="https://raw.github.com/terryma/vim-expand-region/master/expand-region.gif" alt="vim-expand-region" /> |
| 12 | +</p> |
| 13 | + |
| 14 | +## Installation |
| 15 | +Install using [Pathogen], [Vundle], [Neobundle], or your favorite Vim package manager. |
| 16 | + |
| 17 | +## Quick Start |
| 18 | +Press ```+``` to expand the visual selection and ```_``` to shrink it. |
| 19 | + |
| 20 | +## Mapping |
| 21 | +Customize the key mapping if you don't like the default. |
| 22 | + |
| 23 | +``` |
| 24 | +map K <Plug>(expand_region_expand) |
| 25 | +map J <Plug>(expand_region_shrink) |
| 26 | +``` |
| 27 | + |
| 28 | +## Setting |
| 29 | +### Customize selected regions |
| 30 | +The plugin uses __your own__ text objects to determine the expansion. You can customize the text objects the plugin knows about with ```g:expand_region_text_objects```. |
| 31 | + |
| 32 | +```vim |
| 33 | +" Default settings. (NOTE: Remove comments in dictionary before sourcing) |
| 34 | +let g:expand_region_text_objects = { |
| 35 | + \ 'iw' :0, |
| 36 | + \ 'iW' :0, |
| 37 | + \ 'i"' :0, |
| 38 | + \ 'i''' :0, |
| 39 | + \ 'i]' :1, " Support nesting of square brackets |
| 40 | + \ 'ib' :1, " Support nesting of parentheses |
| 41 | + \ 'iB' :1, " Support nesting of braces |
| 42 | + \ 'il' :0, " 'inside line'. Available through https://github.com/kana/vim-textobj-line |
| 43 | + \ 'ip' :0, |
| 44 | + \ 'ie' :0, " 'entire file'. Available through https://github.com/kana/vim-textobj-entire |
| 45 | + \ } |
| 46 | +``` |
| 47 | + |
| 48 | +You can extend the global default dictionary by calling ```expand_region#custom_text_objects```: |
| 49 | + |
| 50 | +```vim |
| 51 | +" Extend the global default (NOTE: Remove comments in dictionary before sourcing) |
| 52 | +call expand_region#custom_text_objects({ |
| 53 | + \ "\/\\n\\n\<CR>": 1, " Motions are supported as well. Here's a search motion that finds a blank line |
| 54 | + \ 'a]' :1, " Support nesting of 'around' brackets |
| 55 | + \ 'ab' :1, " Support nesting of 'around' parentheses |
| 56 | + \ 'aB' :1, " Support nesting of 'around' braces |
| 57 | + \ 'ii' :0, " 'inside indent'. Available through https://github.com/kana/vim-textobj-indent |
| 58 | + \ 'ai' :0, " 'around indent'. Available through https://github.com/kana/vim-textobj-indent |
| 59 | + \ }) |
| 60 | +``` |
| 61 | + |
| 62 | +You can further customize the text objects dictionary on a per filetype basis by defining global variables like ```g:expand_region_text_objects_{ft}```. |
| 63 | + |
| 64 | +```vim |
| 65 | +" Use the following setting for ruby. (NOTE: Remove comments in dictionary before sourcing) |
| 66 | +let g:expand_region_text_objects_ruby = { |
| 67 | + \ 'im' :0, " 'inner method'. Available through https://github.com/vim-ruby/vim-ruby |
| 68 | + \ 'am' :0, " 'around method'. Available through https://github.com/vim-ruby/vim-ruby |
| 69 | + \ } |
| 70 | +``` |
| 71 | + |
| 72 | +Note that this completely replaces the default dictionary. To extend the default on a per filetype basis, you can call ```expand_region#custom_text_objects``` by passing in the filetype in the first argument: |
| 73 | + |
| 74 | +```vim |
| 75 | +" Use the global default + the following for ruby |
| 76 | +call expand_region#custom_text_objects('ruby', { |
| 77 | + \ 'im' :0, |
| 78 | + \ 'am' :0, |
| 79 | + \ }) |
| 80 | +``` |
| 81 | + |
| 82 | +### Customize selection mode |
| 83 | +By default, after an expansion, the plugin leaves you in visual mode. If your ```selectmode```(h:selectmode)) contains ```cmd```, then the plugin will respect that setting and leave you in select mode. If you don't have ```selectmode``` set, but would like to default the expansion in select mode, you can use the global setting below: |
| 84 | + |
| 85 | +```vim |
| 86 | +let g:expand_region_use_select_mode = 1 |
| 87 | +``` |
| 88 | + |
| 89 | +[vim-expand-region]:http://github.com/terryma/vim-expand-region |
| 90 | +[Pathogen]:http://github.com/tpope/vim-pathogen |
| 91 | +[Vundle]:http://github.com/gmarik/vundle |
| 92 | +[Neobundle]:http://github.com/Shougo/neobundle.vim |
0 commit comments