From 96cffa9604ddcea55a126196b5b5c59d402c46fd Mon Sep 17 00:00:00 2001 From: Marco Thomas Date: Wed, 13 Jul 2022 17:59:34 +0200 Subject: [PATCH] nvim: add various keybinds and neogit --- files/nvim/.config/nvim/lua/mappings.lua | 45 +++++++++- files/nvim/.config/nvim/lua/plugins.lua | 101 +++++++++++++++++------ files/nvim/.config/nvim/lua/settings.lua | 2 +- 3 files changed, 118 insertions(+), 30 deletions(-) diff --git a/files/nvim/.config/nvim/lua/mappings.lua b/files/nvim/.config/nvim/lua/mappings.lua index 96472ca..7bae17c 100644 --- a/files/nvim/.config/nvim/lua/mappings.lua +++ b/files/nvim/.config/nvim/lua/mappings.lua @@ -1,4 +1,5 @@ local map = vim.api.nvim_set_keymap +local wk = require 'which-key' local default_opts = { noremap = true, silent = true } vim.g.mapleader = ' ' @@ -29,14 +30,52 @@ map("n", "", " Telescope keymaps", default_opts) -- Show all ke -- Telescope + LSP map("n", "la", " lua vim.lsp.buf.code_action()", default_opts) -- Apply LSP code action map("n", "ld", " Telescope lsp_definitions", default_opts) -- Show all LSP definitions (or jump if only 1) -map("n", "le", " TroubleToggle", default_opts) -- Show errors and warnings +map("n", "le", " Telescope diagnostics", default_opts) -- Show errors and warnings map("n", "lf", " lua vim.lsp.buf.formatting()", default_opts) -- Format buffer with LSP map("n", "lh", " lua vim.lsp.buf.hover()", default_opts) -- Show info of symbol (double tap to enter) +map("n", "ln", " lua vim.lsp.buf.rename()", default_opts) -- Rename LSP symbol map("n", "lr", " Telescope lsp_references", default_opts) -- Show all LSP references map("n", "ls", " Telescope lsp_workspace_symbols", default_opts) -- Search for LSP symbols +map("n", "lt", " TodoTelescope", default_opts) -- Search for LSP symbols +wk.register({ + [""] = { + l = { + a = { "Actions" }, + d = { "Definitions" }, + e = { "Errors" }, + f = { "Format buffer" }, + h = { "Hover information" }, + n = { "(Re)Name symbol" }, + r = { "References" }, + s = { "Symbols" }, + t = { "TODOs" }, + } + } +}) --- Telescope + git(1) -map("n", "gs", " Telescope git_status", default_opts) +-- git +map("n", "gs", " Neogit", default_opts) +wk.register({ + [""] = { + g = { + s = { "Status" }, + } + } +}) + +-- Telescope + telescope-symbols +map("n", "ie", " lua require'telescope.builtin'.symbols{ sources = { 'emoji', 'gitmoji' } }", default_opts) -- Show emojis +map("n", "im", " lua require'telescope.builtin'.symbols{ sources = { 'julia' } }", default_opts) -- Show math symbols +map("n", "in", " lua require'telescope.builtin'.symbols{ sources = { 'nerd' } }", default_opts) -- Show nerd icons +wk.register({ + [""] = { + i = { + e = { "Emoji" }, + m = { "Math symbol" }, + n = { "Nerd Font" }, + } + } +}) -- cmp local cmp = require 'cmp' diff --git a/files/nvim/.config/nvim/lua/plugins.lua b/files/nvim/.config/nvim/lua/plugins.lua index 087ee16..7cfd7e2 100644 --- a/files/nvim/.config/nvim/lua/plugins.lua +++ b/files/nvim/.config/nvim/lua/plugins.lua @@ -1,7 +1,5 @@ vim.cmd [[packadd packer.nvim]] --- TODO: add own snippets (for latex {notes, presentation, wfig, srcd, srci}) - local fn = vim.fn local install_path = fn.stdpath('data') .. '/site/pack/packer/start/packer.nvim' if fn.empty(fn.glob(install_path)) > 0 then @@ -33,13 +31,23 @@ return require('packer').startup(function(use) end, } + -- Icons + use({ + "kyazdani42/nvim-web-devicons", + config = function() + require 'nvim-web-devicons'.setup({ + default = true + }) + end, + }) + -- LuaLine use({ "nvim-lualine/lualine.nvim", requires = { - { "kyazdani42/nvim-web-devicons", opt = true, }, -- Icons - "arkav/lualine-lsp-progress", -- Show lsp loading progress - "SmiteshP/nvim-navic", -- Show breadcrumbs + "kyazdani42/nvim-web-devicons", + "arkav/lualine-lsp-progress", -- Show lsp loading progress + "SmiteshP/nvim-navic", -- Show breadcrumbs }, config = function() require('lualine').setup({ @@ -52,11 +60,10 @@ return require('packer').startup(function(use) 'diff', { 'diagnostics', - -- fake colors from Trouble diagnostics_color = { - warn = { fg = '#dfa000'}, - info = { fg = "#4a94c5"}, - hint = { fg = "35a77c"} + warn = { fg = "orange" }, + info = { fg = "#479bc7" }, + hint = { fg = "darkcyan" } }, } @@ -68,7 +75,7 @@ return require('packer').startup(function(use) function() -- Show trailing whitespace local space = vim.fn.search([[\s\+$]], 'nwc') - return space ~= 0 and "TW:"..space or "" + return space ~= 0 and "TW:" .. space or "" end } } @@ -79,7 +86,26 @@ return require('packer').startup(function(use) -- Fuzzy Finder (Files etc) use({ "nvim-telescope/telescope.nvim", - requires = { { "nvim-lua/plenary.nvim" } }, + requires = { + "nvim-lua/plenary.nvim", + "nvim-telescope/telescope-symbols.nvim", -- Search for icons + }, + config = function() + require('telescope').setup({ + defaults = { + prompt_prefix = "  ", + selection_caret = " ", + entry_prefix = " ", + sorting_strategy = "ascending", + layout_strategy = "horizontal", + layout_config = { + horizontal = { + prompt_position = "top", + } + } + }, + }) + end, }) -- Auto Indentation @@ -101,7 +127,16 @@ return require('packer').startup(function(use) "nvim-treesitter/nvim-treesitter", config = function() require('nvim-treesitter.configs').setup({ - ensure_installed = { "c", "rust", "lua", "python", "haskell" }, + ensure_installed = { + "bash", + "c", + "haskell", + "json", + "latex", + "lua", + "python", + "rust", + }, auto_intall = true, highlight = { enable = true, @@ -112,21 +147,13 @@ return require('packer').startup(function(use) }) -- LSP (install with `:LSPInstall`, inspect with `:LSPInfo`) - use("neovim/nvim-lspconfig") -- Easy to manage LSP servers (attach etc) + use("neovim/nvim-lspconfig") -- Easy to manage LSP servers (attach etc) use("williamboman/nvim-lsp-installer") -- Easy to install LSP servers - use("simrat39/rust-tools.nvim") -- Cooler LSP stuff for Rust - - -- Show error neatly in a minibuffer - use { - "folke/trouble.nvim", - requires = { - "kyazdani42/nvim-web-devicons", - "folke/lsp-colors.nvim", - }, - config = function() require("trouble").setup {} end, - } + use("simrat39/rust-tools.nvim") -- Cooler LSP stuff for Rust -- Snippets + -- TODO: max candidates + -- TODO: time trigger activation use({ 'hrsh7th/nvim-cmp', requires = { @@ -138,8 +165,6 @@ return require('packer').startup(function(use) "saadparwaiz1/cmp_luasnip", }, config = function() - require('luasnip.loaders.from_vscode').lazy_load() - -- require("luasnip.loaders.from_vscode").lazy_load({ paths = { "~/.config/nvim/snippets" } }) local cmp = require 'cmp' cmp.setup({ snippet = { @@ -162,6 +187,15 @@ return require('packer').startup(function(use) end, }, }) + -- Load in friendly-snippets + require('luasnip.loaders.from_vscode').lazy_load() + -- TODO: Add own snippets + --[[ require("luasnip.loaders.from_vscode").lazy_load({ + paths = { + "~/.config/nvim/snippets", + "/home/marc/.local/share/nvim/site/pack/packer/start/friendly-snippets" + } + }) ]] end, }) @@ -193,6 +227,21 @@ return require('packer').startup(function(use) end } + -- git client + use { + 'TimUntersberger/neogit', + requires = 'nvim-lua/plenary.nvim', + config = function() + local neogit = require('neogit') + neogit.setup { + signs = { + section = { "﬌", "" }, + item = { "﬌", "" }, + } + } + end, + } + -- Automatically set up your configuration after cloning packer.nvim -- Put this at the end after all plugins if packer_bootstrap then diff --git a/files/nvim/.config/nvim/lua/settings.lua b/files/nvim/.config/nvim/lua/settings.lua index bd635b8..2f6ddde 100644 --- a/files/nvim/.config/nvim/lua/settings.lua +++ b/files/nvim/.config/nvim/lua/settings.lua @@ -1,4 +1,4 @@ -local opt = vim.opt +local opt = vim.opt opt.colorcolumn = "80" -- Colored column at 80c opt.cursorline = true -- Highlight entire current row