Vim completion based on buffer name

In Vim, I often find myself in a situation where I want to fill in the name of a file that I edit in a separate buffer.

Suppose I have two buffers open: foo.cpp and bar.h. In foo.cpp, I need # to include "bar.h". I want to do something like this:

foo.cpp

#include "b<complete filename to bar.h> 

According to Vim's documentation, I can use CTRL + x CTRL + f to complete the file, but it seems to rely on Vim having the CWD equivalent for the parent directory bar.h. This is not always possible.

Given that I open bar.h in a separate buffer, is auto-completion possible based on the name of the buffer?

+7
source share
1 answer

A good idea; limiting candidates for loaded buffers shortens the list of candidates and also allows matching anywhere on the file path.

To get this, you must perform custom paste in insert mode. File names can be obtained by repeating bufname() for all buffer numbers from 1 to bufnr('$') . I just implemented this as a BufNameComplete plugin. I hope this satisfies your needs (and mine).

+6
source

All Articles