I want to VISUAL select a piece of text character-wise and pass it to an external command.

For example I want to select only the URL from the the text below

abcde www.google.com abcde

and open it in the default browser.

But after I VISUAL selected it and ran the command

:call system('xdg-open', @*)

nothing happened

But the register * was filled with the selected contents. I tested it with:

:echo @*

What is the right command to achieve it?

2 Answers 2


prototype of system is:

system({cmd} [, {input}])

according to :help system()

If {input} is a string it is written to a pipe and passed as
stdin to the command.  The string is written as-is, line
separators are not changed.

so your final command becomes something like this:

echo www.google.com | xdg-open

which doesn't make sense, as xdg-open doesn't read from stdin. you can call

echo system('xdg-open', @*)

to check error message.

At last you can call system like this:

call system('xdg-open ' . @*)
                     ^ don't miss space

One can also do :!xdg-open <C-r><C-w> to shell out and grab the word under the cursor.

I’m not sure how this handles a WORD like www.google.com; it may be that <C-r><C-a> is necessary

  • 1
    I think you mean <C-r><C-a> rather than <C-W>, don't you?
    – user98761
    Jun 11, 2022 at 23:31
  • @user98761 yep, thanks
    – D. Ben Knoble
    Jun 12, 2022 at 0:30

Your Answer

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

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