Created
December 10, 2012 13:21
-
-
Save dahu/4250520 to your computer and use it in GitHub Desktop.
Godlygeek's Comment Text Object
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| " author: godlygeek | |
| " 22 Jun 2010 | |
| " | |
| " the objects returned are visual mode commands | |
| " in visual mode, o jumps to the other end of the match | |
| " | |
| function! s:VAC() | |
| if search('\m\%#/\*', 'bcnW') || search('\m/\%#\*', 'bcnW') | |
| " On /* | |
| return ']*o]*[*o' | |
| elseif search('\m/\*\%(\%(\*/\)\@!\_.\)*\%#\_.\{-}\%(\*/\)', 'bcnW') | |
| \ || search('\m\%#\*/', 'bnW') || search('\m\*\%#/', 'bnW') | |
| " Between /* and */, or on a */ | |
| return '[*o[*]*' | |
| endif | |
| " Return to normal mode and sound a bell. | |
| return "\<C-\>\<C-n>\<Esc>" | |
| endfunction | |
| function! VAB() | |
| normal! <c-v>\} | |
| let top = getpos("'<") | |
| let bottom = getpos("'>") | |
| let bottom[2] = top[2] | |
| call setpos("'>", bottom) | |
| endfunction | |
| function! s:block() | |
| return "}kk" . col('.') . "|" | |
| endfunction | |
| vnoremap <expr> } <SID>block() | |
| function! s:VIC() | |
| let vac = s:VAC() | |
| if vac !~ '\m[\x1b]' " If the result contains an <Esc>, not in a comment | |
| return vac . 'owoge' | |
| endif | |
| return vac | |
| endfunction | |
| vnoremap <expr> ac <SID>VAC() | |
| vnoremap <expr> ic <SID>VIC() | |
| onoremap ac :normal vac<CR> | |
| onoremap ic :normal vic<CR> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment