8

I'm using the latest vim/gvim (8.0.118), but have noticed this problem in the past, with other versions.

I created a file named fizzbuzz.java (outside of gvim), and opened it in a new tab in gvim on my Windows 7 PC at work, using the context menu of my file manager. After closing the tab, using :x, I discovered that I had to rename the file to FizzBuzz.java, to match the name of the class I wrote, which I did outside of gvim.

However, when I went to reopen it in the same instance of gvim, again using the context menu of my file manager, it reverts to the original casing, and when I close it with :x, it saves it as such, so that I had to rename the file again. It was only after deleting the buffer, and refreshing the buffer list in the menu that I was able to get gvim to correctly recognize the new casing of the filename.

This does not happen in gvim 7.4 on Linux (PCLinuxOS)

Is there an easier way to get gvim to recognize, and retain the change in casing of a filename on Windows, without restarting gvim?

5
  • 1
    I can't reproduce your problem, but your wording is not precise so I might be mising something: I created a file named fizzbuzz.java you manually created it in your explorer or used :e fizzbuzz.java? After closing the file do you mean closing the buffer fizzbuzz.java with :bd? I had to rename it to FizzBuzz.java in your explorer, not with :saveas? it reverts to the original casing, and saves it as such where do you see it with the original name? so that I had to rename the file again again how did you renamed it? refreshing the buffer list in the menu which menu?
    – statox
    Commented Jan 6, 2017 at 9:05
  • Updated the question to add answers to your questions. Created and renamed the file outside of gvim. The original casing displays in the status bar when I reopen the file in gvim using my file manager.
    – Herb
    Commented Jan 6, 2017 at 12:24
  • Thank you for the edit. Following your workflow I still can not reproduce this problem. I think it is a strange behavior since the filename is completely handled by the OS... I hope someone will be able to help you :)
    – statox
    Commented Jan 6, 2017 at 12:29
  • 2
    Yeah, vim seems to reuse the original name since it remembers the buffer. As a workaround, try :f %.
    – Antony
    Commented Jan 6, 2017 at 12:43
  • @Antony if you want to add that as an answer, I will accept it.
    – Herb
    Commented Dec 17, 2019 at 18:20

2 Answers 2

2

Why this happens

When you close the file with :x, it saves the buffer and closes the window/tab, but Vim does not forget about the file. If you execute the :ls command after doing so, you will see the buffer is still there.

Then, when you re-open the file, Vim will notice that it already has a buffer with the "same" filename (because your file system is case-preserving but case-insensitive, fizzbuzz.java and FizzBuzz.java are equivalent with respect to the file's identity), and reuse the buffer, with the lower-case file name.

The solution

In order to prevent this, instead of merely closing the window, you need to tell Vim to discard the buffer entirely, by using the :bwipeout command. This completely removes the buffer from Vim, and so when you reopen it, it treats it as an entirely new buffer, and uses the upper-case file name from the filesystem.

An alternative workaround

Note that :bwipeout has some other effects. If these are an issue, you can instead use the workaround suggested by Antony in the comments, which is to allow Vim to open the file using the lower-case file name, but then rename the buffer to match the upper-case name with the :file {name} command:

:f %
0

Close vim completely, and reopen the file manually (ie :edit FileName.ext instead of :MRU), ensuring there's no badly-cased names in the path.

I just solved a similar problem where my filename in vim was lowercase, but the actual path was uppercase, and Fugitive couldn't find the lowercased file for whatever reason. It seemed to persist even after I relaunched vim and opened the file.

The problem was actually that the MRU plugin I was using (CtrlP) had managed to store the lowercase filename, so after restarting vim, when I manually typed :e UpperCaseFileName.type, instead of going through the MRU file via a plugin, it used the correct path.

2
  • I'm not using a MRU plugin. It appears that it's an internal buffer issue.
    – Herb
    Commented Mar 27, 2018 at 15:00
  • It's the same problem, you've opened the file as lowercase.cpp and want to open LowerCase.cpp. It's probably a bug but it's the same solution. Commented Mar 27, 2018 at 15: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.