├── VimFlavor
├── plugin
└── textobj
│ └── syntax.vim
├── autoload
└── textobj
│ └── syntax.vim
├── t
└── basics.vim
└── doc
└── textobj-syntax.txt
/VimFlavor:
--------------------------------------------------------------------------------
1 | flavor 'kana/vim-textobj-user', '~> 0.3'
2 |
--------------------------------------------------------------------------------
/plugin/textobj/syntax.vim:
--------------------------------------------------------------------------------
1 | " textobj-syntax - Text objects for syntax highlighted items
2 | " Version: 0.0.2
3 | " Copyright (C) 2009-2013 Kana Natsuno
4 | " License: So-called MIT license {{{
5 | " Permission is hereby granted, free of charge, to any person obtaining
6 | " a copy of this software and associated documentation files (the
7 | " "Software"), to deal in the Software without restriction, including
8 | " without limitation the rights to use, copy, modify, merge, publish,
9 | " distribute, sublicense, and/or sell copies of the Software, and to
10 | " permit persons to whom the Software is furnished to do so, subject to
11 | " the following conditions:
12 | "
13 | " The above copyright notice and this permission notice shall be included
14 | " in all copies or substantial portions of the Software.
15 | "
16 | " THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 | " OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 | " MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 | " IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20 | " CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21 | " TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22 | " SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | " }}}
24 |
25 | if exists('g:loaded_textobj_syntax')
26 | finish
27 | endif
28 |
29 |
30 |
31 |
32 | call textobj#user#plugin('syntax', {
33 | \ '-': {
34 | \ 'select-a': 'ay', '*select-a-function*': 'textobj#syntax#select_a',
35 | \ 'select-i': 'iy', '*select-i-function*': 'textobj#syntax#select_i',
36 | \ }
37 | \ })
38 |
39 |
40 |
41 |
42 | let g:loaded_textobj_syntax = 1
43 |
44 | " __END__
45 | " vim: foldmethod=marker
46 |
--------------------------------------------------------------------------------
/autoload/textobj/syntax.vim:
--------------------------------------------------------------------------------
1 | " textobj-syntax - Text objects for syntax highlighted items
2 | " Version: 0.0.2
3 | " Copyright (C) 2009-2013 Kana Natsuno
4 | " License: So-called MIT license {{{
5 | " Permission is hereby granted, free of charge, to any person obtaining
6 | " a copy of this software and associated documentation files (the
7 | " "Software"), to deal in the Software without restriction, including
8 | " without limitation the rights to use, copy, modify, merge, publish,
9 | " distribute, sublicense, and/or sell copies of the Software, and to
10 | " permit persons to whom the Software is furnished to do so, subject to
11 | " the following conditions:
12 | "
13 | " The above copyright notice and this permission notice shall be included
14 | " in all copies or substantial portions of the Software.
15 | "
16 | " THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 | " OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 | " MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 | " IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20 | " CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21 | " TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22 | " SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | " }}}
24 | " Interface "{{{1
25 | function! textobj#syntax#select_a() "{{{2
26 | " FIXME: Currently this acts the same as "iy", but it'll be changed.
27 | return textobj#syntax#select_i()
28 | endfunction
29 |
30 |
31 |
32 |
33 | function! textobj#syntax#select_i() "{{{2
34 | let current_position = getpos('.')
35 | let synstack = synstack(current_position[1], current_position[2])
36 |
37 | if empty(synstack) " The character under the cursor is not highlighted.
38 | return 0
39 | endif
40 |
41 | let original_whichwrap = &g:whichwrap
42 | setglobal whichwrap=h,l
43 | while !0
44 | let start_position = getpos('.')
45 | normal! h
46 | let _ = getpos('.')
47 | if synstack(_[1], _[2])[:len(synstack)-1] != synstack
48 | \ || start_position == _
49 | break
50 | endif
51 | endwhile
52 |
53 | call setpos('.', current_position)
54 | while !0
55 | let end_position = getpos('.')
56 | normal! l
57 | let _ = getpos('.')
58 | if synstack(_[1], _[2])[:len(synstack)-1] != synstack
59 | \ || end_position == _
60 | break
61 | endif
62 | endwhile
63 | let &g:whichwrap = original_whichwrap
64 | return ['v', start_position, end_position]
65 | endfunction
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 | " Misc. "{{{1
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 | " __END__ "{{{1
84 | " vim: foldmethod=marker
85 |
--------------------------------------------------------------------------------
/t/basics.vim:
--------------------------------------------------------------------------------
1 | syntax enable
2 | runtime! plugin/textobj/*.vim
3 |
4 |
5 |
6 |
7 | describe 'Named key mappigns'
8 | it 'is available in proper modes'
9 | for lhs in ['(textobj-syntax-a)', '(textobj-syntax-i)']
10 | Expect maparg(lhs, 'c') == ''
11 | Expect maparg(lhs, 'i') == ''
12 | Expect maparg(lhs, 'n') == ''
13 | Expect maparg(lhs, 'o') != ''
14 | Expect maparg(lhs, 'v') != ''
15 | endfor
16 | end
17 | end
18 |
19 |
20 |
21 |
22 | " FIXME: Concrete and revise (textobj-syntax-a) semantics.
23 | " FIXME: Currently, the following tests are just a copy of "iy".
24 | describe '(textobj-syntax-a)'
25 | it 'targets a proper range of text'
26 | enew!
27 | setfiletype c
28 | put ='#define ABC 123 /* FIXME: Fix me. */'
29 | " 0....*....1....*....2....*....3....*.
30 | " ------------------------------------ cDefine
31 | " --- cNumbers
32 | " --- cNumber
33 | " ------------------XX cComment
34 | " -- -- cCommentStart
35 | " ----- cTodo
36 | "
37 | " BUGS: "XX" is not a part of cComment region with the default syntax/c.vim.
38 | " But why? It should be a part of cComment region.
39 |
40 | normal! 1|
41 | normal yay
42 | Expect @0 ==# getline('.')
43 |
44 | normal! 10|
45 | normal yay
46 | Expect @0 ==# getline('.')
47 |
48 | normal! 15|
49 | normal yay
50 | Expect @0 ==# '123'
51 |
52 | normal! 17|
53 | normal yay
54 | Expect @0 ==# '/*'
55 |
56 | normal! 19|
57 | normal yay
58 | Expect @0 ==# '/* FIXME: Fix me. '
59 |
60 | normal! 20|
61 | normal yay
62 | Expect @0 ==# 'FIXME'
63 |
64 | normal! 35|
65 | normal yay
66 | Expect @0 ==# '*/'
67 | end
68 | end
69 |
70 |
71 |
72 |
73 | describe '(textobj-syntax-i)'
74 | it 'targets a proper range of text'
75 | enew!
76 | setfiletype c
77 | put ='#define ABC 123 /* FIXME: Fix me. */'
78 | " 0....*....1....*....2....*....3....*.
79 | " ------------------------------------ cDefine
80 | " --- cNumbers
81 | " --- cNumber
82 | " ------------------XX cComment
83 | " -- -- cCommentStart
84 | " ----- cTodo
85 | "
86 | " BUGS: "XX" is not a part of cComment region with the default syntax/c.vim.
87 | " But why? It should be a part of cComment region.
88 |
89 | normal! 1|
90 | normal yiy
91 | Expect @0 ==# getline('.')
92 |
93 | normal! 10|
94 | normal yiy
95 | Expect @0 ==# getline('.')
96 |
97 | normal! 15|
98 | normal yiy
99 | Expect @0 ==# '123'
100 |
101 | normal! 17|
102 | normal yiy
103 | Expect @0 ==# '/*'
104 |
105 | normal! 19|
106 | normal yiy
107 | Expect @0 ==# '/* FIXME: Fix me. '
108 |
109 | normal! 20|
110 | normal yiy
111 | Expect @0 ==# 'FIXME'
112 |
113 | normal! 35|
114 | normal yiy
115 | Expect @0 ==# '*/'
116 | end
117 | end
118 |
--------------------------------------------------------------------------------
/doc/textobj-syntax.txt:
--------------------------------------------------------------------------------
1 | *textobj-syntax.txt* Text objects for syntax highlighted items
2 |
3 | Version 0.0.2
4 | Script ID: 2716
5 | Copyright (C) 2009-2013 Kana Natsuno
6 | License: So-called MIT license {{{
7 | Permission is hereby granted, free of charge, to any person obtaining
8 | a copy of this software and associated documentation files (the
9 | "Software"), to deal in the Software without restriction, including
10 | without limitation the rights to use, copy, modify, merge, publish,
11 | distribute, sublicense, and/or sell copies of the Software, and to
12 | permit persons to whom the Software is furnished to do so, subject to
13 | the following conditions:
14 |
15 | The above copyright notice and this permission notice shall be included
16 | in all copies or substantial portions of the Software.
17 |
18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
22 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 | }}}
26 |
27 | CONTENTS *textobj-syntax-contents*
28 |
29 | Introduction |textobj-syntax-introduction|
30 | Interface |textobj-syntax-interface|
31 | Commands |textobj-syntax-commands|
32 | Functions |textobj-syntax-functions|
33 | Key Mappings |textobj-syntax-key-mappings|
34 | Customization |textobj-syntax-customization|
35 | Examples |textobj-syntax-examples|
36 | Bugs |textobj-syntax-bugs|
37 | Changelog |textobj-syntax-changelog|
38 |
39 |
40 |
41 |
42 | ==============================================================================
43 | INTRODUCTION *textobj-syntax-introduction*
44 |
45 | *textobj-syntax* is a Vim plugin to provide |text-objects| to select one or
46 | more items which are syntax highlighted.
47 |
48 | For example, if you edit the following line in your vimrc, characters which
49 | are underlined with "~" are syntax highlighted.
50 | >
51 | nnoremap ql :clist
52 | ~~~~~~~~ ~~~~~~~~ ~~~~~ ~~~~~~~~
53 | <
54 | So |(textobj-syntax-a)| and |(textobj-syntax-i)| (which are mapped
55 | from |ay| and |iy| by default) select one of the underlined items if the
56 | cursor is located at the one of them.
57 |
58 |
59 | Requirements:
60 | - Vim 7.2 or later
61 | - |textobj-user| 0.3.8 or later (vimscript#2100)
62 |
63 | Installation:
64 | - Recommended way: Use vim-flavor .
65 |
66 | Latest version:
67 | https://github.com/kana/vim-textobj-syntax
68 |
69 | Document in HTML format:
70 | http://vim-doc.heroku.com/view?https://github.com/kana/vim-textobj-syntax/blob/master/doc/textobj-syntax.txt
71 |
72 |
73 |
74 |
75 | ==============================================================================
76 | INTERFACE *textobj-syntax-interface*
77 |
78 | ------------------------------------------------------------------------------
79 | COMMANDS *textobj-syntax-commands*
80 |
81 | :TextobjSyntaxDefaultKeyMappings[!] *:TextobjSyntaxDefaultKeyMappings*
82 | Define |textobj-syntax-default-key-mappings|.
83 | If [!] is given, existing {lhs}s are overriden.
84 |
85 |
86 | ------------------------------------------------------------------------------
87 | FUNCTIONS *textobj-syntax-functions*
88 |
89 | Any function is not available.
90 |
91 |
92 | ------------------------------------------------------------------------------
93 | KEY MAPPINGS *textobj-syntax-key-mappings*
94 |
95 | NAMED KEY MAPPINGS *textobj-syntax-named-key-mappings*
96 |
97 | (textobj-syntax-a) *(textobj-syntax-a)*
98 | Like |(textobj-syntax-i)|, but this text object
99 | selects also leading or trailing white spaces.
100 |
101 | Note that currently this acts the same as
102 | |(textobj-syntax-i)|.
103 |
104 | (textobj-syntax-i) *(textobj-syntax-i)*
105 | Select the syntax highlighted item under the cursor.
106 | If the character under the cursor is not syntax
107 | highlighted, nothing will be happen.
108 |
109 |
110 | DEFAULT KEY MAPPINGS *textobj-syntax-default-key-mappings*
111 |
112 | textobj-syntax defines the following key mappings
113 | in Visual mode and Operator-pending mode automatically.
114 | See also |g:textobj_syntax_no_default_key_mappings|.
115 |
116 | {lhs} {rhs}
117 | ----- -------------------------- ~
118 | ay |(textobj-syntax-a)| *ay* *v_ay*
119 | iy |(textobj-syntax-i)| *iy* *v_iy*
120 |
121 |
122 |
123 |
124 | ==============================================================================
125 | CUSTOMIZATION *textobj-syntax-customization*
126 |
127 | *g:textobj_syntax_no_default_key_mappings*
128 | If you don't want the default key mappings
129 | Put the following line in your vimrc.
130 | >
131 | let g:textobj_syntax_no_default_key_mappings = 1
132 | <
133 | Then textobj-syntax doesn't define the default key mappings.
134 |
135 | If you want to (re)define the default key mappings
136 | Use |:TextobjSyntaxDefaultKeyMappings| to (re)define the default key
137 | mappings.
138 |
139 |
140 |
141 |
142 | ==============================================================================
143 | EXAMPLES *textobj-syntax-examples*
144 |
145 | See |textobj-syntax-introduction|.
146 |
147 |
148 |
149 |
150 | ==============================================================================
151 | BUGS *textobj-syntax-bugs*
152 |
153 | - Because of the definition of the current syntax highlighting,
154 | |(textobj-syntax-a)| and |(textobj-syntax-i)| may not select
155 | a region of text as you expect.
156 |
157 | - The current selection is not extended like |aw| nor |ip|
158 | whenever |(textobj-syntax-a)| or |(textobj-syntax-i)| is
159 | repeated in Visual mode.
160 |
161 | - So that [count] is just ignored.
162 |
163 | - See |textobj-user-bugs| for further information.
164 |
165 |
166 |
167 |
168 | ==============================================================================
169 | CHANGELOG *textobj-syntax-changelog*
170 |
171 | 0.0.2 2013-01-18T21:17:46+09:00 *textobj-syntax-changelog-0.0.2*
172 | - Support vim-flavor .
173 | - Update |textobj-syntax-introduction|.
174 |
175 | 0.0.1 2012-03-24T14:55:25+09:00 *textobj-syntax-changelog-0.0.1*
176 | - Refine the document a bit.
177 | - Refine the internal structure a bit.
178 |
179 | 0.0.0 2009-07-18T05:30:23+09:00 *textobj-syntax-changelog-0.0.0*
180 | - Initial version.
181 |
182 |
183 |
184 |
185 | ==============================================================================
186 | vim:tw=78:ts=8:ft=help:norl:fen:fdl=0:fdm=marker:
187 |
--------------------------------------------------------------------------------