3

I unfortunately need to work with cmd.exe from time to time and it usually doesn't bug me too much except when I am editing a file in vim and then try to run that file with tab-completion.

If I have the file foo.py open in vim, .foo.py.swp also exists in the directory. The behavior I see is:

C:\foo> f[TAB]
C:\foo> .foo.py.swp[TAB]
C:\foo> foo.py

This is rather infuriating and I'm wondering if there is any way to prevent this behavior short of a complete workaround like changing my swap file naming or using PowerShell. I did notice PowerShell does not emulate this behavior, but I really don't want to use it.

3
  • Why are you so opposed to using PowerShell? Sep 13, 2010 at 0:22
  • I found it less useful than helpful... It's counter-intuitive to both cmd.exe and bash.
    – djs
    Sep 19, 2010 at 0:35
  • 1
    There is now an excellent solution to this problem: clink provides bash readline functionality in a native cmd.exe window.
    – djs
    May 1, 2013 at 4:36

2 Answers 2

3

Windows is behaving exactly as you'd expect if you think it through (and to be honest, until seeing your question, I hadn't thought it completely through). A file name that begins with a '.' is seen as a file with a null file name with an extension. To see how this works, create a directory and then create the following files using touch (I'm assuming you're familiar with touch):

touch .a.aaa
touch a.aaa
touch .b.bbb
touch b.bbb

Now, in that directory, use the tab key to cyle through the files and you'll see that the sequence is:

.a.aaa
.b.bbb
a.aaa
b.bbb

If you want to go through the 'a' files, then type 'a' before the tab and you'll get a predictable .a.aaa, a.aaa.

As for the _ character in a file name, it's just like any other character and sorts after 'Z'.

1

The semantics of FindFirstFile (what CMD uses to enumerate matching files) means that the pattern is tested against the long file name (what you'd like to see) as well as against the autogenerated "8.3" file name. The short name generation is what is causing your spurious matches.

You can disable 8.3 generation via FSUTIL, but that stops FURTHER generation and doesn't remove already existing names. You'd have to run a script that would do renames to fully remove them.

This is dangerous, however, since some programs are clueless and will write the autogenerated shortnames down (say you are using a 16-bit installer, like old versions of MSOFFICE). If you disable their generation, then these installers may fail.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .