neovim: change keybinds wo whichkey
6c8fe5a751365a3f845a24546d1451ecab98da4d
Oliver Krylow <o.krylow@isp-insoft.de> ·
unsigned
- Parent 1: 69c171d3fbcf
bugabingas dorkfiles
6c8fe5a751365a3f845a24546d1451ecab98da4d
Oliver Krylow <o.krylow@isp-insoft.de> ·
unsigned
+237 / −116 text lines
+4 / −0 text lines
+2 / −10 text lines
vim.opt.timeoutlen = 350 -- Highlight the cursor line in the current buffer autocommand({ show_cursor_line_in_active_window = { [[WinLeave * lua vim.opt.cursorline = false]], [[WinEnter * lua vim.opt.cursorline = true]], [[InsertEnter * lua vim.opt.cursorline = false]], [[InsertLeave * lua vim.opt.cursorline = true]], }, })+70 / −43 text lines
-- But unfortunataly, by collecting them here, they are placed "far" from their logical place, i.e. the plugins configuration. -- Delegator over nvim_set_keymap, that sets some default options -- TODO expose this function as module local map = function(mode, left_hand_side, right_hand_side, options) local default_options = { noremap = true, unique = true } if options then default_options = vim.tbl_extend("force", default_options, options) end vim.api.nvim_set_keymap(mode, left_hand_side, right_hand_side, default_options) end map("n", "<LEADER><F9>", [[<CMD>tabnew $MYVIMRC<CR>]]) cheatsheet("LEADER + F9 => Open nvim configuration in a new tab!") map("n", "<LEADER><F10>", [[<CMD>PluginsSync<CR>]]) cheatsheet("LEADER + F10 => Sync nvim plugins configuration!") map("n", "<LEADER>b", [[<CMD>Telescope buffers<CR>]]) cheatsheet("LEADER + b => Select a buffer") map("n", "<LEADER>f", [[<CMD>Telescope file_browser<CR>]]) cheatsheet("LEADER + f => Select a file") map("n", "<LEADER>e", [[<CMD>NvimTreeToggle<CR>]]) cheatsheet("LEADER + e => Toggle file explorer") map("n", "<LEADER>t", [[<CMD>TroubleToggle<CR>]]) cheatsheet("LEADER + t => Toggle the Trouble window.") cheatsheet("") local keys = require("which-key") cheatsheet("") cheatsheet("ALT + j => Move line(s) down") cheatsheet("ALT + k => Move line(s) up") map("n", "<A-j>", [[<CMD>move .+1<CR>==]]) map("n", "<A-k>", [[<CMD>move .-2<CR>==]]) map("i", "<A-j>", [[<ESC><CMD>move .+1<CR>==gi]]) map("i", "<A-k>", [[<ESC><CMD>move .-2<CR>==gi]]) map("x", "<A-j>", [[<ESC><CMD>'<,'>move'>+1<CR>gv=gv]]) map("x", "<A-k>", [[<ESC><CMD>'<,'>move'<-2<CR>gv=gv]]) -- bundle all mappings under LEADER here keys.register({ ["<F9>"] = { [[<CMD>tabnew $MYVIMRC<CR>]], "Open Nvim Configuration" }, ["<F10>"] = { [[<CMD>PluginsSync<CR>]], "Sync Plugins" }, ["<F11>"] = { [[<CMD>PluginsCompile<CR>]], "Compile Plugins" }, f = { name = "file operations", f = { [[<CMD>Telescope find_files<CR>]], "Find File" }, b = { [[<CMD>Telescope buffers<CR>]], "Open a Buffer" }, r = { [[<CMD>Telescope oldfiles<CR>]], "Open Recent File" }, e = { [[<CMD>NvimTreeToggle<CR>]], "Toggle File Explorer" }, }, g = { name = "goto navigation", t = { [[<CMD>TroubleToggle<CR>]], "Toggle Trouble Window" }, x = { "<CMD>lua require'spawn'('" .. opener_program .. "',{vim.fn.expand('<cfile>')})<CR>", "Open Url Under Cursor", }, }, a = { name = "code operations", o = { [[<CMD>SymbolsOutline<CR>]], "Toggle Outline" }, }, }, { prefix = "<LEADER>", }) cheatsheet("") cheatsheet("ALT + j => Move line(s) down") cheatsheet("ALT + k => Move line(s) up") keys.register({ ["<A-j>"] = { [[<CMD>move .+1<CR>==]], "Move Current Line(s) Up" }, ["<A-k>"] = { [[<CMD>move .-2<CR>==]], "Move Current Line(s) Down" }, }) keys.register({ ["<A-j>"] = { [[<ESC><CMD>move .+1<CR>==gi]], "Move Current Line(s) Up" }, ["<A-k>"] = { [[<ESC><CMD>move .-2<CR>==gi]], "Move Current Line(s) Down" }, }, { mode = "i", }) keys.register({ ["<A-j>"] = { [[<ESC><CMD>'<,'>move'>+1<CR>gv=gv]], "Move Current Line(s) Up" }, ["<A-k>"] = { [[<ESC><CMD>'<,'>move'<-2<CR>gv=gv]], "Move Current Line(s) Down" }, }, { mode = "x", }) -- Not sure why some bindings have to be escaped with which-key but not when using nvim api directly... local escape = function(string) return vim.api.nvim_replace_termcodes(string, true, true, true) end keys.register({ ["<ESC>"] = { escape([[<C-\><C-n>]]), "Escape terminal mode" }, ["<C-w>"] = { [[<ESC><C-w>]], "Delete Word" }, ["<A-1>"] = { [[<CMD>lua require'FTerm'.toggle()<CR>]], "Toggle the Terminal" }, }, { mode = "t", }) cheatsheet("") cheatsheet("ALT + 1 => Toggle the Terminal") cheatsheet("") keys.register({ ["<A-1>"] = { [[<CMD>lua require'FTerm'.toggle()<CR>]], "Toggle the Terminal" }, })+106 / −38 text lines
require"lspkind".init() local lspkind = require("lspkind") -- TODO define snippets in some other file... local snippets = require("snippets") cmp.setup({ snippet = { expand = function(arguments) --FIXME no clue if this actually does something.. snippets.lookup_snippet(vim.o.filetype, arguments.body) end, }, completion = { autocomplete = false, }, confirmation = { default_behaviour = types.cmp.ConfirmBehavior.Insert }, mapping = { ["<C-d>"] = cmp.mapping.scroll_docs(-4), ["<C-f>"] = cmp.mapping.scroll_docs(4), ["<C-n>"] = cmp.mapping.complete(), ["<C-j>"] = cmp.mapping.select_next_item(), ["<C-k>"] = cmp.mapping.select_prev_item(), ["<C-e>"] = cmp.mapping.abort(), ["<C-y>"] = cmp.mapping.confirm({ select = true }), }, formatting = { format = function(_, vim_item) vim_item.kind = lspkind.presets.default[vim_item.kind] return vim_item end, }, sources = { { name = "nvim_lsp" }, { name = "nvim_lua" }, -- this source only makes sense in neovim lua files... { name = "buffer" }, { name = "path" }, { name = "emoji" }, { name = "calc" }, }, }) -- Configure diagnostics to only show up on file save vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, { signs = true, underline = false, virtual_text = false, -- FIXME these options are not merged yet --[[ show_diagnostic_autocmds = { "BufWritePost" }, diagnostic_delay = 500, ]] -- TODO -- * clear diagnostics on enter i }) local keys = require("which-key") keys.register({ g = { name = "Goto Navigation", ["D"] = { [[<CMD>lua vim.lsp.buf.declaration()<CR>]], "Goto Declaration" }, ["d"] = { [[<CMD>lua vim.lsp.buf.definition()<CR>]], "Goto Definition" }, ["i"] = { [[<CMD>lua vim.lsp.buf.implementation()<CR>]], "Goto Implementation" }, ["t"] = { [[<CMD>lua vim.lsp.buf.type_definition()<CR>]], "Goto Type Definition" }, ["w"] = { [[<CMD>lua vim.lsp.buf.document_symbol()<CR>]], "Goto Document Symbol" }, ["W"] = { [[<CMD>lua vim.lsp.buf.workspace_symbol()<CR>]], "Goto Workspace Symbol" }, ["n"] = { [[<CMD>lua vim.lsp.diagnostic.goto_next()<CR>]], "Goto Next Diagnostic" }, ["N"] = { [[<CMD>lua vim.lsp.diagnostic.goto_prev()<CR>]], "Goto Previous Diagnostic" }, }, a = { name = "Code Operations", ["h"] = { [[<CMD>lua vim.lsp.buf.hover()<CR>]], "Show Hover" }, ["d"] = { [[<CMD>lua vim.lsp.diagnostic.show_line_diagnostics()<CR>]], "Show Diagnostics on Current Line", }, ["s"] = { [[<CMD>lua vim.lsp.buf.signature_help()<CR>]], "Show Signature Help" }, ["f"] = { [[<CMD>lua vim.lsp.buf.code_action()<CR>]], "Code Actions..." }, ["r"] = { [[<CMD>lua vim.lsp.buf.rename()<CR>]], "Rename" }, ["="] = { [[<CMD>lua vim.lsp.buf.formatting()<CR>]], "Format" }, -- hook lsp into vim autocomplete in insert mode vim.api.nvim_buf_set_option(buffer_number, "omnifunc", "v:lua.vim.lsp.omnifunc") local map = function(type, key, value) vim.api.nvim_buf_set_keymap(buffer_number, type, key, value, { noremap = true, silent = true }) end map("n", "<LEADER>gD", "<CMD>lua vim.lsp.buf.declaration()<CR>") map("n", "<LEADER>gd", "<CMD>lua vim.lsp.buf.definition()<CR>") map("n", "<LEADER>gr", "<CMD>lua vim.lsp.buf.references()<CR>") map("n", "<LEADER>gi", "<CMD>lua vim.lsp.buf.implementation()<CR>") map("n", "<LEADER>gt", "<CMD>lua vim.lsp.buf.type_definition()<CR>") map("n", "<LEADER>gw", "<CMD>lua vim.lsp.buf.document_symbol()<CR>") map("n", "<LEADER>gW", "<CMD>lua vim.lsp.buf.workspace_symbol()<CR>") map("n", "<LEADER>ah", "<CMD>lua vim.lsp.buf.hover()<CR>") map("n", "<LEADER>as", "<CMD>lua vim.lsp.buf.signature_help()<CR>") map("n", "<LEADER>af", "<CMD>lua vim.lsp.buf.code_action()<CR>") map("n", "<LEADER>ar", "<CMD>lua vim.lsp.buf.rename()<CR>") map("n", "<LEADER>a=", "<CMD>lua vim.lsp.buf.formatting()<CR>") map("n", "<LEADER>ai", "<CMD>lua vim.lsp.buf.incoming_calls()<CR>") map("n", "<LEADER>ao", "<CMD>lua vim.lsp.buf.outgoing_calls()<CR>") map("n", "<LEADER>n", "<CMD>lua vim.lsp.diagnostic.goto_next()<CR>") map("n", "<LEADER>N", "<CMD>lua vim.lsp.diagnostic.goto_prev()<CR>") map("n", "<LEADER><LEADER>", "<CMD>lua vim.lsp.diagnostic.show_line_diagnostics()<CR>") ["R"] = { [[<CMD>lua vim.lsp.buf.references()<CR>]], "Show References" }, ["i"] = { [[<CMD>lua vim.lsp.buf.incoming_calls()<CR>]], "Show Incoming Calls" }, ["o"] = { [[<CMD>lua vim.lsp.buf.outgoing_calls()<CR>]], "Show Outgoind Calls" }, }, }, { prefix = "<LEADER>", buffer = buffer_number, }) local sumneko_home = "~/Workspace/sua-language-server" local sumneko_home = "~/Workspace/lua-language-server" --TODO: How to switch this configuration based upon if we are editing neovim configuration or just any Lua file/project? capabilites = capabilities, capabilites = capabilities, capabilites = capabilities, -- lsp.zls.setup({ on_attach = integrate_into_neovim }) lsp.clangd.setup({ on_attach = integrate_into_neovim }) capabilites = capabilities, lsp.dotls.setup({ on_attach = integrate_into_neovim }) capabilites = capabilities,+54 / −24 text lines
open_fn = require("packer.util").float, require("which-key").setup({}) local key_labels = { ["<space>"] = "SPACE", ["<cr>"] = "ENTER", ["<tab>"] = "TAB", ["."] = "DOT" } for f_key_number = 1, 12 do key_labels["<F" .. f_key_number .. ">"] = "F" .. f_key_number end require("which-key").setup({ marks = true, registers = true, spelling = { enabled = true, suggestions = 5 }, key_labels = key_labels, window = { border = "single" }, }) "nvim-lua/completion-nvim", use("beauwilliams/focus.nvim")+1 / −1 text lines