summaryrefslogtreecommitdiff
path: root/ftplugin
diff options
context:
space:
mode:
authorryanss2015-02-24 23:59:00 -0500
committerryanss2015-02-24 23:59:00 -0500
commit64a5492992e0480b017b6c299dab380b45398e46 (patch)
tree75066f1c939f42441874b14c18c95772965d9cd9 /ftplugin
parent2bfd616bc9b90e33ad3eee992a2d3f0e99fc92ec (diff)
downloadvim-hn-64a5492992e0480b017b6c299dab380b45398e46.tar.gz
Improve helper motions and documentation
Diffstat (limited to 'ftplugin')
-rw-r--r--ftplugin/hackernews.vim36
1 files changed, 25 insertions, 11 deletions
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 <buffer> u u:Python hackernews.recall_pos()<cr>
noremap <buffer> <C-r> <C-r>:Python hackernews.recall_pos()<cr>
-" 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 <buffer> J :call <SID>NextItem(0)<cr>
-noremap <buffer> K :call <SID>NextItem(1)<cr>
+noremap <buffer> J :call <SID>Move(0)<cr>
+noremap <buffer> K :call <SID>Move(1)<cr>