From daa9394fd5db3aa34b0d797a18f50f19d2f3a89c Mon Sep 17 00:00:00 2001 From: Alexander Gehrke Date: Fri, 8 Sep 2023 11:14:20 +0200 Subject: [PATCH] Add keybindings and binding descriptions --- lazy-lock.json | 1 + lua/plugins/telescope.lua | 95 ++++++++++++++++++++------------------- plugin/on-attach.lua | 47 +++++++++---------- 3 files changed, 73 insertions(+), 70 deletions(-) diff --git a/lazy-lock.json b/lazy-lock.json index 0bcb98c..9bec4f4 100644 --- a/lazy-lock.json +++ b/lazy-lock.json @@ -14,6 +14,7 @@ "gitsigns.nvim": { "branch": "main", "commit": "d8590288417fef2430f85bc8b312fae8b1cf2c40" }, "gitv": { "branch": "master", "commit": "a73599c34202709eaa7da78f4fe32b97c6ef83f8" }, "hledger-vim": { "branch": "master", "commit": "165eb483a10fd610bd9cad5d5246e457bf5fe285" }, + "hover.nvim": { "branch": "main", "commit": "c366d1b0f9d6612d25681d3fea0f9ea46fa54f4d" }, "indent-blankline.nvim": { "branch": "master", "commit": "9637670896b68805430e2f72cf5d16be5b97a22a" }, "lazy.nvim": { "branch": "main", "commit": "2a9354c7d2368d78cbd5575a51a2af5bd8a6ad01" }, "lsp-colors.nvim": { "branch": "main", "commit": "2bbe7541747fd339bdd8923fc45631a09bb4f1e5" }, diff --git a/lua/plugins/telescope.lua b/lua/plugins/telescope.lua index 9d12b2b..27acbc9 100644 --- a/lua/plugins/telescope.lua +++ b/lua/plugins/telescope.lua @@ -1,53 +1,54 @@ ---Plug 'nvim-telescope/telescope.nvim' - ---Plug 'nvim-telescope/telescope-fzf-native.nvim', { 'do': 'cmake -S. -Bbuild -DCMAKE_BUILD_TYPE=Release && cmake --build build --config Release && cmake --install build --prefix build' } ---Plug 'gbrlsnchs/telescope-lsp-handlers.nvim' ---Plug 'nvim-telescope/telescope-ui-select.nvim' return { - "nvim-telescope/telescope.nvim", - dependencies = { - {'nvim-telescope/telescope-fzf-native.nvim', - build = 'cmake -S. -Bbuild -DCMAKE_BUILD_TYPE=Release && cmake --build build --config Release && cmake --install build --prefix build', - }, - 'gbrlsnchs/telescope-lsp-handlers.nvim', ---Plug { 'do': 'cmake -S. -Bbuild -DCMAKE_BUILD_TYPE=Release && cmake --build build --config Release && cmake --install build --prefix build' } + "nvim-telescope/telescope.nvim", + dependencies = { + { + 'nvim-telescope/telescope-fzf-native.nvim', + build = + 'cmake -S. -Bbuild -DCMAKE_BUILD_TYPE=Release && cmake --build build --config Release && cmake --install build --prefix build', }, - cmd = "Telescope", - version = false, - keys = { - {',ff', require("telescope.builtin").fd, desc = "Find files"}, - {',fg', require("telescope.builtin").git_files, desc = "Find files (git)"}, - {',gs', require("telescope.builtin").git_status, desc = "Git status"}, - {',s', require("telescope.builtin").lsp_dynamic_workspace_symbols, desc = "Symbols"}, - {'g/', require("telescope.builtin").live_grep, desc = "Live grep"}, - {'', require("telescope.builtin").current_buffer_fuzzy_find, desc = "Fuzzy find"}, - {'*', require("telescope.builtin").grep_string, desc = "Find at cursor"}, - {'gb', require("telescope.builtin").buffers}, - { ":", require("telescope.builtin").command_history, desc = "Command History" }, - { ";", require("telescope.builtin").commands, desc = "Commands" }, + 'gbrlsnchs/telescope-lsp-handlers.nvim', + }, + cmd = "Telescope", + version = false, + keys = function() + local builtin = require("telescope.builtin") + local utils = require("telescope.utils") + return { + { ',,', function() builtin.fd { cwd = utils.buffer_dir() } end, desc = "Find files in current file's dir" }, + { ',ff', builtin.fd, desc = "Find files" }, + { ',fg', builtin.git_files, desc = "Find files (git)" }, + { ',gs', builtin.git_status, desc = "Git status" }, + { ',s', builtin.lsp_dynamic_workspace_symbols, desc = "Symbols" }, + { 'g/', builtin.live_grep, desc = "Live grep" }, + { '', builtin.current_buffer_fuzzy_find, desc = "Fuzzy find" }, + { '*', builtin.grep_string, desc = "Find at cursor" }, + { 'gb', builtin.buffers, desc = "Switch buffer" }, + { ":", builtin.command_history, desc = "Command History" }, + { ";", builtin.commands, desc = "Commands" }, + } + end, + opts = { + defaults = { + prompt_prefix = " ", + selection_caret = " ", }, - opts = { - defaults = { - prompt_prefix = " ", - selection_caret = " ", + extensions = { + fzf = { + fuzzy = true, -- false will only do exact matching + override_generic_sorter = true, -- override the generic sorter + override_file_sorter = true, -- override the file sorter + case_mode = "smart_case", -- or "ignore_case" or "respect_case" + -- the default case_mode is "smart_case" }, - extensions = { - fzf = { - fuzzy = true, -- false will only do exact matching - override_generic_sorter = true, -- override the generic sorter - override_file_sorter = true, -- override the file sorter - case_mode = "smart_case", -- or "ignore_case" or "respect_case" - -- the default case_mode is "smart_case" - }, - ["ui-select"] = { - require("telescope.themes").get_dropdown { } - }, + ["ui-select"] = { + require("telescope.themes").get_dropdown {} }, }, - config = function(_, opts) - local telescope = require('telescope') - telescope.setup(opts) - telescope.load_extension('fzf') - telescope.load_extension('ui-select') - end, - } + }, + config = function(_, opts) + local telescope = require('telescope') + telescope.setup(opts) + telescope.load_extension('fzf') + telescope.load_extension('ui-select') + end, +} diff --git a/plugin/on-attach.lua b/plugin/on-attach.lua index 4a0fb5e..9dcf82c 100644 --- a/plugin/on-attach.lua +++ b/plugin/on-attach.lua @@ -8,34 +8,35 @@ local on_attach = function(args) -- Mappings. local opts = { silent = true, buffer = bufnr } local loud = { buffer = bufnr } + local desc = function(text) return { silent = true, buffer = bufnr, desc = text} end local map = vim.keymap.set -- See `:help vim.lsp.*` for documentation on any of the below functions map("n", "dr", function() require("dap").repl.toggle() end, { silent = true }) - map('n', 'gD', vim.lsp.buf.declaration, opts) - map('n', 'gd', vim.lsp.buf.definition, opts) - map('n', 'gi', vim.lsp.buf.implementation, opts) - map('n', '', vim.lsp.buf.signature_help, opts) - map('n', 'D', vim.lsp.buf.type_definition, opts) - map('n', 'rn', vim.lsp.buf.rename, opts) - map('n', '', vim.lsp.buf.code_action, loud) - map('n', '', vim.lsp.codelens.run, loud) - map('n', 'gr', vim.lsp.buf.references, opts) - map('n', '', vim.diagnostic.open_float, opts) - map('n', '[d', vim.diagnostic.goto_prev, opts) - map('n', ']d', vim.diagnostic.goto_next, opts) - map('n', '', vim.diagnostic.setloclist, opts) - map("n", "f", function() vim.lsp.buf.format { async = true } end, opts) - map("n", "dc", function() require("dap").continue() end, opts) - map("n", "dK", function() require("dap.ui.widgets").hover() end, opts) - map("n", "dt", function() require("dap").toggle_breakpoint() end, opts) - map("n", "dso", function() require("dap").step_over() end, opts) - map("n", "dsi", function() require("dap").step_into() end, opts) - map("n", "dl", function() require("dap").run_last() end, opts) + map('n', 'gD', vim.lsp.buf.declaration, desc("Go to declaration")) + map('n', 'gd', vim.lsp.buf.definition, desc("Go to definition")) + map('n', 'gi', vim.lsp.buf.implementation, desc("Go to implementation")) + map('n', '', vim.lsp.buf.signature_help, desc("Show signature help")) + map('n', 'D', vim.lsp.buf.type_definition, desc("Go to type definition")) + map('n', 'rn', vim.lsp.buf.rename, desc("Rename")) + map('n', '', vim.lsp.buf.code_action, desc("Code action")) + map('n', '', vim.lsp.codelens.run, desc("Run code lens")) + map('n', 'gr', vim.lsp.buf.references, desc("Go to references")) + map('n', '', vim.diagnostic.open_float, desc("Open diagnostics")) + map('n', '[d', vim.diagnostic.goto_prev, desc("Go to previous diagnostic")) + map('n', '[d', vim.diagnostic.goto_prev, desc("Go to next diagnostic")) + map('n', '', vim.diagnostic.setloclist, desc("Add buffer diagnostics to location list")) + map("n", "f", function() vim.lsp.buf.format { async = true } end, desc("Format buffer")) + map("n", "dc", function() require("dap").continue() end, desc("Debug: Continue")) + map("n", "dK", function() require("dap.ui.widgets").hover() end, desc("Debug: Hover")) + map("n", "dt", function() require("dap").toggle_breakpoint() end, desc("Debug: Toggle breakpoint")) + map("n", "dso", function() require("dap").step_over() end, desc("Debug: Step over")) + map("n", "dsi", function() require("dap").step_into() end, desc("Debug: Step into")) + map("n", "dl", function() require("dap").run_last() end, desc("Debug: Run last")) - map("n", "aa", vim.diagnostic.setqflist, opts) - map("n", "aw", function() vim.diagnostic.setqflist({ severity = "W" }) end, opts) - map("n", "ae", function() vim.diagnostic.setqflist({ severity = "E" }) end, opts) + map("n", "aa", vim.diagnostic.setqflist, desc("Add all diagnostics to quickfix list")) + map("n", "aw", function() vim.diagnostic.setqflist({ severity = "W" }) end, desc("Add all warnings to quickfix list")) + map("n", "ae", function() vim.diagnostic.setqflist({ severity = "E" }) end, desc("Add all errors to quickfix list")) vim.cmd [[autocmd CursorHoldI * silent! lua vim.lsp.buf.signature_help()]] vim.cmd [[autocmd CursorHold * lua vim.diagnostic.open_float({max_width = 100, focusable = false})]]