mirror of
https://github.com/pojokcodeid/nvim-lazy.git
synced 2025-06-22 08:53:31 +02:00
add: tidy up the code, more modular
This commit is contained in:
parent
1545d8335d
commit
1f424a1225
10 changed files with 583 additions and 522 deletions
|
@ -43,10 +43,10 @@ return {
|
||||||
color_icons = true,
|
color_icons = true,
|
||||||
numbers = "none", -- | "ordinal" | "buffer_id" | "both" | function({ ordinal, id, lower, raise }): string,
|
numbers = "none", -- | "ordinal" | "buffer_id" | "both" | function({ ordinal, id, lower, raise }): string,
|
||||||
close_command = function(bufnum)
|
close_command = function(bufnum)
|
||||||
require("user.utils").bufremove(bufnum)
|
require("user.utils.bufferline").bufremove(bufnum)
|
||||||
end,
|
end,
|
||||||
right_mouse_command = function(bufnum)
|
right_mouse_command = function(bufnum)
|
||||||
require("user.utils").bufremove(bufnum)
|
require("user.utils.bufferline").bufremove(bufnum)
|
||||||
end,
|
end,
|
||||||
-- close_command = "bdelete! %d",
|
-- close_command = "bdelete! %d",
|
||||||
-- right_mouse_command = "bdelete! %d",
|
-- right_mouse_command = "bdelete! %d",
|
||||||
|
|
|
@ -3,173 +3,24 @@ return {
|
||||||
"nvim-lualine/lualine.nvim",
|
"nvim-lualine/lualine.nvim",
|
||||||
event = { "InsertEnter", "BufRead", "BufNewFile" },
|
event = { "InsertEnter", "BufRead", "BufNewFile" },
|
||||||
config = function()
|
config = function()
|
||||||
local hide_in_width = function()
|
local component = require("user.utils.lualine_component")
|
||||||
return vim.fn.winwidth(0) > 80
|
local treesitter = component.treesitter
|
||||||
end
|
local lsp_info = component.lsp_info
|
||||||
local icons = require("user.icons")
|
local diagnostics = component.diagnostics
|
||||||
|
local diff = component.diff
|
||||||
local getLeftSubstring = function(word, length)
|
local spaces = component.spaces
|
||||||
if #word > length then
|
local mode = component.mode
|
||||||
return string.sub(word, 1, length) .. "..."
|
local get_branch = component.get_branch
|
||||||
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 lsp_progress = {}
|
local lsp_progress = {}
|
||||||
local data_ok, lspprogress = pcall(require, "lsp-progress")
|
local data_ok, lspprogress = pcall(require, "lsp-progress")
|
||||||
if data_ok then
|
if data_ok then
|
||||||
lsp_progress = lspprogress.progress
|
lsp_progress = lspprogress.progress
|
||||||
end
|
end
|
||||||
local colors = {
|
local colors = component.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",
|
|
||||||
}
|
|
||||||
|
|
||||||
-- check config for theme
|
-- check config for theme
|
||||||
local set_theme
|
local set_theme
|
||||||
local bubbles_theme = {}
|
local bubbles_theme
|
||||||
local data_exists, config = pcall(require, "core.config")
|
local data_exists, config = pcall(require, "core.config")
|
||||||
if data_exists then
|
if data_exists then
|
||||||
if config.colorscheme ~= nil then
|
if config.colorscheme ~= nil then
|
||||||
|
@ -204,40 +55,7 @@ return {
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
bubbles_theme = {
|
bubbles_theme = component.bubbles_theme(colors)
|
||||||
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 },
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
if set_theme == "auto" then
|
if set_theme == "auto" then
|
||||||
bubbles_theme = vim.fn.fnamemodify("auto", ":t")
|
bubbles_theme = vim.fn.fnamemodify("auto", ":t")
|
||||||
end
|
end
|
||||||
|
@ -269,7 +87,7 @@ return {
|
||||||
},
|
},
|
||||||
lualine_b = { get_branch },
|
lualine_b = { get_branch },
|
||||||
lualine_c = { diff, lsp_info, lsp_progress },
|
lualine_c = { diff, lsp_info, lsp_progress },
|
||||||
lualine_x = { diagnostics, treesitter, spaces, "filetype" },
|
lualine_x = { diagnostics, spaces, treesitter, "filetype" },
|
||||||
lualine_y = { "progress" },
|
lualine_y = { "progress" },
|
||||||
lualine_z = {
|
lualine_z = {
|
||||||
{ "location", separator = { right = " " }, padding = 1 },
|
{ "location", separator = { right = " " }, padding = 1 },
|
||||||
|
|
|
@ -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
|
|
44
lua/user/utils/bufferline.lua
Normal file
44
lua/user/utils/bufferline.lua
Normal file
|
@ -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
|
10
lua/user/utils/formatter.lua
Normal file
10
lua/user/utils/formatter.lua
Normal file
|
@ -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
|
19
lua/user/utils/linter.lua
Normal file
19
lua/user/utils/linter.lua
Normal file
|
@ -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
|
16
lua/user/utils/lsp.lua
Normal file
16
lua/user/utils/lsp.lua
Normal file
|
@ -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
|
193
lua/user/utils/lualine_component.lua
Normal file
193
lua/user/utils/lualine_component.lua
Normal file
|
@ -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,
|
||||||
|
}
|
284
lua/user/utils/whichkey.lua
Normal file
284
lua/user/utils/whichkey.lua
Normal file
|
@ -0,0 +1,284 @@
|
||||||
|
local M = {}
|
||||||
|
|
||||||
|
-- for debug
|
||||||
|
local debug_key = {}
|
||||||
|
|
||||||
|
if vim.fn.has("win32") == 0 then
|
||||||
|
debug_key = {
|
||||||
|
name = " Debug",
|
||||||
|
t = { "<cmd>lua require'dap'.toggle_breakpoint()<cr>", "Toggle Breakpoint" },
|
||||||
|
b = { "<cmd>lua require'dap'.step_back()<cr>", "Step Back" },
|
||||||
|
c = { "<cmd>lua require'dap'.continue()<cr>", "Continue" },
|
||||||
|
C = { "<cmd>lua require'dap'.run_to_cursor()<cr>", "Run To Cursor" },
|
||||||
|
d = { "<cmd>lua require'dap'.disconnect()<cr>", "Disconnect" },
|
||||||
|
g = { "<cmd>lua require'dap'.session()<cr>", "Get Session" },
|
||||||
|
i = { "<cmd>lua require'dap'.step_into()<cr>", "Step Into" },
|
||||||
|
o = { "<cmd>lua require'dap'.step_over()<cr>", "Step Over" },
|
||||||
|
u = { "<cmd>lua require'dap'.step_out()<cr>", "Step Out" },
|
||||||
|
p = { "<cmd>lua require'dap'.pause()<cr>", "Pause" },
|
||||||
|
r = { "<cmd>lua require'dap'.repl.toggle()<cr>", "Toggle Repl" },
|
||||||
|
s = { "<cmd>lua require'dap'.continue()<cr>", "Start" },
|
||||||
|
q = { "<cmd>lua require'dap'.close()<cr>", "Quit" },
|
||||||
|
U = { "<cmd>lua require'dapui'.toggle({reset = true})<cr>", "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"] = { "<cmd>Alpha<cr>", " Alpha" },
|
||||||
|
["e"] = { "<cmd>NvimTreeToggle<cr>", " Explorer" },
|
||||||
|
["w"] = { "<cmd>w!<CR>", " Save" },
|
||||||
|
["q"] = { "<cmd>q!<CR>", " Quit" },
|
||||||
|
-- open exloler and close toggleterm
|
||||||
|
["o"] = {
|
||||||
|
"<cmd>lua require('user.utils.whichkey')._OPEN_EXPLORER()<cr>",
|
||||||
|
" Open Explorer",
|
||||||
|
},
|
||||||
|
["h"] = { "<cmd>nohlsearch<CR>", " No Highlight" },
|
||||||
|
["f"] = {
|
||||||
|
"<cmd>Telescope find_files <CR>",
|
||||||
|
" Find files",
|
||||||
|
},
|
||||||
|
["F"] = { "<cmd>Telescope live_grep theme=ivy<cr>", " Find Text" },
|
||||||
|
["/"] = {
|
||||||
|
function()
|
||||||
|
require("Comment.api").toggle.linewise.current()
|
||||||
|
end,
|
||||||
|
" Coment line",
|
||||||
|
},
|
||||||
|
b = {
|
||||||
|
name = " Buffers",
|
||||||
|
-- show all buffers with telescope
|
||||||
|
b = {
|
||||||
|
"<cmd>lua require('telescope.builtin').buffers(require('telescope.themes').get_dropdown{previewer = false})<cr>",
|
||||||
|
"All Buffer",
|
||||||
|
},
|
||||||
|
-- close current active buffer
|
||||||
|
c = { "<cmd>lua require('user.utils.whichkey').bufremove()<cr>", "Close current buffer" },
|
||||||
|
-- bufferline close left
|
||||||
|
d = {
|
||||||
|
"<cmd>BufferLineCloseLeft<cr>",
|
||||||
|
"Buffer close left",
|
||||||
|
},
|
||||||
|
-- bufferline close right
|
||||||
|
D = {
|
||||||
|
"<cmd>BufferLineCloseRight<cr>",
|
||||||
|
"Buffer close right",
|
||||||
|
},
|
||||||
|
-- bufferline close others
|
||||||
|
a = {
|
||||||
|
"<cmd>BufferLineCloseOthers<cr>",
|
||||||
|
"Buffer close others",
|
||||||
|
},
|
||||||
|
-- close all bufferline
|
||||||
|
A = {
|
||||||
|
"<cmd>BufferLineCloseOthers<cr><cmd>bd!<cr>",
|
||||||
|
"Buffer close All Buffer",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
g = {
|
||||||
|
name = " Git",
|
||||||
|
g = { "<cmd>lua require('user.utils.whichkey')._LAZYGIT_TOGGLE()<CR>", "Lazygit" },
|
||||||
|
j = { "<cmd>lua require 'gitsigns'.next_hunk()<cr>", "Next Hunk" },
|
||||||
|
k = { "<cmd>lua require 'gitsigns'.prev_hunk()<cr>", "Prev Hunk" },
|
||||||
|
l = { "<cmd>lua require 'gitsigns'.blame_line()<cr>", "Blame" },
|
||||||
|
p = { "<cmd>lua require 'gitsigns'.preview_hunk()<cr>", "Preview Hunk" },
|
||||||
|
r = { "<cmd>lua require 'gitsigns'.reset_hunk()<cr>", "Reset Hunk" },
|
||||||
|
R = { "<cmd>lua require 'gitsigns'.reset_buffer()<cr>", "Reset Buffer" },
|
||||||
|
s = { "<cmd>lua require 'gitsigns'.stage_hunk()<cr>", "Stage Hunk" },
|
||||||
|
u = {
|
||||||
|
"<cmd>lua require 'gitsigns'.undo_stage_hunk()<cr>",
|
||||||
|
"Undo Stage Hunk",
|
||||||
|
},
|
||||||
|
o = { "<cmd>Telescope git_status<cr>", "Open changed file" },
|
||||||
|
b = { "<cmd>Telescope git_branches<cr>", "Checkout branch" },
|
||||||
|
c = { "<cmd>Telescope git_commits<cr>", "Checkout commit" },
|
||||||
|
d = {
|
||||||
|
"<cmd>Gitsigns diffthis HEAD<cr>",
|
||||||
|
"Diff",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
l = {
|
||||||
|
name = " LSP",
|
||||||
|
a = { "<cmd>lua vim.lsp.buf.code_action()<cr>", "Code Action" },
|
||||||
|
d = {
|
||||||
|
"<cmd>Telescope diagnostics bufnr=0<cr>",
|
||||||
|
"Document Diagnostics",
|
||||||
|
},
|
||||||
|
w = {
|
||||||
|
"<cmd>Telescope diagnostics<cr>",
|
||||||
|
"Workspace Diagnostics",
|
||||||
|
},
|
||||||
|
f = { "<cmd>lua vim.lsp.buf.format{async=true}<cr>", "Format" },
|
||||||
|
i = { "<cmd>LspInfo<cr>", "Info" },
|
||||||
|
I = { "<cmd>Mason<cr>", "Installer Info" },
|
||||||
|
j = {
|
||||||
|
"<cmd>lua vim.lsp.diagnostic.goto_next()<CR>",
|
||||||
|
"Next Diagnostic",
|
||||||
|
},
|
||||||
|
k = {
|
||||||
|
"<cmd>lua vim.lsp.diagnostic.goto_prev()<cr>",
|
||||||
|
"Prev Diagnostic",
|
||||||
|
},
|
||||||
|
l = { "<cmd>lua vim.lsp.codelens.run()<cr>", "CodeLens Action" },
|
||||||
|
q = { "<cmd>lua vim.diagnostic.setloclist()<cr>", "Quickfix" },
|
||||||
|
r = { "<cmd>lua vim.lsp.buf.rename()<cr>", "Rename" },
|
||||||
|
s = { "<cmd>Telescope lsp_document_symbols<cr>", "Document Symbols" },
|
||||||
|
S = {
|
||||||
|
"<cmd>Telescope lsp_dynamic_workspace_symbols<cr>",
|
||||||
|
"Workspace Symbols",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
s = {
|
||||||
|
name = " Search",
|
||||||
|
b = { "<cmd>Telescope git_branches<cr>", "Checkout branch" },
|
||||||
|
c = { "<cmd>Telescope colorscheme<cr>", "Colorscheme" },
|
||||||
|
h = { "<cmd>Telescope help_tags<cr>", "Find Help" },
|
||||||
|
M = { "<cmd>Telescope man_pages<cr>", "Man Pages" },
|
||||||
|
r = { "<cmd>Telescope oldfiles<cr>", "Open Recent File" },
|
||||||
|
R = { "<cmd>Telescope registers<cr>", "Registers" },
|
||||||
|
k = { "<cmd>Telescope keymaps<cr>", "Keymaps" },
|
||||||
|
C = { "<cmd>Telescope commands<cr>", "Commands" },
|
||||||
|
},
|
||||||
|
|
||||||
|
t = {
|
||||||
|
name = " Terminal",
|
||||||
|
l = { "<cmd>terminal live-server<cr>", "Live Server" },
|
||||||
|
P = { "<cmd>lua require('user.utils.whichkey')._NEWTAB_TOGGLE()<cr>", "Power Shell" },
|
||||||
|
x = { "<cmd>ToggleTermToggleAll!<cr>", "Close Tab" },
|
||||||
|
n = { "<cmd>lua require('user.utils.whichkey')._NODE_TOGGLE()<cr>", "Node" },
|
||||||
|
b = { "<cmd>lua require('user.utils.whichkey')._BTOP_TOGGLE()<cr>", "Btop" },
|
||||||
|
p = { "<cmd>lua require('user.utils.whichkey')._PYTHON_TOGGLE()<cr>", "Python" },
|
||||||
|
f = { "<cmd>ToggleTerm direction=float<cr>", "Float" },
|
||||||
|
h = { "<cmd>ToggleTerm size=10 direction=horizontal<cr>", "Horizontal" },
|
||||||
|
v = { "<cmd>ToggleTerm size=80 direction=vertical<cr>", "Vertical" },
|
||||||
|
s = { "<cmd>ToggleTerm direction=tab<cr>", "New Tab" },
|
||||||
|
a = { "<cmd>lua require('user.utils.whichkey')._OPEN_ALACRITTY()<cr>", "Open Alacritty" },
|
||||||
|
w = { "<cmd>lua require('user.utils.whichkey')._OPEN_WEZTERM()<cr>", "Open Wezterm" },
|
||||||
|
t = { "<cmd>lua require('user.utils.whichkey')._OPEN_WEZTERM_TAB()<cr>", "Open Tab Wezterm" },
|
||||||
|
j = { "<cmd>lua _SET_TAB_TITLE()<cr>", "Set Tab Title" },
|
||||||
|
},
|
||||||
|
r = {
|
||||||
|
name = " Run",
|
||||||
|
l = { "<cmd>edit term://live-server<cr>", "Live Server" },
|
||||||
|
s = {
|
||||||
|
'<cmd>autocmd bufwritepost [^_]*.sass,[^_]*.scss silent exec "!sass %:p %:r.css"<CR>',
|
||||||
|
"Auto Compile Sass",
|
||||||
|
},
|
||||||
|
r = { "<cmd>RunCode<CR>", "Run Code" },
|
||||||
|
f = { "<cmd>RunFile<CR>", "Run File" },
|
||||||
|
p = { "<cmd>RunProject<CR>", "Run Project" },
|
||||||
|
g = { "<cmd>terminal<cr>gradle run<cr>", "Run Gradle" },
|
||||||
|
m = {
|
||||||
|
"<cmd>terminal mvn package<cr>",
|
||||||
|
"MVN Build",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
d = debug_key,
|
||||||
|
z = {
|
||||||
|
name = " Plugins(Lazy)",
|
||||||
|
i = { "<cmd>Lazy install<cr>", "Install" },
|
||||||
|
s = { "<cmd>Lazy sync<cr>", "Sync" },
|
||||||
|
S = { "<cmd>Lazy clear<cr>", "Status" },
|
||||||
|
c = { "<cmd>Lazy clean<cr>", "Clean" },
|
||||||
|
u = { "<cmd>Lazy update<cr>", "Update" },
|
||||||
|
p = { "<cmd>Lazy profile<cr>", "Profile" },
|
||||||
|
l = { "<cmd>Lazy log<cr>", "Log" },
|
||||||
|
d = { "<cmd>Lazy debug<cr>", "Debug" },
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
M.mappings2 = {
|
||||||
|
["/"] = { "<esc><cmd>lua require('Comment.api').toggle.linewise(vim.fn.visualmode())<cr>", " Commet Block" },
|
||||||
|
}
|
||||||
|
|
||||||
|
return M
|
|
@ -7,7 +7,7 @@ end
|
||||||
|
|
||||||
function _SET_TAB_TITLE()
|
function _SET_TAB_TITLE()
|
||||||
-- 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
|
end
|
||||||
|
|
||||||
local icons = require("user.icons")
|
local icons = require("user.icons")
|
||||||
|
@ -101,198 +101,6 @@ local opts2 = {
|
||||||
nowait = true, -- use `nowait` when creating keymaps
|
nowait = true, -- use `nowait` when creating keymaps
|
||||||
}
|
}
|
||||||
|
|
||||||
-- for debug
|
|
||||||
local debug_key = {}
|
|
||||||
|
|
||||||
if vim.fn.has("win32") == 0 then
|
|
||||||
debug_key = {
|
|
||||||
name = " Debug",
|
|
||||||
t = { "<cmd>lua require'dap'.toggle_breakpoint()<cr>", "Toggle Breakpoint" },
|
|
||||||
b = { "<cmd>lua require'dap'.step_back()<cr>", "Step Back" },
|
|
||||||
c = { "<cmd>lua require'dap'.continue()<cr>", "Continue" },
|
|
||||||
C = { "<cmd>lua require'dap'.run_to_cursor()<cr>", "Run To Cursor" },
|
|
||||||
d = { "<cmd>lua require'dap'.disconnect()<cr>", "Disconnect" },
|
|
||||||
g = { "<cmd>lua require'dap'.session()<cr>", "Get Session" },
|
|
||||||
i = { "<cmd>lua require'dap'.step_into()<cr>", "Step Into" },
|
|
||||||
o = { "<cmd>lua require'dap'.step_over()<cr>", "Step Over" },
|
|
||||||
u = { "<cmd>lua require'dap'.step_out()<cr>", "Step Out" },
|
|
||||||
p = { "<cmd>lua require'dap'.pause()<cr>", "Pause" },
|
|
||||||
r = { "<cmd>lua require'dap'.repl.toggle()<cr>", "Toggle Repl" },
|
|
||||||
s = { "<cmd>lua require'dap'.continue()<cr>", "Start" },
|
|
||||||
q = { "<cmd>lua require'dap'.close()<cr>", "Quit" },
|
|
||||||
U = { "<cmd>lua require'dapui'.toggle({reset = true})<cr>", "Toggle UI" },
|
|
||||||
}
|
|
||||||
end
|
|
||||||
-- end debug
|
|
||||||
local mappings2 = {
|
|
||||||
["/"] = { "<esc><cmd>lua require('Comment.api').toggle.linewise(vim.fn.visualmode())<cr>", " Commet Block" },
|
|
||||||
}
|
|
||||||
local mappings = {
|
|
||||||
["a"] = { "<cmd>Alpha<cr>", " Alpha" },
|
|
||||||
["e"] = { "<cmd>NvimTreeToggle<cr>", " Explorer" },
|
|
||||||
["w"] = { "<cmd>w!<CR>", " Save" },
|
|
||||||
["q"] = { "<cmd>q!<CR>", " Quit" },
|
|
||||||
-- open exloler and close toggleterm
|
|
||||||
["o"] = {
|
|
||||||
"<cmd>lua require('user.utils')._OPEN_EXPLORER()<cr>",
|
|
||||||
" Open Explorer",
|
|
||||||
},
|
|
||||||
["h"] = { "<cmd>nohlsearch<CR>", " No Highlight" },
|
|
||||||
["f"] = {
|
|
||||||
"<cmd>Telescope find_files <CR>",
|
|
||||||
" Find files",
|
|
||||||
},
|
|
||||||
["F"] = { "<cmd>Telescope live_grep theme=ivy<cr>", " Find Text" },
|
|
||||||
["/"] = {
|
|
||||||
function()
|
|
||||||
require("Comment.api").toggle.linewise.current()
|
|
||||||
end,
|
|
||||||
" Coment line",
|
|
||||||
},
|
|
||||||
b = {
|
|
||||||
name = " Buffers",
|
|
||||||
-- show all buffers with telescope
|
|
||||||
b = {
|
|
||||||
"<cmd>lua require('telescope.builtin').buffers(require('telescope.themes').get_dropdown{previewer = false})<cr>",
|
|
||||||
"All Buffer",
|
|
||||||
},
|
|
||||||
-- close current active buffer
|
|
||||||
c = { "<cmd>lua require('user.utils').bufremove()<cr>", "Close current buffer" },
|
|
||||||
-- bufferline close left
|
|
||||||
d = {
|
|
||||||
"<cmd>BufferLineCloseLeft<cr>",
|
|
||||||
"Buffer close left",
|
|
||||||
},
|
|
||||||
-- bufferline close right
|
|
||||||
D = {
|
|
||||||
"<cmd>BufferLineCloseRight<cr>",
|
|
||||||
"Buffer close right",
|
|
||||||
},
|
|
||||||
-- bufferline close others
|
|
||||||
a = {
|
|
||||||
"<cmd>BufferLineCloseOthers<cr>",
|
|
||||||
"Buffer close others",
|
|
||||||
},
|
|
||||||
-- close all bufferline
|
|
||||||
A = {
|
|
||||||
"<cmd>BufferLineCloseOthers<cr><cmd>bd!<cr>",
|
|
||||||
"Buffer close All Buffer",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
g = {
|
|
||||||
name = " Git",
|
|
||||||
g = { "<cmd>lua require('user.utils')._LAZYGIT_TOGGLE()<CR>", "Lazygit" },
|
|
||||||
j = { "<cmd>lua require 'gitsigns'.next_hunk()<cr>", "Next Hunk" },
|
|
||||||
k = { "<cmd>lua require 'gitsigns'.prev_hunk()<cr>", "Prev Hunk" },
|
|
||||||
l = { "<cmd>lua require 'gitsigns'.blame_line()<cr>", "Blame" },
|
|
||||||
p = { "<cmd>lua require 'gitsigns'.preview_hunk()<cr>", "Preview Hunk" },
|
|
||||||
r = { "<cmd>lua require 'gitsigns'.reset_hunk()<cr>", "Reset Hunk" },
|
|
||||||
R = { "<cmd>lua require 'gitsigns'.reset_buffer()<cr>", "Reset Buffer" },
|
|
||||||
s = { "<cmd>lua require 'gitsigns'.stage_hunk()<cr>", "Stage Hunk" },
|
|
||||||
u = {
|
|
||||||
"<cmd>lua require 'gitsigns'.undo_stage_hunk()<cr>",
|
|
||||||
"Undo Stage Hunk",
|
|
||||||
},
|
|
||||||
o = { "<cmd>Telescope git_status<cr>", "Open changed file" },
|
|
||||||
b = { "<cmd>Telescope git_branches<cr>", "Checkout branch" },
|
|
||||||
c = { "<cmd>Telescope git_commits<cr>", "Checkout commit" },
|
|
||||||
d = {
|
|
||||||
"<cmd>Gitsigns diffthis HEAD<cr>",
|
|
||||||
"Diff",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
l = {
|
|
||||||
name = " LSP",
|
|
||||||
a = { "<cmd>lua vim.lsp.buf.code_action()<cr>", "Code Action" },
|
|
||||||
d = {
|
|
||||||
"<cmd>Telescope diagnostics bufnr=0<cr>",
|
|
||||||
"Document Diagnostics",
|
|
||||||
},
|
|
||||||
w = {
|
|
||||||
"<cmd>Telescope diagnostics<cr>",
|
|
||||||
"Workspace Diagnostics",
|
|
||||||
},
|
|
||||||
f = { "<cmd>lua vim.lsp.buf.format{async=true}<cr>", "Format" },
|
|
||||||
i = { "<cmd>LspInfo<cr>", "Info" },
|
|
||||||
I = { "<cmd>Mason<cr>", "Installer Info" },
|
|
||||||
j = {
|
|
||||||
"<cmd>lua vim.lsp.diagnostic.goto_next()<CR>",
|
|
||||||
"Next Diagnostic",
|
|
||||||
},
|
|
||||||
k = {
|
|
||||||
"<cmd>lua vim.lsp.diagnostic.goto_prev()<cr>",
|
|
||||||
"Prev Diagnostic",
|
|
||||||
},
|
|
||||||
l = { "<cmd>lua vim.lsp.codelens.run()<cr>", "CodeLens Action" },
|
|
||||||
q = { "<cmd>lua vim.diagnostic.setloclist()<cr>", "Quickfix" },
|
|
||||||
r = { "<cmd>lua vim.lsp.buf.rename()<cr>", "Rename" },
|
|
||||||
s = { "<cmd>Telescope lsp_document_symbols<cr>", "Document Symbols" },
|
|
||||||
S = {
|
|
||||||
"<cmd>Telescope lsp_dynamic_workspace_symbols<cr>",
|
|
||||||
"Workspace Symbols",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
s = {
|
|
||||||
name = " Search",
|
|
||||||
b = { "<cmd>Telescope git_branches<cr>", "Checkout branch" },
|
|
||||||
c = { "<cmd>Telescope colorscheme<cr>", "Colorscheme" },
|
|
||||||
h = { "<cmd>Telescope help_tags<cr>", "Find Help" },
|
|
||||||
M = { "<cmd>Telescope man_pages<cr>", "Man Pages" },
|
|
||||||
r = { "<cmd>Telescope oldfiles<cr>", "Open Recent File" },
|
|
||||||
R = { "<cmd>Telescope registers<cr>", "Registers" },
|
|
||||||
k = { "<cmd>Telescope keymaps<cr>", "Keymaps" },
|
|
||||||
C = { "<cmd>Telescope commands<cr>", "Commands" },
|
|
||||||
},
|
|
||||||
|
|
||||||
t = {
|
|
||||||
name = " Terminal",
|
|
||||||
l = { "<cmd>terminal live-server<cr>", "Live Server" },
|
|
||||||
P = { "<cmd>lua require('user.utils')._NEWTAB_TOGGLE()<cr>", "Power Shell" },
|
|
||||||
x = { "<cmd>ToggleTermToggleAll!<cr>", "Close Tab" },
|
|
||||||
n = { "<cmd>lua require('user.utils')._NODE_TOGGLE()<cr>", "Node" },
|
|
||||||
b = { "<cmd>lua require('user.utils')._BTOP_TOGGLE()<cr>", "Btop" },
|
|
||||||
p = { "<cmd>lua require('user.utils')._PYTHON_TOGGLE()<cr>", "Python" },
|
|
||||||
f = { "<cmd>ToggleTerm direction=float<cr>", "Float" },
|
|
||||||
h = { "<cmd>ToggleTerm size=10 direction=horizontal<cr>", "Horizontal" },
|
|
||||||
v = { "<cmd>ToggleTerm size=80 direction=vertical<cr>", "Vertical" },
|
|
||||||
s = { "<cmd>ToggleTerm direction=tab<cr>", "New Tab" },
|
|
||||||
a = { "<cmd>lua require('user.utils')._OPEN_ALACRITTY()<cr>", "Open Alacritty" },
|
|
||||||
w = { "<cmd>lua require('user.utils')._OPEN_WEZTERM()<cr>", "Open Wezterm" },
|
|
||||||
t = { "<cmd>lua require('user.utils')._OPEN_WEZTERM_TAB()<cr>", "Open Tab Wezterm" },
|
|
||||||
j = { "<cmd>lua _SET_TAB_TITLE()<cr>", "Set Tab Title" },
|
|
||||||
},
|
|
||||||
r = {
|
|
||||||
name = " Run",
|
|
||||||
l = { "<cmd>edit term://live-server<cr>", "Live Server" },
|
|
||||||
s = {
|
|
||||||
'<cmd>autocmd bufwritepost [^_]*.sass,[^_]*.scss silent exec "!sass %:p %:r.css"<CR>',
|
|
||||||
"Auto Compile Sass",
|
|
||||||
},
|
|
||||||
r = { "<cmd>RunCode<CR>", "Run Code" },
|
|
||||||
f = { "<cmd>RunFile<CR>", "Run File" },
|
|
||||||
p = { "<cmd>RunProject<CR>", "Run Project" },
|
|
||||||
g = { "<cmd>terminal<cr>gradle run<cr>", "Run Gradle" },
|
|
||||||
m = {
|
|
||||||
"<cmd>terminal mvn package<cr>",
|
|
||||||
"MVN Build",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
d = debug_key,
|
|
||||||
z = {
|
|
||||||
name = " Plugins(Lazy)",
|
|
||||||
i = { "<cmd>Lazy install<cr>", "Install" },
|
|
||||||
s = { "<cmd>Lazy sync<cr>", "Sync" },
|
|
||||||
S = { "<cmd>Lazy clear<cr>", "Status" },
|
|
||||||
c = { "<cmd>Lazy clean<cr>", "Clean" },
|
|
||||||
u = { "<cmd>Lazy update<cr>", "Update" },
|
|
||||||
p = { "<cmd>Lazy profile<cr>", "Profile" },
|
|
||||||
l = { "<cmd>Lazy log<cr>", "Log" },
|
|
||||||
d = { "<cmd>Lazy debug<cr>", "Debug" },
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
local wkey = {}
|
local wkey = {}
|
||||||
local data_exists, key = pcall(require, "core.config")
|
local data_exists, key = pcall(require, "core.config")
|
||||||
if data_exists then
|
if data_exists then
|
||||||
|
@ -300,6 +108,6 @@ if data_exists then
|
||||||
end
|
end
|
||||||
|
|
||||||
which_key.setup(setup)
|
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(wkey, opts)
|
||||||
which_key.register(mappings2, opts2)
|
which_key.register(require("user.utils.whichkey").mappings2, opts2)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue