From 739fc710fb4738ec54605322f4d50ccb01536a67 Mon Sep 17 00:00:00 2001 From: ryanss Date: Tue, 3 Mar 2015 12:07:54 -0500 Subject: Add commment thread folding --- ftplugin/hackernews.vim | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'ftplugin/hackernews.vim') diff --git a/ftplugin/hackernews.vim b/ftplugin/hackernews.vim index c64b5d2..5f42f7c 100644 --- a/ftplugin/hackernews.vim +++ b/ftplugin/hackernews.vim @@ -62,11 +62,15 @@ function! s:Move(backwards) " Move to next/previous title line let pattern = '^\s*\d\+\.\s.' endif - execute 'silent normal! ' . dir . pattern . dir . 'e\r ' + execute 'silent normal! ' . dir . pattern . dir . '\r ' elseif match(getline(2), '^\d\+\s.\+ago') == 0 " Comment Page let pattern = '^\s*Comment by' execute 'silent normal! ' . dir . pattern . dir . '\r zt' + " Do not stop on folded lines + if foldclosed(line('.')) != -1 + execute 'silent normal! ' . dir . pattern . dir . '\r zt' + endif else " Article if a:backwards @@ -79,3 +83,28 @@ endfunction noremap J :call Move(0) noremap K :call Move(1) + + +" Fold comment threads +function! s:FoldComments() + if match(getline(2), '^\d\+\s.\+ago') != 0 + " Do not continue if this is not a comments page + return + endif + set nowrapscan + try + execute 'silent normal! ' . 'jj?^\s*Comment by.*:?\r j' + catch + " Nothing to fold + return + endtry + let level = matchstr(getline('.'), '^\s\+') + try + execute 'silent normal! ' . 'zf/\n^\s\{0,' . len(level). '}Comment/\r ' + catch + execute 'silent! normal! ' . 'zf/\n\%$/e\r ' + endtry + set wrapscan +endfunction + +noremap F :call FoldComments() -- cgit v1.2.3