0

A simple work flow I often use when running an rspec test I have just been working on, in vim, is as follows:

15:   it "my example test" do
16:     expect(1 == 1).to be true
17:   end

And to run this test, you can do:

!rspec %:15

This runs rspec as an external command. % expands to the current filename, and :15 tells rspec to only run the test line 15, rather than all tests in the file.

This technique works fine under normal circumstances. However, if you try to run a test on lines 80-89 then something strange happens:

84:   it "my other test" do
85:     expect(4 > 3).to be false
86:   end

!rspec %:84

This runs the command rspec [filename]4 - i.e. the :8 characters disappear! (And you get a "file not found" error.)

A workaround to avoid this problem is to press TAB after entering %, which immediately expands % to the full path name.

However, what's the reason behind this strange vim behaviour? Is it a bug, or a feature?

Tom Lord
  • 27,404
  • 4
  • 50
  • 77

1 Answers1

0

A different, related question led me to finding the answer to this.

You can find the answer, along with more detail, by running :help filename-modifiers in vim. Here is a summary of the key point:

The file name modifiers can be used after "%", "#", "#n", "<cfile>", "<sfile>", "<afile>" or "<abuf>".

: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.

8 is the only numerical filename-modifier. If you wish to disable this feature entirely, you can compile vim without the +modify_fname feature.

Community
  • 1
  • 1
Tom Lord
  • 27,404
  • 4
  • 50
  • 77