2

I don't normally set autochdir, but I'm trying it out and seeing what kind of small frustrations I encounter as a way of learning more about vim.

For the purposes of this question, my .vimrc is the following:

set laststatus=2
set autochdir

Suppose I'm working with the following project.

~/tmp/some-project $ tree
.
├── a
│   └── README.txt
└── b
    └── README.txt

If I run the following, then emacs will populate two buffers that display as README.txt<a> and README.txt<b>.

emacs `find . -type f`

If I run the following, then vim will create two buffers side by side.

vim -O `find . -type f`

One of the buffers will be called README.txt and the other will be called ~/tmp/some-project/b/README.txt.

When I change which buffer has focus, then the names will all shift because vim itself has chdired when autochdir is set.


The problem that I'm running into is this. If I only have one buffer visible, then that buffer will be called README.txt regardless of which directory I'm in and I can't tell which README.txt I'm looking at.

Is there a way to configure vim to show buffers with single-segment paths as README.txt<a> or something similar so I can more easily tell which file I'm editing when autochdir is enabled.

3
  • You can personalize your status line with :help 'statusline' and massage filenames with :help fnamemodify(). Also, autochdir is an abomination.
    – romainl
    Commented Oct 26, 2023 at 6:45
  • I prefer to have the Vim working directory to be set to the root of the project (~/tmp/some-project). There are plugins that do that for you automatically based on the content of the root folder (e.g. vim-rooter). Commented Oct 26, 2023 at 9:04
  • Funny to read such strong feelings on autochdir. I've had it enabled for ten years or so and I actually like it. Having it off tends to confuse me. When in doubt, ask :pwd. Just my two cents.
    – Friedrich
    Commented Oct 26, 2023 at 10:01

1 Answer 1

1

Some ideas:

  • Press Ctrl-G, or run :file
  • Configure your statusline

For the statusline, you can experiment with %f (in the default), %F, and %t. I’ve rolled my own such that I can switch been short statusline (%t) and long statusline (path + %t), where the trailing component is always highlighted.

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.