Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the current buffer file path using the Neovim Lua API?

Tags:

lua

neovim

I am using Neovim 0.5 and want to write a custom function to use with telescope.nvim.

I need to get the path of the file loaded in the current buffer before I can execute the function. I have been unable to find how to do this after reading the Neovim Lua API documentation.

So far I've found that vim.api.nvim_get_current_buf() returns the current buffer number, but how do I get the full file path of the current buffer?

like image 912
Smit Patel Avatar asked Sep 14 '25 05:09

Smit Patel


1 Answers

You can access the full path to the file in the current buffer using vim.api.nvim_buf_get_name(0), where 0 for buffer id means "the current buffer".

https://neovim.io/doc/user/api.html#nvim_buf_get_name()

like image 61
Isti115 Avatar answered Sep 16 '25 10:09

Isti115