1

:GBrowse is giving Netrw not found. Define your own :Browse to use :GBrowse since netrw is disabled by telescope.nvim.

I tried to define :Browse like this:

:command! -nargs=1 Browse !open <args>

but it does not work properly when using :GBrowse with ranges like :.GBrowse or :'<,'>GBrowse, because the url will contain # and it will try to expand it to the alternate filename (:h alternate-file, :h c_#). The expansion fails with E194: No alternate file name to substitute for '#': !open https://github.com/xxx/yyy#L3

How can I define a :Browse that works for :GBrowse in all cases?

2 Answers 2

2

The following :Browse definition works when using :GBrowse with ranges:

:command! -nargs=1 Browse silent execute '!open' shellescape(<q-args>,1)

Relevant help pages: :h :!, :h shellescape(), :h :execute and :h :silent)

0

Who want a pure Lua solution in neovim, this is a Lua version of @RubenLaguna solution:

vim.api.nvim_create_user_command(
  'Browse',
  function (opts)
    vim.fn.system { 'xdg-open', opts.fargs[1] }
  end,
  { nargs = 1 }
)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.