diff options
author | jluehrs2 <jluehrs2@uiuc.edu> | 2008-04-28 01:22:47 -0500 |
---|---|---|
committer | jluehrs2 <jluehrs2@uiuc.edu> | 2008-04-28 01:22:47 -0500 |
commit | 0aca84b834d453b8c36eb79ce10be9e1838f14b5 (patch) | |
tree | 5523ccde40628eb351e10713448673434c581afc /vimrc | |
parent | 510c3a6d6680603456beecbad892834ec2de4296 (diff) | |
download | vim-foldtext-0aca84b834d453b8c36eb79ce10be9e1838f14b5.tar.gz vim-foldtext-0aca84b834d453b8c36eb79ce10be9e1838f14b5.zip |
add a function to generate text objects
Diffstat (limited to 'vimrc')
-rw-r--r-- | vimrc | 37 |
1 files changed, 37 insertions, 0 deletions
@@ -584,6 +584,43 @@ endif " }}} " }}} " Text objects {{{ +" Text object creation {{{ +let g:text_object_number = 0 +function Textobj(char, callback) + let g:text_object_number += 1 + function Textobj_{g:text_object_number}(inner, operator, count, callback) + let [startline, startcol, endline, endcol] = function(a:callback)(a:inner, a:count) + if startline == endline + let objlength = endcol - startcol + 1 + else + let lines = getline(startline + 1, endline - 1) + let lines = [strpart(getline(startline), startcol - 1)] + + \ lines + + \ [strpart(getline(endline), 0, endcol)] + let objlength = 0 + for line in lines + let objlength += strlen(line) + 1 + endfor + let objlength -= 1 + endif + call cursor(startline, startcol) + exe 'normal! '.a:operator.objlength.' ' + + if a:operator == 'c' + normal! l + startinsert + elseif a:operator == 'v' + normal! h + endif + endfunction + + let cbname = '"' . substitute(a:callback, '^s:', '<SID>', '') . '"' + exe 'onoremap <silent>a'.a:char.' <Esc>:call Textobj_'.g:text_object_number.'(0, v:operator, v:prevcount, '.cbname.')<CR>' + exe 'onoremap <silent>i'.a:char.' <Esc>:call Textobj_'.g:text_object_number.'(1, v:operator, v:prevcount, '.cbname.')<CR>' + exe 'xnoremap <silent>a'.a:char.' <Esc>:call Textobj_'.g:text_object_number.'(0, "v", v:prevcount, '.cbname.')<CR>' + exe 'xnoremap <silent>i'.a:char.' <Esc>:call Textobj_'.g:text_object_number.'(1, "v", v:prevcount, '.cbname.')<CR>' +endfunction +" }}} " / for regex {{{ function Textobj_regex(inner, operator) let pos = getpos('.') |