1

I know that I can do:

:b home<tab>

and vim will autocomplete to all buffers with the word "home" in them. My problem is that this includes all buffers that have "home" anywhere in their path, which means all buffers under /home will be available to select. How can I get vim to only search the file name (and not the entire path) for buffer autocomplete?

Thanks.

1 Answer 1

0

Note that buffer names only start with /home if you used it explicitly:

:e /home/username/.bashrc    " /home/username/.bashrc

None of the buffer names resulting from the following commands will start with /home:

:e ~/.bashrc                 " ~/.bashrc
:e ../../foo/bar.txt         " ../../foo/bar.txt
:e README.md                 " README.md
etc.

In my opinion the problem you are trying to solve seems too uncommon to warrant a dedicated solution.

Anyway, it is possible to use $ to anchor the "pattern" at the end of the filename, so you can do:

:b home.*$<Tab>
1
  • Thanks, @romaini. So whilst the buffer names don't include the path if you don't specify it, autocomplete still searches the full path even though it isn't part of the buffer name. If you do cd; vim home.txt .vimrc, then :b home<tab>, both files will be returned (assuming your home directory is under /home). May 13, 2023 at 12:44

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.