Search code examples
luaneovim

NVIM - convert buffer number into buffer


At some point I saw a function that would allow you to get the buffer from the buffer number.

I cannot find that function anymore. I searched the documentation for bufnr buffer etc. but I couldn't find it anymore.

Basically I am trying to do something like :

function (client, bufnr) 
  local buffer = nvim_get_buffer(bufnr)
  buffer.lsp.formatting()
end

Solution

  • You can directly use vim.lsp.buf.format function with buffer number, see Neovim LSP docs :

    function (client, bufnr) 
      vim.lsp.buf.format({ bufnr = bufnr })
    end