diff --git a/lua/config/autocmds.lua b/lua/config/autocmds.lua index 693604d..a289458 100644 --- a/lua/config/autocmds.lua +++ b/lua/config/autocmds.lua @@ -47,3 +47,9 @@ vim.api.nvim_create_autocmd({ "BufEnter", "FocusGained" }, { ) end, }) + +-- Set up autocommands and highlight settings +local load_highlight = require("config.highlight") +-- load_highlight.setup_indent_highlight() +load_highlight.setup_autocommands() +load_highlight.setup_dashboard_highlight() diff --git a/lua/config/highlight.lua b/lua/config/highlight.lua new file mode 100644 index 0000000..7ead17b --- /dev/null +++ b/lua/config/highlight.lua @@ -0,0 +1,242 @@ +local M = {} + +-- Function to convert RGB to hexadecimal +local function rgb_to_hex(rgb) + return string.format("#%02x%02x%02x", rgb[1], rgb[2], rgb[3]) +end + +local function get_bg_color(hlgroup) + local hl = vim.api.nvim_get_hl(0, { name = hlgroup, link = false }) + local bg = hl.bg + if bg then + return rgb_to_hex({ + bit.rshift(bit.band(bg, 0xFF0000), 16), + bit.rshift(bit.band(bg, 0x00FF00), 8), + bit.band(bg, 0x0000FF), + }) + end + return nil +end + +local function get_fg_color(hlgroup) + local hl = vim.api.nvim_get_hl(0, { name = hlgroup, link = false }) + local fg = hl.fg + if fg then + return rgb_to_hex({ + bit.rshift(bit.band(fg, 0xFF0000), 16), + bit.rshift(bit.band(fg, 0x00FF00), 8), + bit.band(fg, 0x0000FF), + }) + end + return nil +end + +-- Function to set up indent highlights +function M.setup_indent_highlight() + -- Get the background color of CursorLine + local cursorline_bg_hex = get_bg_color("CursorLine") + + -- Get the foreground color of Error + local miniiconsred_fg_hex = get_fg_color("Error") + + local hooks = require("ibl.hooks") + -- create the highlight groups in the highlight setup hook, so they are reset + -- every time the colorscheme changes + if cursorline_bg_hex then + -- Define custom highlight groups for indent using the CursorLine background color + hooks.register(hooks.type.HIGHLIGHT_SETUP, function() + vim.api.nvim_set_hl( + 0, + "IndentBlanklineIndent", + { fg = cursorline_bg_hex, nocombine = true } + ) + vim.api.nvim_set_hl( + 0, + "IndentsScopeHighlight", + { fg = miniiconsred_fg_hex, nocombine = true } + ) + end) + end + + -- Configure the indent-blankline plugin + require("ibl").setup({ + indent = { + char = { + "󰎤", + "󰎧", + "󰎪", + "󰎭", + "󰎱", + "󰎳", + "󰎶", + "󰎹", + "󰎼", + "󰽽", + }, + highlight = { + "IndentBlanklineIndent", + }, + }, + scope = { + show_start = true, + highlight = { + "IndentsScopeHighlight", + "IndentsScopeHighlight", + }, + char = "┋", + }, + whitespace = { + remove_blankline_trail = true, + }, + exclude = { + filetypes = { + "help", + "alpha", + "dashboard", + "neo-tree", + "Trouble", + "trouble", + "lazy", + "mason", + "notify", + "toggleterm", + "lazyterm", + }, + }, + }) + + -- Configure the deadcolumn plugin + require("deadcolumn").setup({ + scope = "line", ---@type string|fun(): integer + modes = function(mode) + return mode:find("^[ictRss\x13]") ~= nil + end, + blending = { + threshold = 0.9, + colorcode = cursorline_bg_hex, + hlgroup = { "Normal", "bg" }, + }, + warning = { + alpha = 0.4, + offset = 0, + colorcode = miniiconsred_fg_hex, + hlgroup = { "Error", "bg" }, + }, + extra = { + follow_tw = "80", + }, + }) + + -- Set colorcolumn + vim.cmd(":set colorcolumn=120") +end + +function M.setup_mode_highlight() + local current_mode = vim.fn.mode() + local bg_color + + if current_mode == "n" then + bg_color = get_bg_color("MiniStatuslineModeNormal") + vim.api.nvim_set_hl(0, "SmoothCursor", { fg = bg_color }) + vim.fn.sign_define("smoothcursor", { text = "" }) + elseif current_mode == "v" then + bg_color = get_bg_color("MiniStatuslineModeVisual") + vim.api.nvim_set_hl(0, "SmoothCursor", { fg = bg_color }) + vim.fn.sign_define("smoothcursor", { text = "" }) + elseif current_mode == "V" then + bg_color = get_bg_color("MiniStatuslineModeVisual") + vim.api.nvim_set_hl(0, "SmoothCursor", { fg = bg_color }) + vim.fn.sign_define("smoothcursor", { text = "" }) + elseif current_mode == "R" or current_mode == "r" then + bg_color = get_bg_color("MiniStatuslineModeReplace") + vim.api.nvim_set_hl(0, "SmoothCursor", { fg = bg_color }) + vim.fn.sign_define("smoothcursor", { text = "" }) + elseif current_mode == "i" then + bg_color = get_bg_color("MiniStatuslineModeInsert") + vim.api.nvim_set_hl(0, "SmoothCursor", { fg = bg_color }) + vim.fn.sign_define("smoothcursor", { text = "" }) + else + bg_color = get_bg_color("MiniStatuslineModeNormal") + vim.api.nvim_set_hl(0, "SmoothCursor", { fg = bg_color }) + vim.fn.sign_define("smoothcursor", { text = "" }) + end +end + +function M.setup_dashboard_highlight() + if not vim.g.DashboardHeaderColor then + local dash_color = get_fg_color("Error") + vim.api.nvim_set_hl(0, "DashboardHeader", { fg = dash_color }) + else + vim.api.nvim_set_hl( + 0, + "DashboardHeader", + { fg = vim.g.DashboardHeaderColor } + ) + end +end + +-- Setup autocommands to update on InsertEnter and ColorScheme events +function M.setup_autocommands() + local autogrp = vim.api.nvim_create_augroup + local autocmd = vim.api.nvim_create_autocmd + -- Autocommand to trigger setup on InsertEnter + autogrp("IndentHighlight", { clear = true }) + autocmd("InsertEnter", { + group = "IndentHighlight", + callback = function() + M.setup_indent_highlight() + end, + }) + + -- Autocommand to trigger setup on ColorScheme + autocmd("ColorScheme", { + group = "IndentHighlight", + callback = function() + M.setup_indent_highlight() + end, + }) + + -- Autocommand to trigger setup on ModeChanged + autogrp("ModeHighlighting", { clear = true }) + autocmd("ModeChanged", { + group = "ModeHighlighting", + callback = function() + M.setup_mode_highlight() + end, + }) + + -- Create a new augroup for the dashboard + local dashboardGroup = autogrp("DashboardColors", { clear = true }) + -- Set the color for DashboardHeader when VimEnter event triggers + autocmd("CursorMoved", { + group = dashboardGroup, + callback = function() + M.setup_dashboard_highlight() + end, + }) + -- Reapply highlights when the colorscheme changes + autocmd("ColorScheme", { + pattern = "*", + group = dashboardGroup, + callback = function() + M.setup_dashboard_highlight() + end, + }) + -- Match neovim and terminal background colors + vim.api.nvim_create_autocmd({ "UIEnter", "ColorScheme" }, { + callback = function() + local normal = vim.api.nvim_get_hl(0, { name = "Normal" }) + if not normal.bg then + return + end + io.write(string.format("\027]11;#%06x\027\\", normal.bg)) + end, + }) + vim.api.nvim_create_autocmd("UILeave", { + callback = function() + io.write("\027]111\027\\") + end, + }) +end + +return M diff --git a/lua/config/options.lua b/lua/config/options.lua index 2049e4f..43454fc 100644 --- a/lua/config/options.lua +++ b/lua/config/options.lua @@ -16,3 +16,6 @@ vim.g.usewakatime = true vim.g.usehardtime = false vim.g.useimage = true vim.o.background = "dark" + +vim.g.DashboardHeaderColor = "#A6E3A1" +vim.g.mousemoveevent = true diff --git a/lua/config/rootiest.lua b/lua/config/rootiest.lua index 84ff435..01de56e 100644 --- a/lua/config/rootiest.lua +++ b/lua/config/rootiest.lua @@ -64,12 +64,50 @@ end -- Set cursor icons function M.set_cursor_icons() - vim.fn.sign_define("smoothcursor_n", { text = "" }) - vim.fn.sign_define("smoothcursor_v", { text = "" }) - vim.fn.sign_define("smoothcursor_V", { text = "" }) - vim.fn.sign_define("smoothcursor_i", { text = "" }) - vim.fn.sign_define("smoothcursor_c", { text = "" }) - vim.fn.sign_define("smoothcursor_R", { text = "󰊄" }) + local function rgb_to_hex(rgb) + return string.format("#%02x%02x%02x", rgb[1], rgb[2], rgb[3]) + end + + local function get_bg_color(hlgroup) + local hl = vim.api.nvim_get_hl(0, { name = hlgroup, link = false }) + local bg = hl.bg + if bg then + return rgb_to_hex({ + bit.rshift(bit.band(bg, 0xFF0000), 16), + bit.rshift(bit.band(bg, 0x00FF00), 8), + bit.band(bg, 0x0000FF), + }) + end + return nil + end + local current_mode = vim.fn.mode() + local bg_color + + if current_mode == "n" then + bg_color = get_bg_color("MiniStatuslineModeNormal") + vim.api.nvim_set_hl(0, "SmoothCursor", { fg = bg_color }) + vim.fn.sign_define("smoothcursor", { text = "" }) + elseif current_mode == "v" then + bg_color = get_bg_color("MiniStatuslineModeVisual") + vim.api.nvim_set_hl(0, "SmoothCursor", { fg = bg_color }) + vim.fn.sign_define("smoothcursor", { text = "" }) + elseif current_mode == "V" then + bg_color = get_bg_color("MiniStatuslineModeVisual") + vim.api.nvim_set_hl(0, "SmoothCursor", { fg = bg_color }) + vim.fn.sign_define("smoothcursor", { text = "" }) + elseif current_mode == "R" or current_mode == "r" then + bg_color = get_bg_color("MiniStatuslineModeReplace") + vim.api.nvim_set_hl(0, "SmoothCursor", { fg = bg_color }) + vim.fn.sign_define("smoothcursor", { text = "" }) + elseif current_mode == "i" then + bg_color = get_bg_color("MiniStatuslineModeInsert") + vim.api.nvim_set_hl(0, "SmoothCursor", { fg = bg_color }) + vim.fn.sign_define("smoothcursor", { text = "" }) + else + bg_color = get_bg_color("MiniStatuslineModeNormal") + vim.api.nvim_set_hl(0, "SmoothCursor", { fg = bg_color }) + vim.fn.sign_define("smoothcursor", { text = "" }) + end end -- Evaluate dependencies and print warnings if needed diff --git a/lua/plugins/editor.lua b/lua/plugins/editor.lua index d4c41ce..e10c4a8 100644 --- a/lua/plugins/editor.lua +++ b/lua/plugins/editor.lua @@ -18,6 +18,14 @@ return { { -- Illuminate import = "lazyvim.plugins.extras.editor.illuminate", }, + { + "akinsho/bufferline.nvim", + opts = { + options = { + separator_style = "slant", + }, + }, + }, { "folke/flash.nvim", opts = { @@ -28,25 +36,8 @@ return { }, }, }, - { + { -- indent-blankline "lukas-reineke/indent-blankline.nvim", - opts = { - scope = { show_start = true, show_end = true }, - indent = { - char = { - "󰎤", - "󰎧", - "󰎪", - "󰎭", - "󰎱", - "󰎳", - "󰎶", - "󰎹", - "󰎼", - "󰽽", - }, - }, - }, }, { -- Outline import = "lazyvim.plugins.extras.editor.outline", @@ -96,7 +87,7 @@ return { }, { -- CodeWindow "gorbit99/codewindow.nvim", - event = "InsertEnter", + event = "BufEnter", config = function() require("codewindow").setup({ auto_enable = true, @@ -128,32 +119,7 @@ return { }, { -- DeadColumn "Bekaboo/deadcolumn.nvim", - event = "InsertEnter", - config = function() - require("deadcolumn").setup({ - scope = "line", ---@type string|fun(): integer - ---@type string[]|fun(mode: string): boolean - modes = function(mode) - return mode:find("^[ictRss\x13]") ~= nil - end, - blending = { - threshold = 0.9, - colorcode = "#737895", - hlgroup = { "Normal", "bg" }, - }, - warning = { - alpha = 0.4, - offset = 0, - colorcode = "#f27b82", - hlgroup = { "Error", "bg" }, - }, - extra = { - ---@type string? - follow_tw = "80", - }, - }) - vim.cmd(":set colorcolumn=120") - end, + event = "BufEnter", }, { -- Precognition "tris203/precognition.nvim", @@ -168,11 +134,11 @@ return { }, { -- SmoothCursor "gen740/SmoothCursor.nvim", - event = "InsertEnter", - lazy = true, + event = "BufEnter", + -- lazy = true, config = function() - ---@diagnostic disable-next-line: missing-parameter - require("smoothcursor").setup() + ---@diagnostic disable-next-line: missing-fields + require("smoothcursor").setup({}) end, }, }