├── test ├── .gitignore ├── .themisrc └── testobj_between.vimspec ├── plugin └── textobj │ └── between.vim ├── autoload └── textobj │ └── between.vim └── doc └── textobj-between.txt /test/.gitignore: -------------------------------------------------------------------------------- 1 | /.deps/ 2 | -------------------------------------------------------------------------------- /test/.themisrc: -------------------------------------------------------------------------------- 1 | call themis#helper('deps').git('kana/vim-textobj-user') 2 | call themis#helper('command').with(themis#helper('assert')) 3 | -------------------------------------------------------------------------------- /plugin/textobj/between.vim: -------------------------------------------------------------------------------- 1 | " textobj-between - Text objects for a range between a character. 2 | " Version: 0.2.0 3 | " Author : thinca 4 | " License: zlib License 5 | 6 | if exists('g:loaded_textobj_between') 7 | finish 8 | endif 9 | let g:loaded_textobj_between = 1 10 | 11 | let s:save_cpo = &cpo 12 | set cpo&vim 13 | 14 | " Interface "{{{1 15 | call textobj#user#plugin('betweenimpl', { 16 | \ '-': { 17 | \ 'select-a': [], '*select-a-function*': 'textobj#between#impl_select_a', 18 | \ 'select-i': [], '*select-i-function*': 'textobj#between#impl_select_i', 19 | \ } 20 | \ }) 21 | 22 | omap (textobj-between-a) textobj#between#select_a() 23 | xmap (textobj-between-a) textobj#between#select_a() 24 | omap (textobj-between-i) textobj#between#select_i() 25 | xmap (textobj-between-i) textobj#between#select_i() 26 | 27 | " Overwrite default-key-mappings and a command defined by textobj-user 28 | function! s:define_default_key_mappings(force_overwrite) 29 | let modifier = a:force_overwrite ? '' : '' 30 | execute 'silent! omap' modifier 'af (textobj-between-a)' 31 | execute 'silent! xmap' modifier 'af (textobj-between-a)' 32 | execute 'silent! omap' modifier 'if (textobj-between-i)' 33 | execute 'silent! xmap' modifier 'if (textobj-between-i)' 34 | endfunction 35 | command! -bang -bar TextobjBetweenDefaultKeyMappings 36 | \ call s:define_default_key_mappings(0) 37 | if !get(g:, 'textobj_between_no_default_key_mappings', 0) 38 | TextobjBetweenDefaultKeyMappings! 39 | endif 40 | 41 | " Delete this because this may make users confused 42 | delcommand TextobjBetweenimplDefaultKeyMappings 43 | 44 | 45 | let &cpo = s:save_cpo 46 | unlet s:save_cpo 47 | -------------------------------------------------------------------------------- /autoload/textobj/between.vim: -------------------------------------------------------------------------------- 1 | " textobj-between - Text objects for a range between a character. 2 | " Version: 0.2.0 3 | " Author : thinca 4 | " License: zlib License 5 | 6 | let s:save_cpo = &cpo 7 | set cpo&vim 8 | 9 | let s:edge_char = '' 10 | 11 | function! textobj#between#select_i() 12 | call s:getchar() 13 | return "\(textobj-betweenimpl-i)" 14 | endfunction 15 | 16 | function! textobj#between#select_a() 17 | call s:getchar() 18 | return "\(textobj-betweenimpl-a)" 19 | endfunction 20 | 21 | function! s:getchar() 22 | let c = getchar() 23 | if type(c) == type(0) 24 | let c = nr2char(c) 25 | endif 26 | if c !~ '[[:print:]]' 27 | return 0 28 | endif 29 | let s:edge_char = c 30 | endfunction 31 | 32 | function! textobj#between#impl_select_a() 33 | return s:select(0) 34 | endfunction 35 | 36 | function! textobj#between#impl_select_i() 37 | return s:select(1) 38 | endfunction 39 | 40 | function! s:select(in) 41 | if s:edge_char ==# '' 42 | return 0 43 | endif 44 | 45 | let save_ww = &whichwrap 46 | set whichwrap=h,l 47 | 48 | try 49 | let pos = getpos('.') 50 | let pat = s:edge_char == '\' ? '\\' : '\V' . s:edge_char 51 | for i in range(v:count1) 52 | if !search(pat, 'bW') 53 | return 0 54 | endif 55 | endfor 56 | if a:in 57 | normal! l 58 | endif 59 | let start = getpos('.') 60 | 61 | call setpos('.', pos) 62 | for i in range(v:count1) 63 | if !search(pat, 'W') 64 | return 0 65 | endif 66 | endfor 67 | if a:in 68 | normal! h 69 | endif 70 | let end = getpos('.') 71 | return ['v', start, end] 72 | finally 73 | let &whichwrap = save_ww 74 | endtry 75 | endfunction 76 | 77 | let &cpo = s:save_cpo 78 | unlet s:save_cpo 79 | -------------------------------------------------------------------------------- /test/testobj_between.vimspec: -------------------------------------------------------------------------------- 1 | Describe textobj-between-i 2 | Before each 3 | % delete _ 4 | End 5 | 6 | It selects a text-block between a specified char (Operator-pending mode) 7 | call setline(1, 'text/text-block/text') 8 | normal f-dif/ 9 | Assert Equals(getline(1), 'text//text') 10 | 11 | call setline(1, '\text-block\') 12 | normal ldif\ 13 | Assert Equals(getline(1), '\\') 14 | End 15 | 16 | It selects a text-block between a specified char (Visual mode) 17 | call setline(1, 'text/text-block/text') 18 | normal f-vif/d 19 | Assert Equals(getline(1), 'text//text') 20 | 21 | call setline(1, '\text-block\') 22 | normal lvif\d 23 | Assert Equals(getline(1), '\\') 24 | End 25 | 26 | It is dot-repeatable 27 | call setline(1, '/text-block/') 28 | normal ldif/ 29 | call setline(1, '/text-block/') 30 | normal . 31 | Assert Equals(getline(1), '//') 32 | End 33 | End 34 | 35 | Describe textobj-between-a 36 | Before each 37 | % delete _ 38 | End 39 | 40 | It selects a text-block that starts and ends with a specified char (Operator-pending mode) 41 | call setline(1, 'text/text-block/text') 42 | normal f-daf/ 43 | Assert Equals(getline(1), 'texttext') 44 | 45 | call setline(1, '\text-block\') 46 | normal daf\ 47 | Assert Equals(getline(1), '') 48 | End 49 | 50 | It selects a text-block that starts and ends with a specified char (Visual mode) 51 | call setline(1, 'text/text-block/text') 52 | normal f-vaf/d 53 | Assert Equals(getline(1), 'texttext') 54 | 55 | call setline(1, '\text-block\') 56 | normal lvaf\d 57 | Assert Equals(getline(1), '') 58 | End 59 | 60 | It is dot-repeatable 61 | call setline(1, '/text-block/') 62 | normal ldaf/ 63 | 64 | call setline(1, 'text/text-block/text') 65 | normal f-. 66 | Assert Equals(getline(1), 'texttext') 67 | End 68 | End 69 | 70 | Describe :TextobjBetweenDefaultKeyMappings 71 | Before each 72 | onoremap if (dummy-rhs) 73 | vnoremap af (dummy-rhs) 74 | End 75 | 76 | It doesn't overwrite key-mappings when "!" isn't specified 77 | TextobjBetweenDefaultKeyMappings 78 | Assert Equal(maparg('if', 'o'), '(dummy-rhs)') 79 | Assert Equal(maparg('af', 'v'), '(dummy-rhs)') 80 | End 81 | 82 | It overwrites key-mappings when "!" is specified 83 | TextobjBetweenDefaultKeyMappings! 84 | Assert Equal(maparg('if', 'o'), '(textobj-between-i)') 85 | Assert Equal(maparg('af', 'v'), '(textobj-between-a)') 86 | End 87 | End 88 | -------------------------------------------------------------------------------- /doc/textobj-between.txt: -------------------------------------------------------------------------------- 1 | *textobj-between.txt* Text objects for a range between a character. 2 | 3 | Version: 0.2.0 4 | Author : thinca 5 | License: zlib License 6 | 7 | ============================================================================== 8 | CONTENTS *textobj-between-contents* 9 | 10 | INTRODUCTION |textobj-between-introduction| 11 | INTERFACE |textobj-between-interface| 12 | KEY MAPPINGS |textobj-between-key-mappings| 13 | CUSTOMIZING |textobj-between-customizing| 14 | CHANGELOG |textobj-between-changelog| 15 | 16 | 17 | ============================================================================== 18 | INTRODUCTION *textobj-between-introduction* 19 | 20 | *textobj-between* is a Vim plugin to provide text objects to select a range 21 | between a character. 22 | 23 | 24 | Requirements: 25 | - Vim 7.2 or later 26 | - |textobj-user| 0.3.8 or later 27 | 28 | 29 | Latest version: 30 | https://github.com/thinca/vim-textobj-between 31 | 32 | 33 | ============================================================================== 34 | INTERFACE *textobj-between-interface* 35 | 36 | ------------------------------------------------------------------------------ 37 | KEY MAPPINGS *textobj-between-key-mappings* 38 | 39 | These key mappings are defined in Visual mode and Operator-pending mode. 40 | 41 | (textobj-between-a){char} *(textobj-between-a)* 42 | Select the range between the [count]'th {char}. This 43 | is including the {char}. 44 | 45 | (textobj-between-i){char} *(textobj-between-i)* 46 | Select the range between the [count]'th {char}. This 47 | is excluding the {char}. 48 | 49 | 50 | 51 | ============================================================================== 52 | CUSTOMIZING *textobj-between-customizing* 53 | 54 | *g:textobj_between_no_default_key_mappings* 55 | *:TextobjBetweenDefaultKeyMappings* 56 | This plugin will define the following key mappings in Visual mode and 57 | Operator-pending mode automatically. If you don't want these key mappings, 58 | define |g:textobj_between_no_default_key_mappings| before this plugin is loaded 59 | (e.g. in your |vimrc|). You can also use |:TextobjBetweenDefaultKeyMappings| 60 | to redefine these key mappings. This command doesn't override existing {lhs}s 61 | unless [!] is given. 62 | 63 | {lhs} {rhs} ~ 64 | ----- ---------------------- ~ 65 | af (textobj-between-a) 66 | if (textobj-between-i) 67 | 68 | 69 | 70 | ============================================================================== 71 | CHANGELOG *textobj-between-changelog* 72 | 73 | 0.2.0 2012-12-09 74 | - Autoloadize. 75 | 76 | 0.1.0 2010-06-14 77 | - Initial version. 78 | 79 | 80 | ============================================================================== 81 | vim:tw=78:fo=tcq2mM:ts=8:ft=help:norl 82 | --------------------------------------------------------------------------------