Skip to content

Commit

Permalink
fix: Highlight on yank issue solved by reloading the autocmd each tim…
Browse files Browse the repository at this point in the history
…e the colorscheme is changed.
  • Loading branch information
muhammadzkralla committed Nov 12, 2024
1 parent 3277e98 commit 38555a9
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 11 deletions.
Binary file removed images/img1.png
Binary file not shown.
Binary file removed images/img2.png
Binary file not shown.
Binary file removed images/img3.png
Binary file not shown.
Binary file removed images/img4.png
Binary file not shown.
Binary file removed images/img5.png
Binary file not shown.
8 changes: 4 additions & 4 deletions lazy-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,23 @@
"friendly-snippets": { "branch": "main", "commit": "de8fce94985873666bd9712ea3e49ee17aadb1ed" },
"gitsigns.nvim": { "branch": "main", "commit": "4daf7022f1481edf1e8fb9947df13bb07c18e89a" },
"indent-blankline.nvim": { "branch": "master", "commit": "e7a4442e055ec953311e77791546238d1eaae507" },
"lazy.nvim": { "branch": "main", "commit": "b1134ab82ee4279e31f7ddf7e34b2a99eb9b7bc9" },
"lazy.nvim": { "branch": "main", "commit": "7967abe55752aa90532e6bb4bd4663fe27a264cb" },
"lsp_signature.nvim": { "branch": "master", "commit": "fc38521ea4d9ec8dbd4c2819ba8126cea743943b" },
"lualine.nvim": { "branch": "master", "commit": "2a5bae925481f999263d6f5ed8361baef8df4f83" },
"mason-lspconfig.nvim": { "branch": "main", "commit": "4d0e5b49363cac187326998b96aa6a2884e0e89b" },
"mason-nvim-dap.nvim": { "branch": "main", "commit": "8b9363d83b5d779813cdd2819b8308651cec2a09" },
"mason.nvim": { "branch": "main", "commit": "e2f7f9044ec30067bc11800a9e266664b88cda22" },
"mini.icons": { "branch": "main", "commit": "a2742459f0ee32806c2438ca06b4d8b331f3f4d4" },
"mini.icons": { "branch": "main", "commit": "54686be7d58807906cb2c8c2216e0bf9c044f19a" },
"neo-tree.nvim": { "branch": "v3.x", "commit": "a77af2e764c5ed4038d27d1c463fa49cd4794e07" },
"nui.nvim": { "branch": "main", "commit": "b58e2bfda5cea347c9d58b7f11cf3012c7b3953f" },
"nvim-autopairs": { "branch": "master", "commit": "ee297f215e95a60b01fde33275cc3c820eddeebe" },
"nvim-cmp": { "branch": "main", "commit": "f17d9b4394027ff4442b298398dfcaab97e40c4f" },
"nvim-dap": { "branch": "master", "commit": "8517126e9323e346f6a99b3b594c5a940b914dcd" },
"nvim-dap-ui": { "branch": "master", "commit": "ffa89839f97bad360e78428d5c740fdad9a0ff02" },
"nvim-jdtls": { "branch": "master", "commit": "c4279b8ffce9b64eb302056d78dfebc2968a49bc" },
"nvim-lspconfig": { "branch": "master", "commit": "d01864641c6e43c681c3e9f6cf4745c75fdd9dcc" },
"nvim-lspconfig": { "branch": "master", "commit": "d2d153a179ed59aa7134d7ebdf4d7dcb156efa22" },
"nvim-nio": { "branch": "master", "commit": "a428f309119086dc78dd4b19306d2d67be884eee" },
"nvim-treesitter": { "branch": "master", "commit": "0603b3e3d21ebe2fa82dc5361a3d500e0d3ad3a8" },
"nvim-treesitter": { "branch": "master", "commit": "7646c1c12a3121562aa87fd79aace48c728ac096" },
"nvim-web-devicons": { "branch": "master", "commit": "19d257cf889f79f4022163c3fbb5e08639077bd8" },
"plenary.nvim": { "branch": "master", "commit": "2d9b06177a975543726ce5c73fca176cedbffe9d" },
"telescope-ui-select.nvim": { "branch": "master", "commit": "6e51d7da30bd139a6950adf2a47fda6df9fa06d2" },
Expand Down
24 changes: 17 additions & 7 deletions lua/config/autocmds.lua
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
-- Define a custom highlight group for yank highlighting
vim.cmd [[
highlight YankHighlight guibg=#FFD700 guifg=#000000 ctermbg=214 ctermfg=0
]]
--
-- -- Optional: Add highlighting on yank (copy)
-- Define a function to set the custom yank highlight group
local function setup_yank_highlight()
vim.cmd [[
highlight YankHighlight guibg=#FFD700 guifg=#000000 ctermbg=214 ctermfg=0
]]
end

-- Apply yank highlight after colorscheme loads
vim.api.nvim_create_autocmd("ColorScheme", {
pattern = "*",
callback = setup_yank_highlight,
})

-- Run the setup function initially
setup_yank_highlight()

-- Set up yank highlighting autocmd
vim.api.nvim_create_augroup('YankHighlight', { clear = true })
vim.api.nvim_create_autocmd('TextYankPost', {
group = 'YankHighlight',
callback = function()
-- Use the custom highlight group for yank highlighting
vim.highlight.on_yank({ timeout = 200, higroup = 'YankHighlight' })
end,
})
Expand Down

0 comments on commit 38555a9

Please sign in to comment.