├── hacker.gif ├── Readme.md └── hacker.py /hacker.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dpzmick/neovim-hackernews/HEAD/hacker.gif -------------------------------------------------------------------------------- /Readme.md: -------------------------------------------------------------------------------- 1 | Hacker News in neovim 2 | ===================== 3 | 4 | install: 5 | 6 | copy hacker.py into ~/.nvim/rplugin/python/hacker.py 7 | 8 | open neovim 9 | 10 | run :HackerNews to open the top 30 hacker news stories in a new vim buffer. The 11 | buffer will take a second to open, but the stories are populated in the 12 | background and the buffer will open when it is ready. 13 | 14 | In that new buffer, run :HackerOpen to open the selected story 15 | 16 | The plugin is not particularly useful, but its a cool demo of neovim's features. 17 | 18 | Demo 19 | ==== 20 | ![demo](hacker.gif) 21 | -------------------------------------------------------------------------------- /hacker.py: -------------------------------------------------------------------------------- 1 | import neovim 2 | from hackernews import HackerNews 3 | import webbrowser 4 | 5 | @neovim.plugin 6 | class Hacker(object): 7 | def __init__(self, vim): 8 | self.vim = vim 9 | self.hn = HackerNews() 10 | self.urls = None 11 | 12 | 13 | @neovim.command("Test") 14 | def test(self): 15 | self.vim.command("vsplit") 16 | 17 | @neovim.command('HackerNews') 18 | def fill_buffer(self): 19 | 20 | stories = [] 21 | urls = {} 22 | for story in self.hn.top_stories()[0:30]: 23 | item = self.hn.get_item(story) 24 | stories.append(item.title) 25 | urls[item.title] = item.url 26 | 27 | self.vim.command("split HackerNews") 28 | self.vim.command("buffer HackerNews") 29 | self.vim.command("set buftype=nofile") 30 | self.vim.command("set bufhidden=hide") 31 | self.vim.command("setlocal noswapfile") 32 | self.vim.current.buffer[:] = stories 33 | self.urls = urls 34 | 35 | @neovim.command('HackerOpen') 36 | def autocmd_handler(self): 37 | url = self.urls[self.vim.current.line] 38 | webbrowser.open_new_tab(url) 39 | --------------------------------------------------------------------------------