Skip to content

Instantly share code, notes, and snippets.

@wladston
Created July 16, 2025 13:30
Show Gist options
  • Save wladston/35d55a318a8acfb9208b23ef0fa2bb83 to your computer and use it in GitHub Desktop.
Save wladston/35d55a318a8acfb9208b23ef0fa2bb83 to your computer and use it in GitHub Desktop.
Neovim, switch colorscheme preserving underline on links, highlights, and formatting
-- After changing colorscheme, Neovim wipes syntax highlights and conceal rules.
-- This re-runs filetype syntax and restores conceal settings if they were in use.
-- Prevents broken link formatting and visible markdown/tutor syntax.
vim.api.nvim_create_autocmd('ColorScheme', {
pattern = '*',
callback = function()
local win = vim.api.nvim_get_current_win()
local conceallevel = vim.wo[win].conceallevel
local concealcursor = vim.wo[win].concealcursor
local ft = vim.bo.filetype
if ft ~= '' then
vim.cmd('doautocmd Syntax ' .. ft)
end
if conceallevel > 0 then
vim.schedule(function()
vim.wo[win].conceallevel = conceallevel
vim.wo[win].concealcursor = concealcursor
end)
end
end,
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment