xiyaowong/link-visitor.nvim

github github
utility
stars 45
issues 0
subscribers 3
forks 3
CREATED

2022-07-02

UPDATED

6 months ago


link-visitor

Let me help you open the links!

link-visitor-demo

Installation

xiyaowong/link-visitor.nvim

Same as other normal plugins, use your favourite plugin manager to install.

Setup

require("link-visitor").setup({
  open_cmd = nil,
  --[[
  1. cmd to open url
    defaults:
      win or wsl: cmd.exe /c start
      mac: open
      linux: xdg-open
  2. a function to handle the link
    the function signature: func(link: string)
  --]]
  silent = true, -- disable all prints, `false` by defaults skip_confirmation
  skip_confirmation = false, -- Skip the confirmation step, default: false
  border = "rounded" -- none, single, double, rounded, solid, shadow see `:h nvim_open_win()`
})

API

local lv = require 'link-visitor'

lv.links_in_buffer(bufnr?) -- Open links in the buffer, current buffer by default
lv.link_under_cursor() -- Open link under the cursor(search in current line)
lv.link_near_cursor() -- Open link near the cursor(search in current line)
lv.link_nearest() -- Open the nearest link to the current position(Search in the whole buffer)
lv.visit(url) -- Open the url

Commands

  • VisitLinkInBuffer - Open links in the buffer
  • VisitLinkUnderCursor - Open link under the cursor
  • VisitLinkNearCursor - Open link near the cursor
  • VisitLinkNearest - Open the nearest link to the current position

Highlight Groups

  • LinkVisitorFloat - Background of popup. (default: links to NormalFloat)
  • LinkVisitorBorder - Border of popup. (default: links to FloatBorder)
  • LinkVisitorText - Text displayed in popup. (default: links to MoreMsg)

Example

This plugin is useful for lsp-hover documentation

After entering the float window, use K to open link under the cursor, L to open link near the cursor

coc.nvim

vim.api.nvim_create_autocmd("User", {
    callback = function()
        local ok, buf = pcall(vim.api.nvim_win_get_buf, vim.g.coc_last_float_win)
        if ok then
            vim.keymap.set("n", "K", function()
                require("link-visitor").link_under_cursor()
            end, { buffer = buf })
            vim.keymap.set("n", "L", function()
                require("link-visitor").link_near_cursor()
            end, { buffer = buf })
        end
    end,
    pattern = "CocOpenFloat",
})

native-lsp

TODO