0

I want to write a function which opens a vim plugin's Github page, eg calling the function while on this line:

Plug 'tpope/vim-rhubarb'

... will do !open https://github.com/tpope/vim-rhubarb.

Here's what I have so far:

function! PlugOpenGithub()
  normal 0f'yi'
  normal silent !open https://github.com/<C-R><CR>
endfunction

Invoking it doesn't seem to do anything: the browser doesn't open and there's no error message.

I tried removing the <C-R><CR> to see if that was the problem but still nothing happened.

4
  • @D.BenKnoble answered your question as stated. To perform what you are trying to achieve, you can try this: :call system("open https://github.com/" . getline(".")->matchstr("'.*'")[1:-2]). You probably want to do a bit more error checking to handle edge cases, but it may be a starter for your use. – Andrew Ho-Lee Feb 27 at 23:02
  • Thank you both! I settled on this: call system("open https://github.com/" . matchstr(getline("."), "\\v[^\"']+/[^\"']+")). It's not particularly robust but good enough for this purpose. – Zubin Feb 28 at 7:03
  • Please add an answer if you find something that works for you! – D. Ben Knoble Feb 28 at 17:36
0

Thanks for pointing me in the right direction! I settled on this:

call system("open https://github.com/" . matchstr(getline("."), "\\v[^\"']+/[^\"']+"))

It's not particularly robust but is good enough for this purpose.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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