diff --git a/lua/plugins/bufferline.lua b/lua/plugins/bufferline.lua index 53a1915..3da85fa 100644 --- a/lua/plugins/bufferline.lua +++ b/lua/plugins/bufferline.lua @@ -43,10 +43,10 @@ return { color_icons = true, numbers = "none", -- | "ordinal" | "buffer_id" | "both" | function({ ordinal, id, lower, raise }): string, close_command = function(bufnum) - require("user.utils").bufremove(bufnum) + require("user.utils.bufferline").bufremove(bufnum) end, right_mouse_command = function(bufnum) - require("user.utils").bufremove(bufnum) + require("user.utils.bufferline").bufremove(bufnum) end, -- close_command = "bdelete! %d", -- right_mouse_command = "bdelete! %d", diff --git a/lua/plugins/lualine.lua b/lua/plugins/lualine.lua index 8438a51..1cf312e 100644 --- a/lua/plugins/lualine.lua +++ b/lua/plugins/lualine.lua @@ -3,173 +3,24 @@ return { "nvim-lualine/lualine.nvim", event = { "InsertEnter", "BufRead", "BufNewFile" }, config = function() - local hide_in_width = function() - return vim.fn.winwidth(0) > 80 - end - local icons = require("user.icons") - - local getLeftSubstring = function(word, length) - if #word > length then - return string.sub(word, 1, length) .. "..." - else - return word - end - end - - local treesitter = { - function() - return icons.ui.Paint .. " TS" - end, - color = function() - local buf = vim.api.nvim_get_current_buf() - local ts = vim.treesitter.highlighter.active[buf] - return { fg = ts and not vim.tbl_isempty(ts) and "#50fa7b" or "#FF5555" } - end, - cond = hide_in_width, - } - - -- start for lsp - local list_registered_providers_names = function(filetype) - local s = require("null-ls.sources") - local available_sources = s.get_available(filetype) - local registered = {} - for _, source in ipairs(available_sources) do - for method in pairs(source.methods) do - registered[method] = registered[method] or {} - table.insert(registered[method], source.name) - end - end - return registered - end - - local null_ls = require("null-ls") - -- for formatter - local list_registered = function(filetype) - local method = null_ls.methods.FORMATTING - local registered_providers = list_registered_providers_names(filetype) - return registered_providers[method] or {} - end - - --- for linter - local alternative_methods = { - null_ls.methods.DIAGNOSTICS, - null_ls.methods.DIAGNOSTICS_ON_OPEN, - null_ls.methods.DIAGNOSTICS_ON_SAVE, - } - - local linter_list_registered = function(filetype) - local registered_providers = list_registered_providers_names(filetype) - local providers_for_methods = vim.iter(vim.tbl_map(function(m) - return registered_providers[m] or {} - end, alternative_methods)) - - return providers_for_methods - end - -- end for lsp - - local lsp_info = { - function() - local msg = "LSP Inactive" - local buf_ft = vim.bo.filetype - -- start register - local buf_clients = {} - buf_clients = vim.lsp.get_clients({ bufnr = 0 }) - local buf_client_names = {} - if next(buf_clients) == nil then - -- TODO: clean up this if statement - if type(msg) == "boolean" or #msg == 0 then - return "LSP Inactive" - end - return msg - end - -- add client - for _, client in pairs(buf_clients) do - if client.name ~= "null-ls" and client.name ~= "copilot" then - table.insert(buf_client_names, client.name) - end - end - -- add formatter - local supported_formatters = list_registered(buf_ft) - vim.list_extend(buf_client_names, supported_formatters) - -- add linter - local supported_linters = linter_list_registered(buf_ft) - vim.list_extend(buf_client_names, supported_linters) - -- decomple - local unique_client_names = vim.fn.uniq(buf_client_names) - local msg = table.concat(unique_client_names, ", ") - return msg - end, - icon = icons.ui.Gear .. "", - padding = 1, - } - - local diagnostics = { - "diagnostics", - sources = { "nvim_diagnostic" }, - sections = { "error", "warn" }, - symbols = { - error = icons.diagnostics.BoldError .. " ", - warn = icons.diagnostics.BoldWarning .. " ", - }, - colored = true, - update_in_insert = false, - always_visible = false, - } - - local diff = { - "diff", - colored = true, - symbols = { - added = icons.git.LineAdded .. " ", - modified = icons.git.LineModified .. " ", - removed = icons.git.LineRemoved .. " ", - }, - cond = hide_in_width, - } - - local spaces = function() - return icons.ui.Tab .. " " .. vim.api.nvim_get_option_value(0, "shiftwidth") - end - - local mode = { - "mode", - padding = 1, - separator = { left = " " }, - fmt = function(str) - return icons.ui.Neovim .. " " .. str - end, - } - - local get_branch = function() - if vim.b.gitsigns_head ~= nil then - return icons.git.Branch2 .. " " .. getLeftSubstring(vim.b.gitsigns_head, 6) - else - return icons.git.Branch2 .. vim.fn.fnamemodify("", ":t") - end - end - + local component = require("user.utils.lualine_component") + local treesitter = component.treesitter + local lsp_info = component.lsp_info + local diagnostics = component.diagnostics + local diff = component.diff + local spaces = component.spaces + local mode = component.mode + local get_branch = component.get_branch local lsp_progress = {} local data_ok, lspprogress = pcall(require, "lsp-progress") if data_ok then lsp_progress = lspprogress.progress end - local colors = { - blue = "#50fa7b", - cyan = "#f1fa8c", - black = "#1a1b26", - black_transparant = "none", - white = "#c6c6c6", - red = "#ff757f", - skyblue_1 = "#bd93f9", - grey = "#5f6a8e", - yellow = "#ffb86c", - fg_gutter = "#3b4261", - green1 = "#bd93f9", - } + local colors = component.colors -- check config for theme local set_theme - local bubbles_theme = {} + local bubbles_theme local data_exists, config = pcall(require, "core.config") if data_exists then if config.colorscheme ~= nil then @@ -204,40 +55,7 @@ return { end end - bubbles_theme = { - normal = { - a = { fg = colors.black, bg = colors.skyblue_1 }, - b = { fg = colors.white, bg = colors.grey }, - c = { fg = colors.white, bg = colors.black_transparant }, - }, - - insert = { - a = { fg = colors.black, bg = colors.blue }, - b = { fg = colors.blue, bg = colors.grey }, - }, - visual = { - a = { fg = colors.black, bg = colors.cyan }, - b = { fg = colors.cyan, bg = colors.grey }, - }, - replace = { - a = { bg = colors.red, fg = colors.black }, - b = { bg = colors.fg_gutter, fg = colors.red }, - }, - command = { - a = { bg = colors.yellow, fg = colors.black }, - b = { bg = colors.fg_gutter, fg = colors.yellow }, - }, - terminal = { - a = { bg = colors.green1, fg = colors.black }, - b = { bg = colors.fg_gutter, fg = colors.green1 }, - }, - inactive = { - a = { fg = colors.white, bg = colors.black_transparant }, - b = { fg = colors.white, bg = colors.black_transparant }, - c = { fg = colors.black, bg = colors.black_transparant }, - }, - } - + bubbles_theme = component.bubbles_theme(colors) if set_theme == "auto" then bubbles_theme = vim.fn.fnamemodify("auto", ":t") end @@ -269,7 +87,7 @@ return { }, lualine_b = { get_branch }, lualine_c = { diff, lsp_info, lsp_progress }, - lualine_x = { diagnostics, treesitter, spaces, "filetype" }, + lualine_x = { diagnostics, spaces, treesitter, "filetype" }, lualine_y = { "progress" }, lualine_z = { { "location", separator = { right = " " }, padding = 1 }, diff --git a/lua/user/utils.lua b/lua/user/utils.lua deleted file mode 100644 index 809caf3..0000000 --- a/lua/user/utils.lua +++ /dev/null @@ -1,131 +0,0 @@ -local M = {} -function M.bufremove(buf) - buf = buf or 0 - buf = buf == 0 and vim.api.nvim_get_current_buf() or buf - - if vim.bo.modified then - local choice = vim.fn.confirm(("Save changes to %q?"):format(vim.fn.bufname()), "&Yes\n&No\n&Cancel") - if choice == 0 then -- Cancel - return - end - if choice == 1 then -- Yes - vim.cmd.write() - end - end - - for _, win in ipairs(vim.fn.win_findbuf(buf)) do - vim.api.nvim_win_call(win, function() - if not vim.api.nvim_win_is_valid(win) or vim.api.nvim_win_get_buf(win) ~= buf then - return - end - -- Try using alternate buffer - local alt = vim.fn.bufnr("#") - if alt ~= buf and vim.fn.buflisted(alt) == 1 then - vim.api.nvim_win_set_buf(win, alt) - return - end - - -- Try using previous buffer - local has_previous = pcall(vim.cmd, "bprevious") - if has_previous and buf ~= vim.api.nvim_win_get_buf(win) then - return - end - - -- Create new listed buffer - local new_buf = vim.api.nvim_create_buf(true, false) - vim.api.nvim_win_set_buf(win, new_buf) - end) - end - if vim.api.nvim_buf_is_valid(buf) then - pcall(vim.cmd, "bdelete! " .. buf) - end -end - -function M._LAZYGIT_TOGGLE() - local Terminal = require("toggleterm.terminal").Terminal - local lazygit = Terminal:new({ cmd = "lazygit", hidden = true }) - lazygit:toggle() -end - -function M._NODE_TOGGLE() - local Terminal = require("toggleterm.terminal").Terminal - local node = Terminal:new({ cmd = "node", hidden = true }) - node:toggle() -end - -function M._BTOP_TOGGLE() - local Terminal = require("toggleterm.terminal").Terminal - local htop = Terminal:new({ cmd = "btop", hidden = true }) - htop:toggle() -end - -function M._PYTHON_TOGGLE() - local Terminal = require("toggleterm.terminal").Terminal - local python = Terminal:new({ cmd = "python", hidden = true }) - python:toggle() -end - -function M._NEWTAB_TOGGLE() - local Terminal = require("toggleterm.terminal").Terminal - local pwsh = Terminal:new({ cmd = "pwsh", hidden = true, direction = "tab" }) - pwsh:toggle() -end - -function M._OPEN_EXPLORER() - local Terminal = require("toggleterm.terminal").Terminal - local pwsh = Terminal:new({ cmd = "explorer .", hidden = true, direction = "tab" }) - pwsh:toggle() -end - -function M._LIVE_SERVER() - local Terminal = require("toggleterm.terminal").Terminal - local live_server = Terminal:new({ - cmd = "live-server", - hidden = true, - direction = "tab", - }) - live_server:toggle() -end - -function M._OPEN_ALACRITTY() - -- open alacritty new windows current directory - vim.cmd("silent !alacritty --working-directory " .. vim.fn.getcwd()) -end - -function M._OPEN_WEZTERM() - -- open wezterm new windows current directory - vim.cmd("silent !wezterm start --cwd " .. vim.fn.getcwd()) -end - --- get folder name from current directory -function M._get_folder_name() - return vim.fn.fnamemodify(vim.fn.getcwd(), ":t") -end - -function M._OPEN_WEZTERM_TAB() - -- open new tab wezterm current directory - vim.cmd('silent !wezterm cli spawn --cwd "' .. vim.fn.getcwd() .. '"') -end - -function M._SET_TAB_TITLE() - -- set tab title - vim.cmd('silent !wezterm cli set-tab-title "' .. _get_folder_name() .. '"') -end - -function M._CLOSE_BUFFER() - local buf = vim.api.nvim_get_current_buf() - -- delete current buffer - require("bufdelete").bufdelete(buf, true) -end - --- function for close all bufferline -function M._CLOSE_ALL_BUFFER() - -- get all buffer - local bufs = vim.api.nvim_list_bufs() - -- loop through all buffer - for _, buf in pairs(bufs) do - require("user.utils").bufdelete(buf) - end -end - -return M diff --git a/lua/user/utils/bufferline.lua b/lua/user/utils/bufferline.lua new file mode 100644 index 0000000..5953b1b --- /dev/null +++ b/lua/user/utils/bufferline.lua @@ -0,0 +1,44 @@ +local M = {} +function M.bufremove(buf) + buf = buf or 0 + buf = buf == 0 and vim.api.nvim_get_current_buf() or buf + + if vim.bo.modified then + local choice = vim.fn.confirm(("Save changes to %q?"):format(vim.fn.bufname()), "&Yes\n&No\n&Cancel") + if choice == 0 then -- Cancel + return + end + if choice == 1 then -- Yes + vim.cmd.write() + end + end + + for _, win in ipairs(vim.fn.win_findbuf(buf)) do + vim.api.nvim_win_call(win, function() + if not vim.api.nvim_win_is_valid(win) or vim.api.nvim_win_get_buf(win) ~= buf then + return + end + -- Try using alternate buffer + local alt = vim.fn.bufnr("#") + if alt ~= buf and vim.fn.buflisted(alt) == 1 then + vim.api.nvim_win_set_buf(win, alt) + return + end + + -- Try using previous buffer + local has_previous = pcall(vim.cmd, "bprevious") + if has_previous and buf ~= vim.api.nvim_win_get_buf(win) then + return + end + + -- Create new listed buffer + local new_buf = vim.api.nvim_create_buf(true, false) + vim.api.nvim_win_set_buf(win, new_buf) + end) + end + if vim.api.nvim_buf_is_valid(buf) then + pcall(vim.cmd, "bdelete! " .. buf) + end +end + +return M diff --git a/lua/user/utils/formatter.lua b/lua/user/utils/formatter.lua new file mode 100644 index 0000000..6616801 --- /dev/null +++ b/lua/user/utils/formatter.lua @@ -0,0 +1,10 @@ +local null_ls = require("null-ls") +local M = {} + +M.list_registered = function(filetype) + local method = null_ls.methods.FORMATTING + local registered_providers = require("user.utils.lsp").list_registered_providers_names(filetype) + return registered_providers[method] or {} +end + +return M diff --git a/lua/user/utils/linter.lua b/lua/user/utils/linter.lua new file mode 100644 index 0000000..2d91861 --- /dev/null +++ b/lua/user/utils/linter.lua @@ -0,0 +1,19 @@ +local null_ls = require("null-ls") +local M = {} + +M.alternative_methods = { + null_ls.methods.DIAGNOSTICS, + null_ls.methods.DIAGNOSTICS_ON_OPEN, + null_ls.methods.DIAGNOSTICS_ON_SAVE, +} + +M.linter_list_registered = function(filetype) + local registered_providers = require("user.utils.lsp").list_registered_providers_names(filetype) + local providers_for_methods = vim.iter(vim.tbl_map(function(m) + return registered_providers[m] or {} + end, M.alternative_methods)) + + return providers_for_methods +end + +return M diff --git a/lua/user/utils/lsp.lua b/lua/user/utils/lsp.lua new file mode 100644 index 0000000..646517b --- /dev/null +++ b/lua/user/utils/lsp.lua @@ -0,0 +1,16 @@ +local M = {} + +M.list_registered_providers_names = function(filetype) + local s = require("null-ls.sources") + local available_sources = s.get_available(filetype) + local registered = {} + for _, source in ipairs(available_sources) do + for method in pairs(source.methods) do + registered[method] = registered[method] or {} + table.insert(registered[method], source.name) + end + end + return registered +end + +return M diff --git a/lua/user/utils/lualine_component.lua b/lua/user/utils/lualine_component.lua new file mode 100644 index 0000000..4d88e85 --- /dev/null +++ b/lua/user/utils/lualine_component.lua @@ -0,0 +1,193 @@ +local hide_in_width = function() + return vim.fn.winwidth(0) > 75 +end +local icons = require("user.icons") +local formatter = require("user.utils.formatter") +local linter = require("user.utils.linter") + +local getLeftSubstring = function(word, length) + if #word > length then + return string.sub(word, 1, length) .. "..." + else + return word + end +end + +local unique_list = function(list) + local seen = {} + local result = {} + + for _, val in ipairs(list) do + if not seen[val] then + table.insert(result, val) + seen[val] = true + end + end + + return result +end + +return { + -- treesitter info + treesitter = { + function() + return icons.ui.Paint .. " TS" + end, + color = function() + local buf = vim.api.nvim_get_current_buf() + local ts = vim.treesitter.highlighter.active[buf] + return { fg = ts and not vim.tbl_isempty(ts) and "#50fa7b" or "#FF5555" } + end, + cond = hide_in_width, + }, + + -- Lsp info + lsp_info = { + function() + local msg = "LSP Inactive" + local buf_ft = vim.bo.filetype + -- start register + local buf_clients = {} + buf_clients = vim.lsp.get_clients({ bufnr = 0 }) + local buf_client_names = {} + if next(buf_clients) == nil then + -- TODO: clean up this if statement + if type(msg) == "boolean" or #msg == 0 then + return "LSP Inactive" + end + return msg + end + -- add client + for _, client in pairs(buf_clients) do + if client.name ~= "null-ls" and client.name ~= "copilot" then + table.insert(buf_client_names, client.name) + end + end + + -- add formatter + local supported_formatters = formatter.list_registered(buf_ft) + vim.list_extend(buf_client_names, supported_formatters) + + -- add linter + local supported_linters = linter.linter_list_registered(buf_ft) + vim.list_extend(buf_client_names, supported_linters) + + -- decomple + -- local unique_client_names = vim.fn.uniq(buf_client_names) + local unique_client_names = unique_list(buf_client_names) + msg = table.concat(unique_client_names, ", ") + return msg + end, + icon = icons.ui.Gear .. "", + padding = 1, + cond = hide_in_width, + }, + + -- diagnostics info + diagnostics = { + "diagnostics", + sources = { "nvim_diagnostic" }, + sections = { "error", "warn" }, + symbols = { + error = icons.diagnostics.BoldError .. " ", + warn = icons.diagnostics.BoldWarning .. " ", + }, + colored = true, + update_in_insert = false, + always_visible = false, + }, + + -- git info + diff = { + "diff", + colored = true, + symbols = { + added = icons.git.LineAdded .. " ", + modified = icons.git.LineModified .. " ", + removed = icons.git.LineRemoved .. " ", + }, + cond = hide_in_width, + }, + + -- tab info + spaces = { + function() + -- local shiftwidth = vim.api.nvim_buf_get_option(0, "shiftwidth") + -- local shiftwidth = vim.api.nvim_get_option_value("shiftwidth", { scope = "buf", bufnr = 0 }) + local shiftwidth = vim.fn.shiftwidth() + return icons.ui.Tab .. " " .. shiftwidth + end, + padding = 1, + }, + + -- nvim mode info + mode = { + "mode", + padding = 1, + separator = { left = " " }, + fmt = function(str) + return icons.ui.Neovim .. " " .. str + end, + }, + + -- git branch info + get_branch = function() + if vim.b.gitsigns_head ~= nil then + return icons.git.Branch2 .. " " .. getLeftSubstring(vim.b.gitsigns_head, 6) + else + return icons.git.Branch2 .. vim.fn.fnamemodify("", ":t") + end + end, + + -- default colorscheme + colors = { + blue = "#50fa7b", + cyan = "#f1fa8c", + black = "#1a1b26", + black_transparant = "none", + white = "#c6c6c6", + red = "#ff757f", + skyblue_1 = "#bd93f9", + grey = "#5f6a8e", + yellow = "#ffb86c", + fg_gutter = "#3b4261", + green1 = "#bd93f9", + }, + + -- default lualine theme + bubbles_theme = function(colors) + return { + normal = { + a = { fg = colors.black, bg = colors.skyblue_1 }, + b = { fg = colors.white, bg = colors.grey }, + c = { fg = colors.white, bg = colors.black_transparant }, + }, + + insert = { + a = { fg = colors.black, bg = colors.blue }, + b = { fg = colors.blue, bg = colors.grey }, + }, + visual = { + a = { fg = colors.black, bg = colors.cyan }, + b = { fg = colors.cyan, bg = colors.grey }, + }, + replace = { + a = { bg = colors.red, fg = colors.black }, + b = { bg = colors.fg_gutter, fg = colors.red }, + }, + command = { + a = { bg = colors.yellow, fg = colors.black }, + b = { bg = colors.fg_gutter, fg = colors.yellow }, + }, + terminal = { + a = { bg = colors.green1, fg = colors.black }, + b = { bg = colors.fg_gutter, fg = colors.green1 }, + }, + inactive = { + a = { fg = colors.white, bg = colors.black_transparant }, + b = { fg = colors.white, bg = colors.black_transparant }, + c = { fg = colors.black, bg = colors.black_transparant }, + }, + } + end, +} diff --git a/lua/user/utils/whichkey.lua b/lua/user/utils/whichkey.lua new file mode 100644 index 0000000..20b1e15 --- /dev/null +++ b/lua/user/utils/whichkey.lua @@ -0,0 +1,284 @@ +local M = {} + +-- for debug +local debug_key = {} + +if vim.fn.has("win32") == 0 then + debug_key = { + name = "  Debug", + t = { "lua require'dap'.toggle_breakpoint()", "Toggle Breakpoint" }, + b = { "lua require'dap'.step_back()", "Step Back" }, + c = { "lua require'dap'.continue()", "Continue" }, + C = { "lua require'dap'.run_to_cursor()", "Run To Cursor" }, + d = { "lua require'dap'.disconnect()", "Disconnect" }, + g = { "lua require'dap'.session()", "Get Session" }, + i = { "lua require'dap'.step_into()", "Step Into" }, + o = { "lua require'dap'.step_over()", "Step Over" }, + u = { "lua require'dap'.step_out()", "Step Out" }, + p = { "lua require'dap'.pause()", "Pause" }, + r = { "lua require'dap'.repl.toggle()", "Toggle Repl" }, + s = { "lua require'dap'.continue()", "Start" }, + q = { "lua require'dap'.close()", "Quit" }, + U = { "lua require'dapui'.toggle({reset = true})", "Toggle UI" }, + } +end +-- end debug + +function M._LAZYGIT_TOGGLE() + local Terminal = require("toggleterm.terminal").Terminal + local lazygit = Terminal:new({ cmd = "lazygit", hidden = true }) + lazygit:toggle() +end + +function M._NODE_TOGGLE() + local Terminal = require("toggleterm.terminal").Terminal + local node = Terminal:new({ cmd = "node", hidden = true }) + node:toggle() +end + +function M._BTOP_TOGGLE() + local Terminal = require("toggleterm.terminal").Terminal + local htop = Terminal:new({ cmd = "btop", hidden = true }) + htop:toggle() +end + +function M._PYTHON_TOGGLE() + local Terminal = require("toggleterm.terminal").Terminal + local python = Terminal:new({ cmd = "python", hidden = true }) + python:toggle() +end + +function M._NEWTAB_TOGGLE() + local Terminal = require("toggleterm.terminal").Terminal + local pwsh = Terminal:new({ cmd = "pwsh", hidden = true, direction = "tab" }) + pwsh:toggle() +end + +function M._OPEN_EXPLORER() + local Terminal = require("toggleterm.terminal").Terminal + local pwsh = Terminal:new({ cmd = "explorer .", hidden = true, direction = "tab" }) + pwsh:toggle() +end + +function M._LIVE_SERVER() + local Terminal = require("toggleterm.terminal").Terminal + local live_server = Terminal:new({ + cmd = "live-server", + hidden = true, + direction = "tab", + }) + live_server:toggle() +end + +function M._OPEN_ALACRITTY() + -- open alacritty new windows current directory + vim.cmd("silent !alacritty --working-directory " .. vim.fn.getcwd()) +end + +function M._OPEN_WEZTERM() + -- open wezterm new windows current directory + vim.cmd("silent !wezterm start --cwd " .. vim.fn.getcwd()) +end + +-- get folder name from current directory +function M._get_folder_name() + return vim.fn.fnamemodify(vim.fn.getcwd(), ":t") +end + +function M._OPEN_WEZTERM_TAB() + -- open new tab wezterm current directory + vim.cmd('silent !wezterm cli spawn --cwd "' .. vim.fn.getcwd() .. '"') +end + +function M._SET_TAB_TITLE() + -- set tab title + vim.cmd('silent !wezterm cli set-tab-title "' .. _get_folder_name() .. '"') +end + +function M._CLOSE_BUFFER() + local buf = vim.api.nvim_get_current_buf() + -- delete current buffer + require("bufdelete").bufdelete(buf, true) +end + +-- function for close all bufferline +function M._CLOSE_ALL_BUFFER() + -- get all buffer + local bufs = vim.api.nvim_list_bufs() + -- loop through all buffer + for _, buf in pairs(bufs) do + require("user.utils").bufdelete(buf) + end +end + +M.mappings = { + ["a"] = { "Alpha", "󰕮 Alpha" }, + ["e"] = { "NvimTreeToggle", "󰙅 Explorer" }, + ["w"] = { "w!", "󰆓 Save" }, + ["q"] = { "q!", "󰿅 Quit" }, + -- open exloler and close toggleterm + ["o"] = { + "lua require('user.utils.whichkey')._OPEN_EXPLORER()", + "󱏒 Open Explorer", + }, + ["h"] = { "nohlsearch", "󱪿 No Highlight" }, + ["f"] = { + "Telescope find_files ", + " Find files", + }, + ["F"] = { "Telescope live_grep theme=ivy", " Find Text" }, + ["/"] = { + function() + require("Comment.api").toggle.linewise.current() + end, + "󰆈 Coment line", + }, + b = { + name = "  Buffers", + -- show all buffers with telescope + b = { + "lua require('telescope.builtin').buffers(require('telescope.themes').get_dropdown{previewer = false})", + "All Buffer", + }, + -- close current active buffer + c = { "lua require('user.utils.whichkey').bufremove()", "Close current buffer" }, + -- bufferline close left + d = { + "BufferLineCloseLeft", + "Buffer close left", + }, + -- bufferline close right + D = { + "BufferLineCloseRight", + "Buffer close right", + }, + -- bufferline close others + a = { + "BufferLineCloseOthers", + "Buffer close others", + }, + -- close all bufferline + A = { + "BufferLineCloseOthersbd!", + "Buffer close All Buffer", + }, + }, + + g = { + name = "  Git", + g = { "lua require('user.utils.whichkey')._LAZYGIT_TOGGLE()", "Lazygit" }, + j = { "lua require 'gitsigns'.next_hunk()", "Next Hunk" }, + k = { "lua require 'gitsigns'.prev_hunk()", "Prev Hunk" }, + l = { "lua require 'gitsigns'.blame_line()", "Blame" }, + p = { "lua require 'gitsigns'.preview_hunk()", "Preview Hunk" }, + r = { "lua require 'gitsigns'.reset_hunk()", "Reset Hunk" }, + R = { "lua require 'gitsigns'.reset_buffer()", "Reset Buffer" }, + s = { "lua require 'gitsigns'.stage_hunk()", "Stage Hunk" }, + u = { + "lua require 'gitsigns'.undo_stage_hunk()", + "Undo Stage Hunk", + }, + o = { "Telescope git_status", "Open changed file" }, + b = { "Telescope git_branches", "Checkout branch" }, + c = { "Telescope git_commits", "Checkout commit" }, + d = { + "Gitsigns diffthis HEAD", + "Diff", + }, + }, + + l = { + name = "  LSP", + a = { "lua vim.lsp.buf.code_action()", "Code Action" }, + d = { + "Telescope diagnostics bufnr=0", + "Document Diagnostics", + }, + w = { + "Telescope diagnostics", + "Workspace Diagnostics", + }, + f = { "lua vim.lsp.buf.format{async=true}", "Format" }, + i = { "LspInfo", "Info" }, + I = { "Mason", "Installer Info" }, + j = { + "lua vim.lsp.diagnostic.goto_next()", + "Next Diagnostic", + }, + k = { + "lua vim.lsp.diagnostic.goto_prev()", + "Prev Diagnostic", + }, + l = { "lua vim.lsp.codelens.run()", "CodeLens Action" }, + q = { "lua vim.diagnostic.setloclist()", "Quickfix" }, + r = { "lua vim.lsp.buf.rename()", "Rename" }, + s = { "Telescope lsp_document_symbols", "Document Symbols" }, + S = { + "Telescope lsp_dynamic_workspace_symbols", + "Workspace Symbols", + }, + }, + s = { + name = "  Search", + b = { "Telescope git_branches", "Checkout branch" }, + c = { "Telescope colorscheme", "Colorscheme" }, + h = { "Telescope help_tags", "Find Help" }, + M = { "Telescope man_pages", "Man Pages" }, + r = { "Telescope oldfiles", "Open Recent File" }, + R = { "Telescope registers", "Registers" }, + k = { "Telescope keymaps", "Keymaps" }, + C = { "Telescope commands", "Commands" }, + }, + + t = { + name = "  Terminal", + l = { "terminal live-server", "Live Server" }, + P = { "lua require('user.utils.whichkey')._NEWTAB_TOGGLE()", "Power Shell" }, + x = { "ToggleTermToggleAll!", "Close Tab" }, + n = { "lua require('user.utils.whichkey')._NODE_TOGGLE()", "Node" }, + b = { "lua require('user.utils.whichkey')._BTOP_TOGGLE()", "Btop" }, + p = { "lua require('user.utils.whichkey')._PYTHON_TOGGLE()", "Python" }, + f = { "ToggleTerm direction=float", "Float" }, + h = { "ToggleTerm size=10 direction=horizontal", "Horizontal" }, + v = { "ToggleTerm size=80 direction=vertical", "Vertical" }, + s = { "ToggleTerm direction=tab", "New Tab" }, + a = { "lua require('user.utils.whichkey')._OPEN_ALACRITTY()", "Open Alacritty" }, + w = { "lua require('user.utils.whichkey')._OPEN_WEZTERM()", "Open Wezterm" }, + t = { "lua require('user.utils.whichkey')._OPEN_WEZTERM_TAB()", "Open Tab Wezterm" }, + j = { "lua _SET_TAB_TITLE()", "Set Tab Title" }, + }, + r = { + name = "  Run", + l = { "edit term://live-server", "Live Server" }, + s = { + 'autocmd bufwritepost [^_]*.sass,[^_]*.scss silent exec "!sass %:p %:r.css"', + "Auto Compile Sass", + }, + r = { "RunCode", "Run Code" }, + f = { "RunFile", "Run File" }, + p = { "RunProject", "Run Project" }, + g = { "terminalgradle run", "Run Gradle" }, + m = { + "terminal mvn package", + "MVN Build", + }, + }, + d = debug_key, + z = { + name = " 󱑠 Plugins(Lazy)", + i = { "Lazy install", "Install" }, + s = { "Lazy sync", "Sync" }, + S = { "Lazy clear", "Status" }, + c = { "Lazy clean", "Clean" }, + u = { "Lazy update", "Update" }, + p = { "Lazy profile", "Profile" }, + l = { "Lazy log", "Log" }, + d = { "Lazy debug", "Debug" }, + }, +} + +M.mappings2 = { + ["/"] = { "lua require('Comment.api').toggle.linewise(vim.fn.visualmode())", " 󰆈 Commet Block" }, +} + +return M diff --git a/lua/user/whichkey.lua b/lua/user/whichkey.lua index 6be11a8..7a5b8d7 100644 --- a/lua/user/whichkey.lua +++ b/lua/user/whichkey.lua @@ -7,7 +7,7 @@ end function _SET_TAB_TITLE() -- set tab title - vim.cmd('silent !wezterm cli set-tab-title "' .. require("user.utils")._get_folder_name() .. '"') + vim.cmd('silent !wezterm cli set-tab-title "' .. require("user.utils.whichkey")._get_folder_name() .. '"') end local icons = require("user.icons") @@ -101,198 +101,6 @@ local opts2 = { nowait = true, -- use `nowait` when creating keymaps } --- for debug -local debug_key = {} - -if vim.fn.has("win32") == 0 then - debug_key = { - name = "  Debug", - t = { "lua require'dap'.toggle_breakpoint()", "Toggle Breakpoint" }, - b = { "lua require'dap'.step_back()", "Step Back" }, - c = { "lua require'dap'.continue()", "Continue" }, - C = { "lua require'dap'.run_to_cursor()", "Run To Cursor" }, - d = { "lua require'dap'.disconnect()", "Disconnect" }, - g = { "lua require'dap'.session()", "Get Session" }, - i = { "lua require'dap'.step_into()", "Step Into" }, - o = { "lua require'dap'.step_over()", "Step Over" }, - u = { "lua require'dap'.step_out()", "Step Out" }, - p = { "lua require'dap'.pause()", "Pause" }, - r = { "lua require'dap'.repl.toggle()", "Toggle Repl" }, - s = { "lua require'dap'.continue()", "Start" }, - q = { "lua require'dap'.close()", "Quit" }, - U = { "lua require'dapui'.toggle({reset = true})", "Toggle UI" }, - } -end --- end debug -local mappings2 = { - ["/"] = { "lua require('Comment.api').toggle.linewise(vim.fn.visualmode())", " 󰆈 Commet Block" }, -} -local mappings = { - ["a"] = { "Alpha", "󰕮 Alpha" }, - ["e"] = { "NvimTreeToggle", "󰙅 Explorer" }, - ["w"] = { "w!", "󰆓 Save" }, - ["q"] = { "q!", "󰿅 Quit" }, - -- open exloler and close toggleterm - ["o"] = { - "lua require('user.utils')._OPEN_EXPLORER()", - "󱏒 Open Explorer", - }, - ["h"] = { "nohlsearch", "󱪿 No Highlight" }, - ["f"] = { - "Telescope find_files ", - " Find files", - }, - ["F"] = { "Telescope live_grep theme=ivy", " Find Text" }, - ["/"] = { - function() - require("Comment.api").toggle.linewise.current() - end, - "󰆈 Coment line", - }, - b = { - name = "  Buffers", - -- show all buffers with telescope - b = { - "lua require('telescope.builtin').buffers(require('telescope.themes').get_dropdown{previewer = false})", - "All Buffer", - }, - -- close current active buffer - c = { "lua require('user.utils').bufremove()", "Close current buffer" }, - -- bufferline close left - d = { - "BufferLineCloseLeft", - "Buffer close left", - }, - -- bufferline close right - D = { - "BufferLineCloseRight", - "Buffer close right", - }, - -- bufferline close others - a = { - "BufferLineCloseOthers", - "Buffer close others", - }, - -- close all bufferline - A = { - "BufferLineCloseOthersbd!", - "Buffer close All Buffer", - }, - }, - - g = { - name = "  Git", - g = { "lua require('user.utils')._LAZYGIT_TOGGLE()", "Lazygit" }, - j = { "lua require 'gitsigns'.next_hunk()", "Next Hunk" }, - k = { "lua require 'gitsigns'.prev_hunk()", "Prev Hunk" }, - l = { "lua require 'gitsigns'.blame_line()", "Blame" }, - p = { "lua require 'gitsigns'.preview_hunk()", "Preview Hunk" }, - r = { "lua require 'gitsigns'.reset_hunk()", "Reset Hunk" }, - R = { "lua require 'gitsigns'.reset_buffer()", "Reset Buffer" }, - s = { "lua require 'gitsigns'.stage_hunk()", "Stage Hunk" }, - u = { - "lua require 'gitsigns'.undo_stage_hunk()", - "Undo Stage Hunk", - }, - o = { "Telescope git_status", "Open changed file" }, - b = { "Telescope git_branches", "Checkout branch" }, - c = { "Telescope git_commits", "Checkout commit" }, - d = { - "Gitsigns diffthis HEAD", - "Diff", - }, - }, - - l = { - name = "  LSP", - a = { "lua vim.lsp.buf.code_action()", "Code Action" }, - d = { - "Telescope diagnostics bufnr=0", - "Document Diagnostics", - }, - w = { - "Telescope diagnostics", - "Workspace Diagnostics", - }, - f = { "lua vim.lsp.buf.format{async=true}", "Format" }, - i = { "LspInfo", "Info" }, - I = { "Mason", "Installer Info" }, - j = { - "lua vim.lsp.diagnostic.goto_next()", - "Next Diagnostic", - }, - k = { - "lua vim.lsp.diagnostic.goto_prev()", - "Prev Diagnostic", - }, - l = { "lua vim.lsp.codelens.run()", "CodeLens Action" }, - q = { "lua vim.diagnostic.setloclist()", "Quickfix" }, - r = { "lua vim.lsp.buf.rename()", "Rename" }, - s = { "Telescope lsp_document_symbols", "Document Symbols" }, - S = { - "Telescope lsp_dynamic_workspace_symbols", - "Workspace Symbols", - }, - }, - s = { - name = "  Search", - b = { "Telescope git_branches", "Checkout branch" }, - c = { "Telescope colorscheme", "Colorscheme" }, - h = { "Telescope help_tags", "Find Help" }, - M = { "Telescope man_pages", "Man Pages" }, - r = { "Telescope oldfiles", "Open Recent File" }, - R = { "Telescope registers", "Registers" }, - k = { "Telescope keymaps", "Keymaps" }, - C = { "Telescope commands", "Commands" }, - }, - - t = { - name = "  Terminal", - l = { "terminal live-server", "Live Server" }, - P = { "lua require('user.utils')._NEWTAB_TOGGLE()", "Power Shell" }, - x = { "ToggleTermToggleAll!", "Close Tab" }, - n = { "lua require('user.utils')._NODE_TOGGLE()", "Node" }, - b = { "lua require('user.utils')._BTOP_TOGGLE()", "Btop" }, - p = { "lua require('user.utils')._PYTHON_TOGGLE()", "Python" }, - f = { "ToggleTerm direction=float", "Float" }, - h = { "ToggleTerm size=10 direction=horizontal", "Horizontal" }, - v = { "ToggleTerm size=80 direction=vertical", "Vertical" }, - s = { "ToggleTerm direction=tab", "New Tab" }, - a = { "lua require('user.utils')._OPEN_ALACRITTY()", "Open Alacritty" }, - w = { "lua require('user.utils')._OPEN_WEZTERM()", "Open Wezterm" }, - t = { "lua require('user.utils')._OPEN_WEZTERM_TAB()", "Open Tab Wezterm" }, - j = { "lua _SET_TAB_TITLE()", "Set Tab Title" }, - }, - r = { - name = "  Run", - l = { "edit term://live-server", "Live Server" }, - s = { - 'autocmd bufwritepost [^_]*.sass,[^_]*.scss silent exec "!sass %:p %:r.css"', - "Auto Compile Sass", - }, - r = { "RunCode", "Run Code" }, - f = { "RunFile", "Run File" }, - p = { "RunProject", "Run Project" }, - g = { "terminalgradle run", "Run Gradle" }, - m = { - "terminal mvn package", - "MVN Build", - }, - }, - d = debug_key, - z = { - name = " 󱑠 Plugins(Lazy)", - i = { "Lazy install", "Install" }, - s = { "Lazy sync", "Sync" }, - S = { "Lazy clear", "Status" }, - c = { "Lazy clean", "Clean" }, - u = { "Lazy update", "Update" }, - p = { "Lazy profile", "Profile" }, - l = { "Lazy log", "Log" }, - d = { "Lazy debug", "Debug" }, - }, -} - local wkey = {} local data_exists, key = pcall(require, "core.config") if data_exists then @@ -300,6 +108,6 @@ if data_exists then end which_key.setup(setup) -which_key.register(mappings, opts) +which_key.register(require("user.utils.whichkey").mappings, opts) which_key.register(wkey, opts) -which_key.register(mappings2, opts2) +which_key.register(require("user.utils.whichkey").mappings2, opts2)