Created
January 16, 2021 06:09
-
-
Save wordijp/3e1f7499b572388f78869dc3bc1a386a to your computer and use it in GitHub Desktop.
v[count]B
This file contains 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
" v[count]iBの逆版 | |
vnoremap B :<C-u>call <SID>vNiB(v:count)<CR> | |
function! s:vNiB(count) range | |
let l:n = max([1, s:blocklevel()-a:count]) | |
execute 'normal! v'.l:n.'iB' | |
endfunction | |
function! s:blocklevel() range | |
" NOTE: getposの更新 | |
execute "normal! v\<ESC>" | |
let l:start = s:get_position() | |
let l:level = 0 | |
while 1 | |
let l:next = s:get_NiB_position(l:level + 1) | |
if l:next.eq(l:start) | |
break | |
endif | |
let l:level += 1 | |
endwhile | |
return l:level | |
endfunction | |
function! s:get_NiB_position(N) | |
let l:winview = winsaveview() | |
execute 'normal! v' | |
execute 'silent! normal '.a:N.'iB' | |
execute "normal! \<ESC>" | |
let l:ret = s:get_position() | |
call winrestview(l:winview) | |
return l:ret | |
endfunction | |
function! s:get_position() | |
let l:pos = { | |
\ 'start': getpos("'<")[1:2], | |
\ 'end': getpos("'>")[1:2], | |
\ } | |
function! l:pos.eq(o) | |
return self['start'] == a:o['start'] && self['end'] == a:o['end'] | |
endfunction | |
return l:pos | |
endfunction |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment