Created
February 10, 2012 16:17
-
-
Save kien/1790562 to your computer and use it in GitHub Desktop.
Indent 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
| func! s:indentobj(i, ...) | |
| let ls = { 0: 1, 1: line('.'), 2: line('$') } | |
| if getline(ls[1]) =~ '^\s*$' | retu | en | |
| let idt = max([indent(ls[1]) - &sw * ( v:count1 - 1 ), 0]) | |
| for [idx, rs] in items({ 0: range(ls[1], 1, -1), 2: range(ls[1], ls[2]) }) | |
| for line in rs | if getline(line) !~ '^\s*$' && indent(line) < idt | |
| cal extend(ls, { idx : line }) | brea | |
| en | endfo | |
| endfo | |
| exe 'keepj norm! '.( ls[0] + a:i ).'GV'.( ls[2] - ( a:i || a:0 ) ).'G' | |
| endfunc | |
| ono <silent> ai :<c-u>cal s:indentobj(0)<cr> | |
| ono <silent> ii :<c-u>cal s:indentobj(1)<cr> | |
| vn <silent> ai :<c-u>cal s:indentobj(0)<cr> | |
| vn <silent> ii :<c-u>cal s:indentobj(1)<cr> | |
| " Excluding last line | |
| ono <silent> aI :<c-u>cal s:indentobj(0, 1)<cr> | |
| vn <silent> aI :<c-u>cal s:indentobj(0, 1)<cr> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment