From 64a5492992e0480b017b6c299dab380b45398e46 Mon Sep 17 00:00:00 2001 From: ryanss Date: Tue, 24 Feb 2015 23:59:00 -0500 Subject: Improve helper motions and documentation --- ftplugin/hackernews.vim | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) (limited to 'ftplugin') diff --git a/ftplugin/hackernews.vim b/ftplugin/hackernews.vim index 86c3293..7b0bed4 100644 --- a/ftplugin/hackernews.vim +++ b/ftplugin/hackernews.vim @@ -46,18 +46,32 @@ noremap u u:Python hackernews.recall_pos() noremap :Python hackernews.recall_pos() -" Helper motion to browse front page easier -function! s:NextItem(backwards) - if match(getline('.'), '^\s\{4}.\+ago') >= 0 - " Move to next/previous comment line - let pattern = '^\s\{4}[0-9]' +" Helper motions to browse front page, comments and articles easier +function! s:Move(backwards) + let dir = a:backwards? '?' : '/' + if match(getline(1), "┌───┐") == 0 + " Front Page + if match(getline('.'), '^\s\{4}.\+ago') >= 0 + " Move to next/previous comment line + let pattern = '^\s\{4}[0-9]' + else + " Move to next/previous title line + let pattern = '^\s*\d\+\.\s.' + endif + execute 'silent normal! ' . dir . pattern . dir . 'e\r ' + elseif match(getline(2), '^\d\+\s.\+ago') == 0 + " Comment Page + let pattern = '^\s*Comment by' + execute 'silent normal! ' . dir . pattern . dir . '\r zt' else - " Move to next/previous title line - let pattern = '^\s*\d\+\.\s.' + " Article + if a:backwards + silent normal! { + else + silent normal! } + endif endif - let dir = a:backwards? '?' : '/' - execute 'silent normal! ' . dir . pattern . dir . 'e\r ' endfunction -noremap J :call NextItem(0) -noremap K :call NextItem(1) +noremap J :call Move(0) +noremap K :call Move(1) -- cgit v1.2.3