3

I write ruby test files in vim, and regularly run tests from the file I'm editing by running

:!rspec %:N

or something similar (to execute the test at line N). The problem is that when the first digit of N is an 8, like:

:!rspec %:89

I get an error:

cannot load such file -- /.../foo_spec.rb9

So it looks like the sequence %:8 means something inside of a colon command. Additionally, if I escape the colon: rspec %\:89 works fine.

But why is this happening?

1 Answer 1

3

As you already know % in the vim command line is resolved to the path name of the file in the current buffer. But % can be modified by adding a modifier. A modifier starts with a : and :8 is a valid modifier.

See :help filename-modifiers for the full list of modifiers. For :8 it says:

  :8  Converts the path to 8.3 short format (currently only on
      MS-Windows).  Will act on as much of a path that is an
      existing path.

On Linux a %:8 is just like %, so %:89 results in %9.

5
  • Since OP might not know about % in general it might help to start with something like "unescaped % resolves to the path of the file in the current buffer" and then ":8 is a modifier of % that...".
    – B Layer
    Commented Feb 8, 2019 at 11:53
  • Aha! Thanks for pointing me in the right direction. I can confirm I do know about % :-) Commented Feb 8, 2019 at 11:56
  • Okay, cool. Still might be good to give a little context IMHO by mentioning % alone...only mention is currently "the path".
    – B Layer
    Commented Feb 8, 2019 at 12:00
  • 1
    @BLayer I see, we try to provide answers that are more than a link and a short quote.
    – Ralf
    Commented Feb 8, 2019 at 12:36
  • 1
    @Ralf Yeah! I try to keep in mind "hypothetical, future, non-OP readers" for which context is king when writing an answer. :) Cheers.
    – B Layer
    Commented Feb 8, 2019 at 12:42

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.