Using Neovim's native LSP interface, I noticed that semantic highlighting provided by LSP makes things worse for certain languages, so I want to disable it based on filetype.

I know about possibility of setting client.server_capabilities.semanticTokensProvider = nil using on_attach callback, but disabling semantics token provider entirely seems to have other negative side-effects. So instead I'm trying to do it using suggestions from :help lsp-semantic-highlight:

You can disable semantic highlights by clearing the highlight groups:

    -- Hide semantic highlights for functions
    vim.api.nvim_set_hl(0, '@lsp.type.function', {})

    -- Hide all semantic highlights
    for _, group in ipairs(vim.fn.getcompletion("@lsp", "highlight")) do
      vim.api.nvim_set_hl(0, group, {})

You probably want these inside a |ColorScheme| autocommand.

Running the loop from example works perfectly on disabling it globally, but I'm confused on how to do that for certain filetypes only, without affecting open files of other types.

  • 1
    Unfortunately, highlight groups are global AFAIK.
    – D. Ben Knoble
    Commented Apr 19, 2023 at 12:37
  • @D.BenKnoble nvim_set_hl takes namespace as a first argument, I was hoping maybe that can help. But I myself am clueless on how highlight namespaces work. Commented Apr 20, 2023 at 0:42
  • Have a check for this: gist.github.com/swarn/fb37d9eefe1bc616c2a7e476c0bc0316, should work when specifying <type> and <ft> Commented May 22, 2023 at 8:27

1 Answer 1


You should disable semantic highlighting for specific LSP (for the filetype) that you want to disable.

on_init is a great For example, if you want disable semantic highlighting from lua_ls (Lua):

lspconfig.lua_ls.setup {
  ---@param client lsp.Client
  on_init = function(client, _)
    client.server_capabilities.semanticTokensProvider = nil  -- turn off semantic tokens
  on_attach = ...,
  settings = ...,

For more details, read :help vim.lsp.start_client()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.