I have a file, e.g. ~/abc def.mp3 that I want to open from within a Vim buffer that already contains these lines.

If there were no whitespaces in the filename, I could simply open the file with the standard application for that file type by having the cursor on its name somewhere and pressing gx. How could I make this work with a file that includes whitespaces?

I already tried to visually select it and press gx (with or withouth including a \ before the whitespace, surrounding double quotes etc.) but can't figure it out.

  • 3
    Visual selection + gx works for me (a line containing ~/foo bar.txt, with visual selection from ~ to the final t, as opposed to a selection to the end of line, pressing gx opens gvim with the appropriate file). – muru May 26 '16 at 0:01
  • @muru: Hm, gx does not work for me when I am in visual mode, I just tried your example with a text file. gf on the other hand does work. When I press gx in visual mode, I get the usual error sound GNOME produces when an operation fails. Any ideas what might cause this behaviour? Perhaps I have to go through my list of plugins... – cbaumhardt May 26 '16 at 0:22
  • If you cant open filename with spaces, You can escape spaces in filename by typing \ before each space – SibiCoder May 26 '16 at 2:09

Your Answer

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

Browse other questions tagged or ask your own question.