Neovim auto commands

Updated: 04 July 2025

Flash yanked text

autocmd("TextYankPost", {
    pattern = "*",
    desc = "Highlight text on yank.",
    callback = function ()
        vim.highlight.on_yank { higroup = "Search", timeout = 150 }
    end,
})

Set syntax highlighting for /etc/hosts file

vim.api.nvim_create_autocmd('BufRead', {
  pattern = '/etc/hosts',
  desc = 'Set syntax highlighting for /etc/hosts file.',
  callback = function()
    -- Only the 'bash' filetype seems to work!
    vim.opt.filetype = 'bash'
  end,
})

Leave a comment