bairui

Godlygeek's Syntax Region text-object

Jul 24th, 2011
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VIM 0.90 KB | None | 0 0
  1. " author: godlygeek
  2.  
  3. function s:movement_string(line, col)
  4.   return a:line . "G0" . (a:col > 1 ? (a:col - 1) . "l" : "")
  5. endfunction
  6.  
  7. function! s:VAR()
  8.   let group = synID(line('.'), col('.'), 1)
  9.  
  10.   let orig = [ line('.'), col('.') ]
  11.   let last = orig
  12.  
  13.   while (col('.') != 1 || line('.') != 1)
  14.        \ && index(synstack(line('.'), col('.')), group) >= 0
  15.     let last = [ line('.'), col('.') ]
  16.     call search('.', 'bW')
  17.   endwhile
  18.  
  19.   let beg = last
  20.  
  21.   call cursor(orig)
  22.  
  23.   let last = orig
  24.  
  25.   while (col('.') != col('$') || line('.') != line('$'))
  26.        \ && index(synstack(line('.'), col('.')), group) >= 0
  27.     let last = [ line('.'), col('.') ]
  28.     call search('.', 'W')
  29.   endwhile
  30.  
  31.   let end = last
  32.  
  33.   let g:rv = s:movement_string(beg[0], beg[1]) . "o" . s:movement_string(end[0], end[1])
  34.   return g:rv
  35. endfunction
  36.  
  37. vnoremap <expr> ar <SID>VAR()
  38. onoremap ar :normal var<CR>
Advertisement
Add Comment
Please, Sign In to add comment