4

This may seem a little nit-picky, but I like using the wildmenu to switch between buffers: I do :b and then hit tab until I get to the file I want. The problem is that sometimes, vim shows the entire file path instead of just the file. So instead of getting something nice like

foo.cpp bar.cpp foobar.cpp

I get

foo.cpp ~/Documents/programming/projects/my_project/src/bar.cpp foobar.cpp

Which ANNOYS THE HELL out of me. Sometimes it happens, sometimes it doesn't. Deleting the buffer and reopening the file doesn't do anything; I have to restart vim in order for it to go away.

Does anyone know why vim does this?

EDIT: So, I haven't experienced this problem since I last created this post; however, just now the problem happened again, and I now know the situation in which it manifests. The situation is as follows:

I use the 'quickfix' window for viewing compile errors. When I build my project (via :make) and there are errors, if the files that contain the errors are not currently buffered within vim, then the absolute path of the file is shown in the quickfix window and everywhere else for the rest of the vim session; even if I do :edit foo.cpp after the :make, it will still show the full path for the buffer.

Deleting the buffer and doing another :edit doesn't fix it; vim shows the full path no matter what. The only remedy is to kill vim, open a new process, and to open the files containing the errors before calling :make.

Very strange. Any ideas?

2
  • 1
    Are all of them in same folder?
    – SibiCoder
    Feb 4, 2017 at 13:42
  • I noticed just now that the file's name is ~/blah/something but :pwd outputs /Users/me/blah – maybe some plugin code doesn't 'realize' that they're equivalent? Mar 5, 2021 at 18:52

2 Answers 2

2

That's not a nitpicky concern. You should expect an editor to behave consistently.

As @Raziman points out, buffer names are relative to the current working directory, unless the associated file is NOT even a descendant of the current working directory. If this is not your problem, read on...

If the associated file is definitely a descendant of the current working directory, then it is still possible to get full path buffer names because it depends on how you open the file. For instance, if your current working directory is ~/Documents/programming/projects/my_project/src, you could open foo.cpp in that directory in one of two ways:

  1. Using its relative path like :edit foo.cpp

    The buffer name will just be foo.cpp

  2. Using its full path like :edit ~/Documents/programming/projects/my_project/src/foo.cpp

    The buffer name will be the full path.

How are you opening your files? Are you using a file browser plugin?

2
  • please view my edit.
    – Fake Jake
    Mar 12, 2017 at 10:04
  • I just noticed that a files named path is ~/blah/something.whatever but :pwd outputs /Users/me/blah. Maybe that's the culprit, i.e. ~ not matching /Users/me in some code in various plugins (or Vim/Neovim itself)? Mar 5, 2021 at 18:51
1

The files in the current working folder will be shortened whereas the rest will show the full path. :cd %:p:h in a buffer will change the directory to that of the file, but then every file in other folders will show their full path.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.