refactor folder structure
This commit is contained in:
148
hosts/nb/modules/nvim/config/which-key.lua
Normal file
148
hosts/nb/modules/nvim/config/which-key.lua
Normal file
@@ -0,0 +1,148 @@
|
||||
vim.g.mapleader = " "
|
||||
|
||||
local function smart_quit()
|
||||
local bufnr = vim.api.nvim_get_current_buf()
|
||||
local modified = vim.api.nvim_buf_get_option(bufnr, "modified")
|
||||
if modified then
|
||||
vim.ui.input({
|
||||
prompt = "You have unsaved changes. Quit anyway? (y/n) ",
|
||||
}, function(input)
|
||||
if input == "y" then
|
||||
vim.cmd "q!"
|
||||
end
|
||||
end)
|
||||
else
|
||||
vim.cmd "q!"
|
||||
end
|
||||
end
|
||||
|
||||
local function find_project_files()
|
||||
local _, builtin = pcall(require, "telescope.builtin")
|
||||
local ok = pcall(builtin.git_files)
|
||||
|
||||
if not ok then
|
||||
builtin.find_files()
|
||||
end
|
||||
end
|
||||
|
||||
local wk = require("which-key")
|
||||
|
||||
wk.setup({})
|
||||
|
||||
wk.register({
|
||||
["<leader>"] = {
|
||||
|
||||
[";"] = { "<cmd>Alpha<CR>", "Dashboard" },
|
||||
["w"] = { "<cmd>w!<CR>", "Save" },
|
||||
["q"] = { "<cmd>smart_quit()<CR>", "Quit" },
|
||||
["/"] = { "<Plug>(comment_toggle_linewise_current)", "Comment toggle current line" },
|
||||
["c"] = { "<cmd>BufferKill<CR>", "Close Buffer" },
|
||||
["f"] = { find_project_files, "Find File" },
|
||||
["h"] = { "<cmd>nohlsearch<CR>", "No Highlight" },
|
||||
["t"] = { "<cmd>TodoTelescope keywords=TODO,FIX<CR>", "Find TODO,FIX" },
|
||||
b = {
|
||||
name = "Buffers",
|
||||
j = { "<cmd>BufferLinePick<cr>", "Jump" },
|
||||
f = { "<cmd>Telescope buffers<cr>", "Find" },
|
||||
b = { "<cmd>BufferLineCyclePrev<cr>", "Previous" },
|
||||
n = { "<cmd>BufferLineCycleNext<cr>", "Next" },
|
||||
-- w = { "<cmd>BufferWipeout<cr>", "Wipeout" }, -- TODO: implement this for bufferline
|
||||
e = {
|
||||
"<cmd>BufferLinePickClose<cr>",
|
||||
"Pick which buffer to close",
|
||||
},
|
||||
h = { "<cmd>BufferLineCloseLeft<cr>", "Close all to the left" },
|
||||
l = {
|
||||
"<cmd>BufferLineCloseRight<cr>",
|
||||
"Close all to the right",
|
||||
},
|
||||
D = {
|
||||
"<cmd>BufferLineSortByDirectory<cr>",
|
||||
"Sort by directory",
|
||||
},
|
||||
L = {
|
||||
"<cmd>BufferLineSortByExtension<cr>",
|
||||
"Sort by language",
|
||||
},
|
||||
},
|
||||
-- " Available Debug Adapters:
|
||||
-- " https://microsoft.github.io/debug-adapter-protocol/implementors/adapters/
|
||||
-- " Adapter configuration and installation instructions:
|
||||
-- " https://github.com/mfussenegger/nvim-dap/wiki/Debug-Adapter-installation
|
||||
-- " Debug Adapter protocol:
|
||||
-- " https://microsoft.github.io/debug-adapter-protocol/
|
||||
-- " Debugging
|
||||
g = {
|
||||
name = "Git",
|
||||
g = { Lazygit_toggle, "Lazygit" },
|
||||
j = { "<cmd>lua require 'gitsigns'.next_hunk({navigation_message = false})<cr>", "Next Hunk" },
|
||||
k = { "<cmd>lua require 'gitsigns'.prev_hunk({navigation_message = false})<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" },
|
||||
C = {
|
||||
"<cmd>Telescope git_bcommits<cr>",
|
||||
"Checkout commit(for current file)",
|
||||
},
|
||||
d = {
|
||||
"<cmd>Gitsigns diffthis HEAD<cr>",
|
||||
"Git Diff",
|
||||
},
|
||||
},
|
||||
l = {
|
||||
name = "LSP",
|
||||
a = { "<cmd>lua vim.lsp.buf.code_action()<cr>", "Code Action" },
|
||||
d = { "<cmd>Telescope diagnostics bufnr=0 theme=get_ivy<cr>", "Buffer Diagnostics" },
|
||||
w = { "<cmd>Telescope diagnostics<cr>", "Diagnostics" },
|
||||
-- f = { require("lvim.lsp.utils").format, "Format" },
|
||||
i = { "<cmd>LspInfo<cr>", "Info" },
|
||||
I = { "<cmd>Mason<cr>", "Mason Info" },
|
||||
j = {
|
||||
vim.diagnostic.goto_next,
|
||||
"Next Diagnostic",
|
||||
},
|
||||
k = {
|
||||
vim.diagnostic.goto_prev,
|
||||
"Prev Diagnostic",
|
||||
},
|
||||
l = { vim.lsp.codelens.run, "CodeLens Action" },
|
||||
q = { vim.diagnostic.setloclist, "Quickfix" },
|
||||
r = { vim.lsp.buf.rename, "Rename" },
|
||||
s = { "<cmd>Telescope lsp_document_symbols<cr>", "Document Symbols" },
|
||||
S = {
|
||||
"<cmd>Telescope lsp_dynamic_workspace_symbols<cr>",
|
||||
"Workspace Symbols",
|
||||
},
|
||||
e = { "<cmd>Telescope quickfix<cr>", "Telescope Quickfix" },
|
||||
},
|
||||
|
||||
|
||||
a = { "<cmd>lua require('telescope.builtin').lsp_code_actions()<cr>", "Code Actions" },
|
||||
d = { "<cmd>lua require('telescope.builtin').lsp_document_diagnostics()<cr>", "LSP Diagnostics" },
|
||||
k = { "<cmd>lua vim.lsp.buf.signature_help()<cr>", "Signature Help" },
|
||||
P = { "<cmd>lua require'telescope'.extensions.projects.projects{}<cr>", "Signature Help" },
|
||||
}
|
||||
})
|
||||
|
||||
wk.register(
|
||||
{
|
||||
["/"] = { "<Plug>(comment_toggle_linewise_visual)", "Comment toggle linewise (visual)" },
|
||||
},
|
||||
{
|
||||
mode = "v", -- VISUAL mode
|
||||
prefix = "<leader>",
|
||||
buffer = nil, -- Global mappings. Specify a buffer number for buffer local mappings
|
||||
silent = true, -- use `silent` when creating keymaps
|
||||
noremap = true, -- use `noremap` when creating keymaps
|
||||
nowait = true, -- use `nowait` when creating keymaps
|
||||
}
|
||||
)
|
||||
Reference in New Issue
Block a user