Created
March 12, 2012 17:54
-
-
Save tacahiroy/2023638 to your computer and use it in GitHub Desktop.
How to fold lines are not interested in?
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
function! s:Oritatami(pat) | |
redir => ilist | |
execute ':silent! global/' . a:pat . '/:echo line(".")' | |
redir END | |
let lnums = map(split(ilist, '\n'), 'str2nr(v:val)') | |
if empty(lnums) | |
echomsg printf('pattern "%s" is not found.', a:pat) | |
return | |
endif | |
if lnums[0] != 1 | |
call insert(lnums, 1) | |
endif | |
if lnums[-1] != line('$') | |
call add(lnums, line('$') + 1) | |
endif | |
for i in range(0, len(lnums) - 1) | |
let start = get(lnums, i) + 1 | |
let end = get(lnums, i + 1) | |
if end && start != end | |
execute printf('%d,%dfold', start, end - 1) | |
endif | |
endfor | |
endfunction | |
command! -nargs=1 Orttm call s:Oritatami(<q-args>) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment