From 2b910b5b03517711188ae8aed0cb510cc7b8679f Mon Sep 17 00:00:00 2001 From: ryanss Date: Thu, 19 Feb 2015 21:49:21 -0500 Subject: Add motion to move between items on front page easier From @alexluecke PR #8 Closes #3 --- README.md | 18 +++++++----------- doc/hackernews.txt | 3 ++- ftplugin/hackernews.vim | 17 +++++++++++++++++ 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 5e47853..2eba2fe 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,8 @@ as text. Basic Usage ----------- -* Open the Hacker News home page in Vim by executing the `:HackerNews` command +* 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) @@ -43,17 +44,12 @@ NeoBundle 'ryanss/vim-hackernews' ``` -Roadmap -------- +Running Tests +------------- -* Add option to format text like different programming languages to make it - less obvious that you are reading Hacker News in Vim -* Add configuration value for custom text width -* Add configuration value to specify external browser -* Move away from unofficial API by creating server to cache official Hacker - News API data -* Move away from fuckyeahmarkdown.com by creating server that uses - python-readability to convert article HTML to text +```bash +$ vim -c Vader! tests.vader +``` Contributions diff --git a/doc/hackernews.txt b/doc/hackernews.txt index f993029..b382245 100644 --- a/doc/hackernews.txt +++ b/doc/hackernews.txt @@ -8,7 +8,8 @@ Version: 0.1.1 BASIC USAGE *hackernews-usage* -* Open the Hacker News home page in Vim by executing the `:HackerNews` command +* 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) diff --git a/ftplugin/hackernews.vim b/ftplugin/hackernews.vim index 2c94832..7604ca5 100644 --- a/ftplugin/hackernews.vim +++ b/ftplugin/hackernews.vim @@ -40,3 +40,20 @@ noremap O :python hackernews.link(external=True) noremap gx :python hackernews.link(external=True) 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]' + else + " Move to next/previous title line + let pattern = '^\s*\d\+\.\s.' + endif + let dir = a:backwards? '?' : '/' + execute 'silent normal! ' . dir . pattern . dir . 'e\r ' +endfunction + +noremap J :call NextItem(0) +noremap K :call NextItem(1) -- cgit v1.2.3