From 05569fb9f4e686af6ef4e88ea3a3cecdbb92d2d2 Mon Sep 17 00:00:00 2001 From: Marco Thomas Date: Tue, 12 Jul 2022 21:42:25 +0200 Subject: [PATCH] ft: add rest of nvim config --- files/nvim/.config/nvim/init.lua | 8 +- files/nvim/.config/nvim/lua/lsp.lua | 30 +++++- files/nvim/.config/nvim/lua/mappings.lua | 33 ++++--- files/nvim/.config/nvim/lua/plugins.lua | 121 +++++++++++++++++------ files/nvim/.config/nvim/lua/settings.lua | 23 +++-- 5 files changed, 158 insertions(+), 57 deletions(-) diff --git a/files/nvim/.config/nvim/init.lua b/files/nvim/.config/nvim/init.lua index 80bbead..c7d6b39 100644 --- a/files/nvim/.config/nvim/init.lua +++ b/files/nvim/.config/nvim/init.lua @@ -1,6 +1,8 @@ +-- Make sure to update packer with `:PackerInstall` and `:PackerSync` +-- Treesitter with `:TSUpdate` +-- LSP with `:LSPInstall`, log with `:LSPInfo` + require 'plugins' -- Load plugins require 'settings' -- General settings require 'mappings' -- Keyboard mappings - --- Plugin specific -require 'lsp' +require 'lsp' -- Everything related to LSP diff --git a/files/nvim/.config/nvim/lua/lsp.lua b/files/nvim/.config/nvim/lua/lsp.lua index e8015a6..5334cab 100644 --- a/files/nvim/.config/nvim/lua/lsp.lua +++ b/files/nvim/.config/nvim/lua/lsp.lua @@ -18,12 +18,31 @@ require("nvim-lsp-installer").setup({ }) local lsp = require('lspconfig') +local navic = require('nvim-navic') -- breadcrumbs -- Normal LSPs -lsp.pylsp.setup({}) -lsp.texlab.setup({}) -lsp.sumneko_lua.setup({}) -lsp.hls.setup({}) +-- Install with `:LSPInstall` +local servers = { "pylsp", "sumneko_lua", "hls" } +for _,i in ipairs(servers) do + lsp[i].setup({ + on_attach = function(client, bufnr) + navic.attach(client, bufnr) -- breadcrumbs + end + }) +end + +-- LaTeX (build with `:TexlabBuild`) +-- https://github.com/neovim/nvim-lspconfig/blob/master/lua/lspconfig/server_configurations/texlab.lua +lsp.texlab.setup({ + settings = { + texlab = { + build = { + args = { '-pdf', '-interaction=nonstopmode', '-synctex=1', '-shell-escape','%f' }, + onSave = true, + } + } + } +}) -- Rust (use rust-tools to setup lsp, because it has more features) local opts = { @@ -37,6 +56,9 @@ local opts = { }, }, server = { + on_attach = function(client, bufnr) + navic.attach(client, bufnr) -- breadcrumbs + end, settings = { ["rust-analyzer"] = { checkOnSave = { diff --git a/files/nvim/.config/nvim/lua/mappings.lua b/files/nvim/.config/nvim/lua/mappings.lua index 80ab7d9..96472ca 100644 --- a/files/nvim/.config/nvim/lua/mappings.lua +++ b/files/nvim/.config/nvim/lua/mappings.lua @@ -3,8 +3,10 @@ local default_opts = { noremap = true, silent = true } vim.g.mapleader = ' ' +map("n", "", " noh", default_opts) + -- Telescope -local telescope = require'telescope' +local telescope = require 'telescope' local actions = require "telescope.actions" telescope.setup({ defaults = { @@ -20,26 +22,31 @@ telescope.setup({ } } }) -map("n", "", " Telescope find_files", default_opts) -map("n", "", " Telescope live_grep", default_opts) -map("n", "", " Telescope keymaps", default_opts) +map("n", "", " Telescope find_files", default_opts) -- Show files +map("n", "", " Telescope live_grep", default_opts) -- Grep through current directory +map("n", "", " Telescope keymaps", default_opts) -- Show all keys -- Telescope + LSP -map("n", "ls", " Telescope lsp_workspace_symbols", default_opts) -map("n", "ld", " Telescope lsp_definitions", default_opts) -map("n", "lr", " Telescope lsp_references", default_opts) -map("n", "le", " TroubleToggle", default_opts) -map("n", "la", " lua vim.lsp.buf.code_action", default_opts) +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", "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", "lr", " Telescope lsp_references", default_opts) -- Show all LSP references +map("n", "ls", " Telescope lsp_workspace_symbols", default_opts) -- Search for LSP symbols -- Telescope + git(1) map("n", "gs", " Telescope git_status", default_opts) -- cmp -local cmp = require'cmp' +local cmp = require 'cmp' cmp.setup({ mapping = { [""] = cmp.mapping.select_prev_item(), [""] = cmp.mapping.select_next_item(), - }, - } -) + [""] = cmp.mapping.confirm({ + behavior = cmp.ConfirmBehavior.Insert, + select = true, + }), + }, +}) diff --git a/files/nvim/.config/nvim/lua/plugins.lua b/files/nvim/.config/nvim/lua/plugins.lua index 0003641..087ee16 100644 --- a/files/nvim/.config/nvim/lua/plugins.lua +++ b/files/nvim/.config/nvim/lua/plugins.lua @@ -1,13 +1,12 @@ vim.cmd [[packadd packer.nvim]] --- TODO: null-ls (Formatting) --- TODO: TODO Marking --- TODO: Latex stuff (synctex, bibtex) +-- 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' +local install_path = fn.stdpath('data') .. '/site/pack/packer/start/packer.nvim' if fn.empty(fn.glob(install_path)) > 0 then - packer_bootstrap = fn.system({'git', 'clone', '--depth', '1', 'https://github.com/wbthomason/packer.nvim', install_path}) + packer_bootstrap = fn.system({ 'git', 'clone', '--depth', '1', 'https://github.com/wbthomason/packer.nvim', + install_path }) end return require('packer').startup(function(use) @@ -25,12 +24,55 @@ return require('packer').startup(function(use) end, }) + -- Breadcrumbs (will be loaded into LuaLine) + use { + "SmiteshP/nvim-navic", + requires = "neovim/nvim-lspconfig", + config = function() + require 'nvim-navic'.setup({}) + end, + } + -- LuaLine use({ "nvim-lualine/lualine.nvim", - requires = { "kyazdani42/nvim-web-devicons", opt = true }, + requires = { + { "kyazdani42/nvim-web-devicons", opt = true, }, -- Icons + "arkav/lualine-lsp-progress", -- Show lsp loading progress + "SmiteshP/nvim-navic", -- Show breadcrumbs + }, config = function() - require('lualine').setup({ options = { theme = 'everforest' } }) + require('lualine').setup({ + options = { + theme = 'everforest' + }, + sections = { + lualine_b = { + 'branch', + 'diff', + { + 'diagnostics', + -- fake colors from Trouble + diagnostics_color = { + warn = { fg = '#dfa000'}, + info = { fg = "#4a94c5"}, + hint = { fg = "35a77c"} + }, + } + + }, + lualine_c = { 'filename', require('nvim-navic').get_location }, + lualine_x = { 'lsp_progress', 'encoding', 'fileformat', 'filetype' }, + lualine_z = { + 'location', + function() + -- Show trailing whitespace + local space = vim.fn.search([[\s\+$]], 'nwc') + return space ~= 0 and "TW:"..space or "" + end + } + } + }) end, }) @@ -54,7 +96,7 @@ return require('packer').startup(function(use) end, }) - -- Treesitter + -- Treesitter (Update with `:TSUpdate`) use({ "nvim-treesitter/nvim-treesitter", config = function() @@ -69,10 +111,12 @@ return require('packer').startup(function(use) end, }) - -- LSP - use("neovim/nvim-lspconfig") - use("williamboman/nvim-lsp-installer") - use("simrat39/rust-tools.nvim") -- Cooler LSP stuff for Rust + -- LSP (install with `:LSPInstall`, inspect with `:LSPInfo`) + 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 = { @@ -80,36 +124,37 @@ return require('packer').startup(function(use) "folke/lsp-colors.nvim", }, config = function() require("trouble").setup {} end, -} + } -- Snippets - -- TODO: texlab doenst show snippets? (happy snippets) - -- TODO: add friendly snippets - -- https://github.com/deniserdogan/dotfiles/blob/master/lua/dannzi.lua use({ 'hrsh7th/nvim-cmp', requires = { - "hrsh7th/cmp-nvim-lsp", - "saadparwaiz1/cmp_luasnip", "L3MON4D3/LuaSnip", - "hrsh7th/cmp-path", "hrsh7th/cmp-buffer", + "hrsh7th/cmp-nvim-lsp", + "hrsh7th/cmp-path", + "rafamadriz/friendly-snippets", + "saadparwaiz1/cmp_luasnip", }, config = function() - local cmp = require'cmp' + 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 = { --- expand = function(args) --- require("luasnip").lsp_expand(args.body) --- end, --- }, + snippet = { + expand = function(args) + require("luasnip").lsp_expand(args.body) + end, + }, sources = { - { name = 'nvim_lsp' }, { name = 'luasnip' }, - { name = 'path' }, + { name = 'nvim_lsp' }, { name = 'buffer' }, + { name = 'path' }, }, formatting = { + -- Show icons in cmp box format = function(_, vim_item) local icons = require("icons").lspkind vim_item.kind = string.format("%s %s", icons[vim_item.kind], vim_item.kind) @@ -124,7 +169,27 @@ return require('packer').startup(function(use) use { "folke/which-key.nvim", config = function() - require("which-key").setup { } + require("which-key").setup {} + end + } + + -- Align with `:Align ` + use 'RRethy/nvim-align' + + -- Easily comment out stuff (gc, gb) + use({ + "numToStr/Comment.nvim", + config = function() + require('Comment').setup({}) + end, + }) + + -- Highlight TODOs + use { + "folke/todo-comments.nvim", + requires = "nvim-lua/plenary.nvim", + config = function() + require("todo-comments").setup {} end } diff --git a/files/nvim/.config/nvim/lua/settings.lua b/files/nvim/.config/nvim/lua/settings.lua index 3191bb1..bd635b8 100644 --- a/files/nvim/.config/nvim/lua/settings.lua +++ b/files/nvim/.config/nvim/lua/settings.lua @@ -1,11 +1,16 @@ -local opt = vim.opt +local opt = vim.opt -opt.colorcolumn = "80" -opt.cursorline = true -opt.number = true -opt.relativenumber = true -opt.scrolloff = 12 -opt.signcolumn = "yes" -opt.swapfile = false +opt.colorcolumn = "80" -- Colored column at 80c +opt.cursorline = true -- Highlight entire current row +opt.number = true -- Show line numbers +opt.relativenumber = true -- Show relative line numbers from cursor +opt.scrolloff = 12 -- Minimum lines at top and bottom +opt.signcolumn = "yes" -- Show icons column at on the left side +opt.swapfile = false -- Do not create a swapfile +opt.smartindent = true -- Autoindent new lines +opt.showmode = false -- Disable status on most bottom row +opt.clipboard = "unnamed" -- Copy & Paste with system clipboard +opt.list = true -- Show trailing whitespaces -opt.smartindent = true -- autoindent new lines +vim.opt.undofile = true -- Save undo history +vim.o.mouse = 'a' -- Enable mouse