Closed tan-wei closed 1 year ago
OK. I think here can help. After I implement a function, I will upload code here to help others.
OK, it works:
local default_cmp_sources = cmp.config.sources {
{ name = "nvim_lsp" },
{ name = "nvim_lsp_signature_help" },
{ name = "luasnip" },
{ name = "buffer" },
{ name = "path" },
{ name = "nvim_lua" },
{ name = "emoji" },
{ name = "nerdfont" },
{ name = "rg", keyword_length = 3 },
}
-- Only enable `fonts` for `options.lua`
local buf_is_options_lua = function(bufnr)
local bufname = vim.api.nvim_buf_get_name(bufnr)
local enable_filename = "options.lua"
return bufname:sub(-#enable_filename) == enable_filename
end
vim.api.nvim_create_autocmd("BufReadPre", {
callback = function(t)
local sources = default_cmp_sources
if buf_is_options_lua(t.buf) then
sources[#sources + 1] = { name = "fonts", option = { space_filter = "-" } }
end
cmp.setup.buffer {
sources = sources,
}
end,
})
For me (or any other people), I want to enable this plugin only for a certain file (e.g.,
options.lua
). For now, I can only enable it with file typelua
. But it is to wide I think.Thanks!