" vim-hackernews " -------------- " Browse Hacker News (news.ycombinator.com) inside Vim. " " Author: ryanss " Website: https://github.com/ryanss/vim-hackernews " License: MIT (see LICENSE file) " Version: 0.1.1 if has('python') command! -nargs=1 Python python elseif has('python3') command! -nargs=1 Python python3 else echo "HackerNews.vim Error: Requires Vim compiled with +python or +python3" finish endif if !exists("g:hackernews_marks") let g:hackernews_marks = {} endif " Import Python code execute "Python import sys" execute "Python sys.path.append(r'" . expand(":p:h") . "')" Python << EOF if 'hackernews' not in sys.modules: import hackernews else: # Reload python module to avoid errors when updating plugin hackernews = reload(hackernews) EOF " Load front page execute "Python hackernews.main()" noremap o :Python hackernews.link() 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)