Vim найти буфер по абсолютному пути

487
user14416

Как я могу найти буфер в vimscript, когда у меня есть абсолютный путь, и, как вы знаете, имена буферов vim могут быть относительным путем? Есть ли функция для этого?

0
«связанный путь» -> вы имеете в виду «относительный путь»? akira 9 лет назад 0

1 ответ на вопрос

0
Ingo Karkat

The bufnr() function can find buffers (and return its number). Like bufname(), this can take the queried buffer name in several forms (cp. :help bufname()):

 A full match is preferred, otherwise a match at the start, end or middle of the buffer name is accepted. If you only want a full match then put "^" at the start and "$" at the end of the pattern. 

So, one example would be

:echo bufnr('^C:\path\to\file.txt$') 

Also, you can convert between relative and absolute paths via the fnamemodify() function.