dotfiles/nvim/lua/keybindings.lua

116 lines
3.8 KiB
Lua
Raw Normal View History

2024-01-28 10:41:46 +00:00
require("commander").setup({
2024-01-28 17:41:33 +00:00
prompt_title = "Help | Keybindings",
components = {
"DESC",
"KEYS",
},
2024-01-28 10:41:46 +00:00
integration = {
telescope = {
enable = true,
2024-01-28 17:41:33 +00:00
theme = require("telescope.themes").commander,
2024-01-28 10:41:46 +00:00
},
},
})
local lspconfig = require("lspconfig")
-- Use LspAttach autocommand to only map the following keys
-- after the language server attaches to the current buffer
local lsp_antach_done = false
vim.api.nvim_create_autocmd("LspAttach", {
group = vim.api.nvim_create_augroup("UserLspConfig", {}),
callback = function(ev)
-- Buffer local mappings.
-- See `:help vim.lsp.*` for documentation on any of the below functions
local opts = { buffer = ev.buf }
require("commander").add({
{
desc = "LSP Quickfix",
cmd = function()
vim.lsp.buf.code_action({
filter = function(a)
return a.kind ~= "quickfix" or a.isPreferred
end,
apply = true,
})
end,
keys = { "n", "qf", opts },
},
{ desc = "LSP Declaration", cmd = vim.lsp.buf.declaration, keys = { "n", "gD", opts } },
{ desc = "LSP Definition", cmd = vim.lsp.buf.definition, keys = { "n", "gd", opts } },
{ desc = "LSP Hover", cmd = vim.lsp.buf.hover, keys = { "n", "K", opts } },
{ desc = "LSP Rename", cmd = vim.lsp.buf.rename, keys = { "n", "rn", opts } },
{ desc = "LSP Implementation", cmd = vim.lsp.buf.implementation, keys = { "n", "gi", opts } },
{ desc = "LSP Signature Help", cmd = vim.lsp.buf.signature_help, keys = { "n", "<C-k>", opts } },
2024-04-25 09:12:44 +00:00
{ desc = "LSP Code Action", cmd = vim.lsp.buf.code_action, keys = { "n", "<leader>ca", opts } },
2024-01-28 10:41:46 +00:00
{
desc = "LSP Format",
cmd = function()
vim.lsp.buf.format({ async = true })
end,
2024-04-25 09:12:44 +00:00
keys = { "n", "<leader>f", opts },
2024-01-28 10:41:46 +00:00
},
{
desc = "LSP Diagnostics",
2024-01-28 17:41:33 +00:00
cmd = function()
require("trouble").toggle("document_diagnostics")
end,
2024-04-25 09:12:44 +00:00
keys = { "n", "<leader>d" },
2024-01-28 17:41:33 +00:00
},
{
desc = "LSP Diagnostics whole workspace",
cmd = function()
require("trouble").toggle("workspace_diagnostics")
end,
keys = { "n", "<space>dw" },
2024-01-28 10:41:46 +00:00
},
2024-01-28 17:41:33 +00:00
{ desc = "LSP References", cmd = "<CMD>Telescope lsp_references<CR>", keys = { "n", "<leader>gr" } },
2024-01-28 10:41:46 +00:00
{ desc = "LSP Definitions", cmd = "<CMD>Telescope lsp_definitions<CR>", keys = { "n", "<leader>fcde" } },
{
desc = "LSP Document Symbols",
cmd = "<CMD>Telescope lsp_document_symbols<CR>",
keys = { "n", "<leader>fcds" },
},
{
desc = "LSP Workspace Symbols",
cmd = "<CMD>Telescope lsp_workspace_symbols<CR>",
keys = { "n", "<leader>fcws" },
},
}, { show = not lsp_attach_done })
lsp_attach_done = true
end,
})
require("commander").add({
{
desc = "Open Help",
cmd = require("commander").show,
keys = { "n", "<Leader>h" },
},
{
desc = "Search for files in git",
cmd = "<CMD>Telescope git_files<CR>",
keys = { "n", "<c-p>" },
},
{ desc = "Search for files", cmd = "<CMD>Telescope find_files<CR>", keys = { "n", "<leader>ff" } },
{ desc = "Search for string", cmd = "<CMD>Telescope live_grep<CR>", keys = { "n", "<leader>fg" } },
{ desc = "Git Commits", cmd = "<CMD>Telescope git_commits<CR>", keys = { "n", "<leader>fgc" } },
{ desc = "Git Branches", cmd = "<CMD>Telescope git_branches<CR>", keys = { "n", "<leader>fgb" } },
{ desc = "Git Status", cmd = "<CMD>Telescope git_status<CR>", keys = { "n", "<leader>fgs" } },
{ desc = "Terraform Doc", cmd = "<CMD>Telescope terraform_doc<CR>", keys = { "n", "<leader>ftf" } },
{ desc = "Terraform Modules", cmd = "<CMD>Telescope terraform_doc modules<CR>", keys = { "n", "<leader>ftm" } },
{
desc = "Terraform AWS",
cmd = "<CMD>Telescope terraform_doc full_name=hashicorp/aws<CR>",
keys = { "n", "<leader>ftfa" },
},
{
desc = "Terraform Kubernetes",
cmd = "<CMD>Telescope terraform_doc full_name=hashicorp/kubernetes<CR>",
keys = { "n", "<leader>ftfk" },
},
})