summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorryanss2015-02-19 21:49:21 -0500
committerryanss2015-02-19 21:55:50 -0500
commit2b910b5b03517711188ae8aed0cb510cc7b8679f (patch)
tree5dfba213884be9dfdd77b9b82e9bdcf733ac90cc
parent5712aafb874ce19b38881ddb4a0e158f6741dae5 (diff)
downloadvim-hn-2b910b5b03517711188ae8aed0cb510cc7b8679f.tar.gz
Add motion to move between items on front page easier
From @alexluecke PR #8 Closes #3
-rw-r--r--README.md18
-rw-r--r--doc/hackernews.txt3
-rw-r--r--ftplugin/hackernews.vim17
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 <buffer> O :python hackernews.link(external=True)<cr>
noremap <buffer> gx :python hackernews.link(external=True)<cr>
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]'
+ 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 <buffer> J :call <SID>NextItem(0)<cr>
+noremap <buffer> K :call <SID>NextItem(1)<cr>