martin-braun / browse.nvim

browse for anything using your choice of method

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

browse.nvim

browse for anything using your choice of method

Neovim Lua License

browse.nvim

Features

  • cross platform
  • reduces your search key strokes for any stackoverflow query
  • devdocs search
  • MDN search

Requirements

Installation

  • lazy.nvim

    {
        "lalitmee/browse.nvim",
        dependencies = { "nvim-telescope/telescope.nvim" },
    }
  • packer.nvim

    use({
        "lalitmee/browse.nvim",
        requires = { "nvim-telescope/telescope.nvim" },
    })
  • vim-plug

    Plug 'nvim-telescope/telescope.nvim'
    Plug 'lalitmee/browse.nvim'

Setup

-- default values for the setup
require('browse').setup({
  -- search provider you want to use
  provider = "google", -- duckduckgo, bing

  -- either pass it here or just pass the table to the functions
  -- see below for more
  bookmarks = {},
  icons = {
      bookmark_alias = "->", -- if you have nerd fonts, you can set this to ""
      bookmarks_prompt = "", -- if you have nerd fonts, you can set this to "󰂺 "
      grouped_bookmarks = "->", -- if you have nerd fonts, you can set this to 
  }
})

Usage

There are so many ways in which you can use this to improve your search experience. After bookmarks table support for multiple formats and organized structure of the bookmarks, you can just use open_bookmarks() api.

bookmarks

For bookmarks you can declare your bookmarks in lua table format. bookmarks table can contain multiple structures.

  1. grouped urls with a name key in the table (recommended)

    local bookmarks = {
      ["github"] = {
          ["name"] = "search github from neovim",
          ["code_search"] = "https://github.com/search?q=%s&type=code",
          ["repo_search"] = "https://github.com/search?q=%s&type=repositories",
          ["issues_search"] = "https://github.com/search?q=%s&type=issues",
          ["pulls_search"] = "https://github.com/search?q=%s&type=pullrequests",
      },
    }
  2. urls with aliases

    local bookmarks = {
      ["github_code_search"] = "https://github.com/search?q=%s&type=code",
      ["github_repo_search"] = "https://github.com/search?q=%s&type=repositories",
    }
  3. urls with a query parameter

    local bookmarks = {
      "https://github.com/search?q=%s&type=code",
      "https://github.com/search?q=%s&type=repositories",
    }
  4. simple and direct urls

    local bookmarks = {
         "https://github.com/hoob3rt/lualine.nvim",
         "https://github.com/neovim/neovim",
         "https://neovim.discourse.group/",
         "https://github.com/nvim-telescope/telescope.nvim",
         "https://github.com/rockerBOO/awesome-neovim",
     }
  5. you can also combine all of the above in a table if you want.

and then pass this table into the browse() function like this

vim.keymap.set("n", "<leader>b", function()
  require("browse").browse({ bookmarks = bookmarks })
end)

If this bookmarks table will be empty or will not be passed and if you select Bookmarks from telescope result, you will not see anything in the telescope results.

search

  • input_search(), it will prompt you to search for something
require('browse').input_search()
  • open_bookmarks(), search with the table bookmarks
require("browse").open_bookmarks({ bookmarks = bookmarks })
  • browse(), it opens telescope.nvim dropdown theme to select the method
require("browse").browse({ bookmarks = bookmarks })

devdocs

  • devdocs.search(), search for anything in the devdocs
require('browse.devdocs').search()
  • devdocs.search_with_filetype(), search for anything for the current file type
require('browse.devdocs').search_with_filetype()

mdn

  • mdn.search(), search for anything on MDN
require('browse.mdn').search()

Customizations

You can customize the input_search() to use the provider you like. Possible values for the provider are following:

  • google
  • duckduckgo
  • brave
  • bing

Advanced usage

Create commands for all the functions which browse.nvim exposes and then simply run whatever you want from the command line

local browse = require('browse')

function command(name, rhs, opts)
  opts = opts or {}
  vim.api.nvim_create_user_command(name, rhs, opts)
end

command("InputSearch", function()
  browse.input_search()
end, {})

-- this will open telescope using dropdown theme with all the available options
-- in which `browse.nvim` can be used
command("Browse", function()
  browse.browse({ bookmarks = bookmarks })
end)

command("Bookmarks", function()
  browse.open_bookmarks({ bookmarks = bookmarks })
end)

command("DevdocsSearch", function()
  browse.devdocs.search()
end)

command("DevdocsFiletypeSearch", function()
  browse.devdocs.search_with_filetype()
end)

command("MdnSearch", function()
  browse.mdn.search()
end)

Acknowledgements and Credits

Support

Buy Me A Coffee

About

browse for anything using your choice of method

License:MIT License


Languages

Language:Lua 100.0%