diff options
| author | ryanss | 2015-02-24 23:59:00 -0500 |
|---|---|---|
| committer | ryanss | 2015-02-24 23:59:00 -0500 |
| commit | 64a5492992e0480b017b6c299dab380b45398e46 (patch) | |
| tree | 75066f1c939f42441874b14c18c95772965d9cd9 | |
| parent | 2bfd616bc9b90e33ad3eee992a2d3f0e99fc92ec (diff) | |
| download | vim-hn-64a5492992e0480b017b6c299dab380b45398e46.tar.gz | |
Improve helper motions and documentation
| -rw-r--r-- | README.md | 21 | ||||
| -rw-r--r-- | doc/hackernews.txt | 20 | ||||
| -rw-r--r-- | ftplugin/hackernews.vim | 36 |
3 files changed, 60 insertions, 17 deletions
@@ -17,14 +17,29 @@ Basic Usage ----------- * Open the Hacker News front page in Vim by executing the `:HackerNews` command -* Move between items on the front page with uppercase `J` and `K` * Press lowercase `o` to open links in Vim * Press uppercase `O` to open links in default web browser -* Press lowercase `u` to go back (or whatever you've remapped `undo` to) -* Press `Ctrl+r` to go forward (or whatever you're remapped `redo` to) +* Numbered lines with story titles on the front page link to the story url +* Comment lines on the front page link to the comments url +* Press lowercase `u` to go back +* Press `Ctrl+r` to go forward * Execute the `:bd` command to close and remove the Hacker News buffer +Enhanced Motions +---------------- + +Uppercase `J` and `K` are mapped to helpful new motions based on what type of +content is on the screen: + +* Move to next/prev item when viewing the front page. (If the cursor is on a + numbered line with story title the cursor will move to the next/prev numbered + line with story title. If the cursor is on a comment line it will move to the + next/prev comment line.) +* Move to next/prev comment when viewing comments. +* Move to next/prev paragraph when viewing the text version of articles. + + Installation ------------ diff --git a/doc/hackernews.txt b/doc/hackernews.txt index b382245..2031efd 100644 --- a/doc/hackernews.txt +++ b/doc/hackernews.txt @@ -9,14 +9,28 @@ Version: 0.1.1 BASIC USAGE *hackernews-usage* * Open the Hacker News front page in Vim by executing the `:HackerNews` command -* Move between items on the front page with uppercase `J` and `K` * Press lowercase `o` to open links in Vim * Press uppercase `O` to open links in default web browser -* Press lowercase `u` to go back (or whatever you've remapped `undo` to) -* Press `Ctrl+r` to go forward (or whatever you're remapped `redo` to) +* Numbered lines with story titles on the front page link to the story url +* Comment lines on the front page link to the comments url +* Press lowercase `u` to go back +* Press `Ctrl+r` to go forward * Execute the `:bd` command to close and remove the Hacker News buffer +ENHANCED MOTIONS *hackernews-motions* + +Uppercase `J` and `K` are mapped to helpful new motions based on what type of +content is on the screen: + +* Move to next/prev item when viewing the front page. (If the cursor is on a + numbered line with story title the cursor will move to the next/prev numbered + line with story title. If the cursor is on a comment line it will move to the + next/prev comment line.) +* Move to next/prev comment when viewing comments. +* Move to next/prev paragraph when viewing the text version of articles. + + COMMANDS *hackernews-commands* :HackerNews Open Hacker News front page stories in Vim 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 . '\rzt' 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> |
