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 --- README.md | 21 ++++++++++++++++++--- doc/hackernews.txt | 20 +++++++++++++++++--- ftplugin/hackernews.vim | 36 +++++++++++++++++++++++++----------- 3 files changed, 60 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 2eba2fe..9055e19 100644 --- a/README.md +++ b/README.md @@ -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 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