diff options
| author | ryanss | 2015-03-03 12:07:54 -0500 |
|---|---|---|
| committer | ryanss | 2015-03-03 12:07:54 -0500 |
| commit | 739fc710fb4738ec54605322f4d50ccb01536a67 (patch) | |
| tree | d350f4417c0dfaed1942df6e2e88a2ab1c819605 /ftplugin | |
| parent | b84b66664e4e3e1fa92aef2d3f67ee626b6145b5 (diff) | |
| download | vim-hn-739fc710fb4738ec54605322f4d50ccb01536a67.tar.gz | |
Add commment thread folding
Diffstat (limited to 'ftplugin')
| -rw-r--r-- | ftplugin/hackernews.vim | 31 |
1 files changed, 30 insertions, 1 deletions
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 . '\rzt' + " Do not stop on folded lines + if foldclosed(line('.')) != -1 + execute 'silent normal! ' . dir . pattern . dir . '\rzt' + endif else " Article if a:backwards @@ -79,3 +83,28 @@ endfunction noremap <buffer> J :call <SID>Move(0)<cr> noremap <buffer> K :call <SID>Move(1)<cr> + + +" 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.*:?\rj' + 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 <buffer> F :call <SID>FoldComments()<cr> |
