From e82602334e8c2ab4cdea7008fb40d59363bbecf4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sascha=20L=C3=BCdecke?= Date: Wed, 9 Oct 2024 07:47:31 +0200 Subject: [PATCH] Keybindings and smaller ui related improvements Options: - lualine shows path of files - added breadcrumbs to programming buffers as winbar Plugins: - added mrcjkb/rustaceanvim for improved rust support - added lewis6991/gitsigns.nvim to show changes in files - dropped lspkind, it had no visible effect and could not easily be fixed - added j-hui/fidget.nvim to make $/progress messages (e.g. from lsp) visible Keybindings: - dropped unused and commented out keybindings - fr to resume last fzf search - 0, 1, 2, 3 to mimic emacs .... window keys - to clear last search - added desc field to many keybindings in lsp --- lua/keybindings.lua | 18 +++++---- lua/lsp.lua | 45 ++++++++++------------ lua/plugins.lua | 93 +++++++++++++++++++++++++++++++++++---------- 3 files changed, 105 insertions(+), 51 deletions(-) diff --git a/lua/keybindings.lua b/lua/keybindings.lua index f0d3ed1..f16e0c8 100644 --- a/lua/keybindings.lua +++ b/lua/keybindings.lua @@ -1,17 +1,18 @@ -- Setup fzf-lua keybindings and some other searches local fzf = require('fzf-lua') -vim.keymap.set('n', 'ff', fzf.files, { desc = "Find file" }) -vim.keymap.set('n', 'fs', fzf.blines, { desc = "Search buffer" }) -vim.keymap.set('n', 'fg', fzf.live_grep, { desc = "Grep" }) +vim.keymap.set('n', 'b', fzf.buffers, { desc = "Buffers" }) vim.keymap.set('n', 'fG', fzf.grep_cword, { desc = "Grep word under cursor" }) vim.keymap.set('n', 'fc', fzf.commands, { desc = "Commands" }) +vim.keymap.set('n', 'ff', fzf.files, { desc = "Find file" }) +vim.keymap.set('n', 'fg', fzf.live_grep, { desc = "Grep" }) vim.keymap.set('n', 'fm', fzf.manpages, { desc = "Manpages" }) -vim.keymap.set('n', 'b', fzf.buffers, { desc = "Buffers" }) +vim.keymap.set('n', 'fr', fzf.resume, { desc = "Resume last search" }) +vim.keymap.set('n', 'fs', fzf.blines, { desc = "Search buffer" }) vim.keymap.set('n', 'ft', ":TodoFzfLua", { desc = "Todos" }) -- use fzf buffer lines as default search -vim.keymap.set('n', '/', fzf.blines, { desc = "Search buffer" }) +vim.keymap.set('n', '', fzf.blines, { desc = "Search buffer" }) vim.keymap.set('n', 'z=', fzf.spell_suggest, { desc = "Spelling suggestions" }) -- open file manager and git @@ -63,6 +64,9 @@ vim.keymap.set('n', 'mc', mywords.uhl_all, { desc = "Clear all highlights -- Shortcuts which are known from Emacs -- ------------------------------------------ -vim.keymap.set('n', '1', ":wincmd o", { desc = "Win: close others" }) -vim.keymap.set('n', '0', ":only", { desc = "Win: close current" }) +vim.keymap.set('n', '0', ":hide", { desc = "Win: close current" }) +vim.keymap.set('n', '1', ":only", { desc = "Win: close others" }) +vim.keymap.set('n', '2', ":split", { desc = "Win: split horizontally" }) +vim.keymap.set('n', '2', ":vsplit", { desc = "Win: split vertically" }) vim.keymap.set('n', 'q', "gwap", { desc = "Wrap paragraph" }) +vim.keymap.set('n', '', ":silent! nohls", { desc = "Clear search" }) diff --git a/lua/lsp.lua b/lua/lsp.lua index 465f25a..376a4ee 100644 --- a/lua/lsp.lua +++ b/lua/lsp.lua @@ -13,7 +13,7 @@ require('mason-lspconfig').setup({ ensure_installed = { 'pylsp', 'lua_ls', - 'rust_analyzer', + -- 'rust_analyzer', -- handled by rust mrcjkb/rustaceanvim 'yamlls', 'ts_ls', 'gopls', @@ -22,45 +22,33 @@ require('mason-lspconfig').setup({ }, }) --- Customized on_attach function --- See `:help vim.diagnostic.*` for documentation on any of the below functions -local opts = { noremap = true, silent = true } -vim.keymap.set('n', 'e', vim.diagnostic.open_float, { noremap = true, silent = true, desc = "Popup diagnostics" }) --- 2024-09-23 - currently unused --- vim.keymap.set('n', 'q', vim.diagnostic.setloclist, opts) -vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, opts) -vim.keymap.set('n', ']d', vim.diagnostic.goto_next, opts) -- Use an on_attach function to only map the following keys -- after the language server attaches to the current buffer local on_attach = function(client, bufnr) -- Enable completion triggered by - vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc') + -- vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc') -- See `:help vim.lsp.*` for documentation on any of the below functions local bufopts = { noremap = true, silent = true, buffer = bufnr } - vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, bufopts) - vim.keymap.set('n', 'gd', vim.lsp.buf.definition, bufopts) - vim.keymap.set('n', 'K', vim.lsp.buf.hover, bufopts) - vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, bufopts) - vim.keymap.set('n', '', vim.lsp.buf.signature_help, bufopts) - vim.keymap.set('n', 'wa', vim.lsp.buf.add_workspace_folder, bufopts) - vim.keymap.set('n', 'wr', vim.lsp.buf.remove_workspace_folder, bufopts) + vim.keymap.set('n', 'K', vim.lsp.buf.hover, { desc = "LSP show signature", unpack(bufopts) }) + vim.keymap.set('n', 'wa', vim.lsp.buf.add_workspace_folder, + { desc = "Workspace add folder", unpack(bufopts) }) + vim.keymap.set('n', 'wr', vim.lsp.buf.remove_workspace_folder, + { desc = "Workspace remove folder", unpack(bufopts) }) vim.keymap.set('n', 'wl', function() print(vim.inspect(vim.lsp.buf.list_workspace_folders())) - end, bufopts) - -- vim.keymap.set('n', 'D', vim.lsp.buf.type_definition, bufopts) - vim.keymap.set('n', 'rn', vim.lsp.buf.rename, bufopts) - -- vim.keymap.set('n', 'ca', vim.lsp.buf.code_action, bufopts) + end, { desc = "Workspace list folders", unpack(bufopts) }) + vim.keymap.set('n', 'rn', vim.lsp.buf.rename, { desc = "LSP Rename", unpack(bufopts) }) vim.keymap.set("n", "f", function() vim.lsp.buf.format({ async = true }) - end, bufopts) + end, { desc = "LSP Format buffer", unpack(bufopts) }) -- 2024-09-09 - some ccflow commands - local fzf = require('fzf-lua') vim.keymap.set('n', 'd', fzf.diagnostics_document, { desc = "Document diagnostics" }) vim.keymap.set('n', 'D', fzf.diagnostics_workspace, { desc = "Workspace diagnostics" }) + vim.keymap.set('n', 'e', vim.diagnostic.open_float, { desc = "Popup diagnostics" }) vim.keymap.set('n', 's', fzf.lsp_document_symbols, { desc = "Doc symbols" }) vim.keymap.set('n', 'c', fzf.lsp_code_actions, { desc = "Code Actions" }) -- vim.keymap.set('n', 'gr', vim.lsp.buf.references, bufopts) @@ -69,7 +57,7 @@ local on_attach = function(client, bufnr) end -- Set different settings for different languages' LSP --- LSP list: https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md +-- LSP list: https://github.com/neovim/nvim-lspconfig/blob/master/doc/configs.md -- How to use setup({}): https://github.com/neovim/nvim-lspconfig/wiki/Understanding-setup-%7B%7D -- - the settings table is sent to the LSP -- - on_attach: a lua callback function to run after LSP attaches to a given buffer @@ -108,3 +96,12 @@ require('mason-lspconfig').setup_handlers({ end end }) + + +-- use on_attach to get lsp related shortcuts +vim.g.rustaceanvim = { + -- LSP configuration + server = { + on_attach = on_attach + } +} diff --git a/lua/plugins.lua b/lua/plugins.lua index ec8ea42..115c3a5 100644 --- a/lua/plugins.lua +++ b/lua/plugins.lua @@ -12,17 +12,10 @@ end vim.opt.rtp:prepend(lazypath) require("lazy").setup({ - -- Vscode-like pictograms - { - "onsails/lspkind.nvim", - event = { "VimEnter" }, - }, - -- Auto-completion engine { "hrsh7th/nvim-cmp", dependencies = { - "lspkind.nvim", "hrsh7th/cmp-nvim-lsp", -- lsp auto-completion "hrsh7th/cmp-buffer", -- buffer auto-completion "hrsh7th/cmp-path", -- path auto-completion @@ -49,6 +42,16 @@ require("lazy").setup({ "williamboman/mason.nvim", "williamboman/mason-lspconfig.nvim", "neovim/nvim-lspconfig", + + -- Nice plugin to show what LSPs are doing in the background (and others + -- using $/progress and vim.notify()) + { + "j-hui/fidget.nvim", + opts = { + -- options + }, + }, + -- show lsp signature while coding { "ray-x/lsp_signature.nvim", @@ -94,6 +97,9 @@ require("lazy").setup({ end, }, + -- comfortable table editing, esp. used in orgmode + { 'dhruvasagar/vim-table-mode' }, + -- fzf-lua { "ibhagwan/fzf-lua", @@ -107,7 +113,7 @@ require("lazy").setup({ end }, - -- whichkey + -- which-key { "folke/which-key.nvim", event = "VeryLazy", @@ -161,6 +167,34 @@ require("lazy").setup({ 'nvim-lualine/lualine.nvim', dependencies = { 'nvim-tree/nvim-web-devicons' }, config = function() + -- an alternative might be: + -- https://github.com/nvim-treesitter/nvim-treesitter-context + local function breadcrumb() + local result = require 'nvim-treesitter'.statusline( + { + type_patterns = { + "class", + "impl", + "function", + "method", + "import", + "for", + "if", + "while", + "variable", + "comment", + }, + separator = " ▶ " + } + ) + if result == "" then + result = ' ' + elseif result == nil then + result = '' + end + return result + end + require("lualine").setup { options = { icons_enabled = false, @@ -181,7 +215,7 @@ require("lazy").setup({ } }, sections = { - lualine_a = { 'filename' }, + lualine_a = { { 'filename', path = 1, shorting_target = 50 } }, lualine_b = { 'branch', 'diff', 'diagnostics' }, lualine_c = {}, lualine_x = { 'encoding', 'fileformat', 'filetype' }, @@ -189,16 +223,25 @@ require("lazy").setup({ lualine_z = { 'progress', 'location' } }, inactive_sections = { - lualine_a = {}, + lualine_a = { { 'filename', path = 1, shorting_target = 50 } }, lualine_b = {}, - lualine_c = { 'filename' }, - lualine_x = { 'location' }, - lualine_y = {}, - lualine_z = {} + lualine_c = {}, + -- lualine_x = { 'encoding', 'fileformat', 'filetype' }, + lualine_x = {}, + lualine_y = { 'filesize' }, + lualine_z = { 'location' } }, tabline = {}, - winbar = {}, - inactive_winbar = {}, + winbar = { + lualine_a = { + { breadcrumb, + color = { bg = '#101010', fg = '#568200' }, + }, + }, + }, + inactive_winbar = { + lualine_a = { breadcrumb }, + }, extensions = {} } end @@ -247,9 +290,6 @@ require("lazy").setup({ "PhilRunninger/cmp-rpncalc", }, - -- comfortable table editing, esp. used in orgmode - { 'dhruvasagar/vim-table-mode' }, - -- TODO, WARN, HACK, PERF, NOTE, TEST and others highlighting and searching { "folke/todo-comments.nvim", @@ -275,8 +315,8 @@ require("lazy").setup({ { "cpkio/nvim-treesitter-asciidoc" }, + -- Greeter to run on NeoVim startup { - 'goolord/alpha-nvim', dependencies = { 'nvim-tree/nvim-web-devicons', @@ -384,5 +424,18 @@ require("lazy").setup({ end, }, + -- improved Rust support + { + 'mrcjkb/rustaceanvim', + version = '^5', -- Recommended + lazy = false, -- This plugin is already lazy + }, + -- show git changes on the left + { + "lewis6991/gitsigns.nvim", + config = function() + require('gitsigns').setup() + end, + }, })