Created
November 8, 2012 01:50
-
-
Save dahu/4035975 to your computer and use it in GitHub Desktop.
godlygeek's syntax region 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 | |
function s:movement_string(line, col) | |
return a:line . "G0" . (a:col > 1 ? (a:col - 1) . "l" : "") | |
endfunction | |
function! s:VAR() | |
let group = synID(line('.'), col('.'), 1) | |
let orig = [ line('.'), col('.') ] | |
let last = orig | |
while (col('.') != 1 || line('.') != 1) | |
\ && index(synstack(line('.'), col('.')), group) >= 0 | |
let last = [ line('.'), col('.') ] | |
call search('.', 'bW') | |
endwhile | |
let beg = last | |
call cursor(orig) | |
let last = orig | |
while (col('.') != col('$') || line('.') != line('$')) | |
\ && index(synstack(line('.'), col('.')), group) >= 0 | |
let last = [ line('.'), col('.') ] | |
call search('.', 'W') | |
endwhile | |
let end = last | |
let g:rv = s:movement_string(beg[0], beg[1]) . "o" . s:movement_string(end[0], end[1]) | |
return g:rv | |
endfunction | |
vnoremap <expr> ar <SID>VAR() | |
onoremap ar :normal var<CR> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment