I would like to open a url in vim. Using gx from netrw has been problematic, so I created the following simple mapping:

nnoremap <leader>k !open <C-R><C-F><CR>

This gets the filepath under the cursor and then executes it, with the command looking like:

:!open http://google.com

However, I hate that whenever I open a file (or url) it prompts me with:

Press ENTER or type command to continue

So then I enter in silent at the start:

:silent !open http://google.com

And it opens without that message, but when I go back to it the screen is blank, which is equally annoying.

Is there a way to just "open the link normally"? I.e., not the prompt me with a message, make the screen go blank, or anything other than opening the file/url on its own? How can I do this?

  • 1
    Please edit and move your answer into an answer
    – D. Ben Knoble
    Jun 16 '20 at 13:36
  • @D.BenKnoble thanks, updated!
    – David542
    Jun 21 '20 at 4:17

To achieve this you can prepend silent to the command. For example, the following will work:

nnoremap <leader>k :execute 'silent !open <C-R><C-F>' \| redraw!<CR>

Note also the need to escape the | in the mapping to force redraw at the end as well.

  • David, you can accept your own answer.
    – Ralf
    Jun 21 '20 at 12:44

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.