nixos-configuration/modules/editors/nixvim/keymaps.nix
2025-03-21 02:00:29 +01:00

75 lines
2.2 KiB
Nix
Executable file

{...}: {
programs.nixvim.globals.mapleader = " ";
programs.nixvim.globals.maplocalleader = ",";
programs.nixvim.keymaps = [
{
key = "gl";
action = "<cmd>lua vim.diagnostic.open_float()<cr>";
}
{
key = "<leader>u";
action = "<cmd>UndotreeToggle<cr>";
}
{
key = "<leader>f";
action = "<cmd>Telescope fd<cr>";
}
{
key = "<leader>g";
action = "<cmd>Telescope live_grep<cr>";
}
{
key = "<leader>D";
action = "<cmd>Telescope diagnostics<cr>";
}
{
key = "<leader>b";
action = "<cmd>Telescope buffers<cr>";
}
{
key = "<leader>s";
action = "<cmd>Telescope lsp_document_symbols<cr>";
}
{
key = "<leader>w";
action = "<C-W>";
}
{
# Unbind F1
key = "<F1>";
action = "";
}
];
programs.nixvim.autoCmd = [
{
desc = "LSP Actions";
event = "LspAttach";
callback = {
__raw = ''
function(event)
local opts = { buffer = event.buf }
-- these will be buffer-local keybindings
-- because they only work if you have an active language server
vim.keymap.set('n', 'K', '<cmd>lua vim.lsp.buf.hover()<cr>', opts)
vim.keymap.set('n', 'gd', '<cmd>Telescope lsp_definitions<cr>', opts)
vim.keymap.set('n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<cr>', opts)
vim.keymap.set('n', 'gi', '<cmd>Telescope lsp_implementations<cr>', opts)
vim.keymap.set('n', 'go', '<cmd>Telescope lsp_type_definitions<cr>', opts)
vim.keymap.set('n', 'gr', '<cmd>Telescope lsp_references<cr>', opts)
vim.keymap.set('n', 'gs', '<cmd>lua vim.lsp.buf.signature_help()<cr>', opts)
vim.keymap.set('n', '<leader>r', '<cmd>lua vim.lsp.buf.rename()<cr>', opts)
vim.keymap.set({ 'n', 'x' }, '<F3>', '<cmd>lua vim.lsp.buf.format({async = true})<cr>', opts)
-- vim.keymap.set('n', '<leader>a', '<cmd>lua vim.lsp.buf.code_action()<cr>', opts)
vim.keymap.set("n", "<leader>a", require("actions-preview").code_actions, opts)
vim.keymap.set("n", "gh", "<cmd>ClangdSwitchSourceHeader<cr>", opts)
end
'';
};
}
];
}