From c7a66c16057ea707339828099ca41565294bd564 Mon Sep 17 00:00:00 2001 From: Marco Thomas Date: Mon, 11 Jul 2022 20:19:12 +0200 Subject: [PATCH] ft: add initial nvim config --- files/nvim/nvim/init.lua | 6 + files/nvim/nvim/lua/icons.lua | 207 +++++++++++++++++++++++++++++++ files/nvim/nvim/lua/lsp.lua | 50 ++++++++ files/nvim/nvim/lua/mappings.lua | 45 +++++++ files/nvim/nvim/lua/plugins.lua | 136 ++++++++++++++++++++ files/nvim/nvim/lua/settings.lua | 11 ++ 6 files changed, 455 insertions(+) create mode 100644 files/nvim/nvim/init.lua create mode 100644 files/nvim/nvim/lua/icons.lua create mode 100644 files/nvim/nvim/lua/lsp.lua create mode 100644 files/nvim/nvim/lua/mappings.lua create mode 100644 files/nvim/nvim/lua/plugins.lua create mode 100644 files/nvim/nvim/lua/settings.lua diff --git a/files/nvim/nvim/init.lua b/files/nvim/nvim/init.lua new file mode 100644 index 0000000..80bbead --- /dev/null +++ b/files/nvim/nvim/init.lua @@ -0,0 +1,6 @@ +require 'plugins' -- Load plugins +require 'settings' -- General settings +require 'mappings' -- Keyboard mappings + +-- Plugin specific +require 'lsp' diff --git a/files/nvim/nvim/lua/icons.lua b/files/nvim/nvim/lua/icons.lua new file mode 100644 index 0000000..ee0b09c --- /dev/null +++ b/files/nvim/nvim/lua/icons.lua @@ -0,0 +1,207 @@ +local M = {} + +M.lspkind = { + Namespace = "", + Text = " ", + Method = " ", + Function = " ", + Constructor = " ", + Field = "ﰠ ", + Variable = " ", + Class = "ﴯ ", + Interface = " ", + Module = " ", + Property = "ﰠ ", + Unit = "塞 ", + Value = " ", + Enum = " ", + Keyword = " ", + Snippet = " ", + Color = " ", + File = " ", + Reference = " ", + Folder = " ", + EnumMember = " ", + Constant = " ", + Struct = "פּ ", + Event = " ", + Operator = " ", + TypeParameter = " ", + Table = "", + Object = " ", + Tag = "", + Array = "[]", + Boolean = " ", + Number = " ", + Null = "ﳠ", + String = " ", + Calendar = "", + Watch = " ", + Package = "", +} + +M.statusline_separators = { + default = { + left = "", + right = " ", + }, + + round = { + left = "", + right = "", + }, + + block = { + left = "█", + right = "█", + }, + + arrow = { + left = "", + right = "", + }, +} + +M.devicons = { + default_icon = { + icon = "", + name = "Default", + }, + + c = { + icon = "", + name = "c", + }, + + css = { + icon = "", + name = "css", + }, + + deb = { + icon = "", + name = "deb", + }, + + Dockerfile = { + icon = "", + name = "Dockerfile", + }, + + html = { + icon = "", + name = "html", + }, + + jpeg = { + icon = "", + name = "jpeg", + }, + + jpg = { + icon = "", + name = "jpg", + }, + + js = { + icon = "", + name = "js", + }, + + kt = { + icon = "󱈙", + name = "kt", + }, + + lock = { + icon = "", + name = "lock", + }, + + lua = { + icon = "", + name = "lua", + }, + + mp3 = { + icon = "", + name = "mp3", + }, + + mp4 = { + icon = "", + name = "mp4", + }, + + out = { + icon = "", + name = "out", + }, + + png = { + icon = "", + name = "png", + }, + + py = { + icon = "", + name = "py", + }, + + ["robots.txt"] = { + icon = "ﮧ", + name = "robots", + }, + + toml = { + icon = "", + name = "toml", + }, + + ts = { + icon = "ﯤ", + name = "ts", + }, + + ttf = { + icon = "", + name = "TrueTypeFont", + }, + + rb = { + icon = "", + name = "rb", + }, + + rpm = { + icon = "", + name = "rpm", + }, + + vue = { + icon = "﵂", + name = "vue", + }, + + woff = { + icon = "", + name = "WebOpenFontFormat", + }, + + woff2 = { + icon = "", + name = "WebOpenFontFormat2", + }, + + xz = { + icon = "", + name = "xz", + }, + + zip = { + icon = "", + name = "zip", + }, +} + +return M diff --git a/files/nvim/nvim/lua/lsp.lua b/files/nvim/nvim/lua/lsp.lua new file mode 100644 index 0000000..e8015a6 --- /dev/null +++ b/files/nvim/nvim/lua/lsp.lua @@ -0,0 +1,50 @@ +-- Custom warning symbols +local signs = { Error = " ", Warn = " ", Hint = " ", Info = " " } +for type, icon in pairs(signs) do + local hl = "DiagnosticSign" .. type + vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = hl }) +end + +-- Easily install LSPs with `:LSPInstall` +require("nvim-lsp-installer").setup({ + automatic_installation = true, + ui = { + icons = { + server_installed = "✓", + server_pending = "➜", + server_uninstalled = "✗", + }, + }, +}) + +local lsp = require('lspconfig') + +-- Normal LSPs +lsp.pylsp.setup({}) +lsp.texlab.setup({}) +lsp.sumneko_lua.setup({}) +lsp.hls.setup({}) + +-- Rust (use rust-tools to setup lsp, because it has more features) +local opts = { + tools = { + autoSetHints = true, + hover_with_actions = true, + inlay_hints = { + show_parameter_hints = false, + parameter_hints_prefix = "", + other_hints_prefix = "", + }, + }, + server = { + settings = { + ["rust-analyzer"] = { + checkOnSave = { + command = "clippy" + }, + } + } + }, +} + +require('rust-tools').setup(opts) diff --git a/files/nvim/nvim/lua/mappings.lua b/files/nvim/nvim/lua/mappings.lua new file mode 100644 index 0000000..80ab7d9 --- /dev/null +++ b/files/nvim/nvim/lua/mappings.lua @@ -0,0 +1,45 @@ +local map = vim.api.nvim_set_keymap +local default_opts = { noremap = true, silent = true } + +vim.g.mapleader = ' ' + +-- Telescope +local telescope = require'telescope' +local actions = require "telescope.actions" +telescope.setup({ + defaults = { + mappings = { + i = { + [""] = actions.move_selection_next, + [""] = actions.move_selection_previous, + }, + n = { + [""] = actions.move_selection_next, + [""] = actions.move_selection_previous, + } + } + } +}) +map("n", "", " Telescope find_files", default_opts) +map("n", "", " Telescope live_grep", default_opts) +map("n", "", " Telescope keymaps", default_opts) + +-- 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) + +-- Telescope + git(1) +map("n", "gs", " Telescope git_status", default_opts) + +-- cmp +local cmp = require'cmp' +cmp.setup({ + mapping = { + [""] = cmp.mapping.select_prev_item(), + [""] = cmp.mapping.select_next_item(), + }, + } +) diff --git a/files/nvim/nvim/lua/plugins.lua b/files/nvim/nvim/lua/plugins.lua new file mode 100644 index 0000000..0003641 --- /dev/null +++ b/files/nvim/nvim/lua/plugins.lua @@ -0,0 +1,136 @@ +vim.cmd [[packadd packer.nvim]] + +-- TODO: null-ls (Formatting) +-- TODO: TODO Marking +-- TODO: Latex stuff (synctex, bibtex) + +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 + packer_bootstrap = fn.system({'git', 'clone', '--depth', '1', 'https://github.com/wbthomason/packer.nvim', install_path}) +end + +return require('packer').startup(function(use) + -- Packer can manage itself + use 'wbthomason/packer.nvim' + + -- Theme + use({ + 'sainnhe/everforest', + config = function() + vim.cmd("set background=light") + vim.cmd("let g:everforest_background = 'hard'") + vim.cmd("colorscheme everforest") + vim.cmd("set termguicolors") + end, + }) + + -- LuaLine + use({ + "nvim-lualine/lualine.nvim", + requires = { "kyazdani42/nvim-web-devicons", opt = true }, + config = function() + require('lualine').setup({ options = { theme = 'everforest' } }) + end, + }) + + -- Fuzzy Finder (Files etc) + use({ + "nvim-telescope/telescope.nvim", + requires = { { "nvim-lua/plenary.nvim" } }, + }) + + -- Auto Indentation + use({ + 'nmac427/guess-indent.nvim', + config = function() require('guess-indent').setup {} end, + }) + + -- Autopairs + use({ + "windwp/nvim-autopairs", + config = function() + require('nvim-autopairs').setup({}) + end, + }) + + -- Treesitter + use({ + "nvim-treesitter/nvim-treesitter", + config = function() + require('nvim-treesitter.configs').setup({ + ensure_installed = { "c", "rust", "lua", "python", "haskell" }, + auto_intall = true, + highlight = { + enable = true, + additional_vim_regex_highlighting = false, + }, + }) + end, + }) + + -- LSP + use("neovim/nvim-lspconfig") + use("williamboman/nvim-lsp-installer") + use("simrat39/rust-tools.nvim") -- Cooler LSP stuff for Rust + use { + "folke/trouble.nvim", + requires = { + "kyazdani42/nvim-web-devicons", + "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", + }, + config = function() + local cmp = require'cmp' + cmp.setup({ +-- snippet = { +-- expand = function(args) +-- require("luasnip").lsp_expand(args.body) +-- end, +-- }, + sources = { + { name = 'nvim_lsp' }, + { name = 'luasnip' }, + { name = 'path' }, + { name = 'buffer' }, + }, + formatting = { + format = function(_, vim_item) + local icons = require("icons").lspkind + vim_item.kind = string.format("%s %s", icons[vim_item.kind], vim_item.kind) + return vim_item + end, + }, + }) + end, + }) + + -- which-key + use { + "folke/which-key.nvim", + config = function() + require("which-key").setup { } + end + } + + -- Automatically set up your configuration after cloning packer.nvim + -- Put this at the end after all plugins + if packer_bootstrap then + require('packer').sync() + end +end) diff --git a/files/nvim/nvim/lua/settings.lua b/files/nvim/nvim/lua/settings.lua new file mode 100644 index 0000000..3191bb1 --- /dev/null +++ b/files/nvim/nvim/lua/settings.lua @@ -0,0 +1,11 @@ +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.smartindent = true -- autoindent new lines