From df7bfd1282e4f17d289688d5533b6dab0d6cc74b Mon Sep 17 00:00:00 2001 From: Tobias Reisinger Date: Sun, 2 Apr 2023 19:31:08 +0200 Subject: [PATCH] Add nvim config --- .config/nvim/after/plugin/colors.lua | 8 +++ .config/nvim/after/plugin/fugitive.lua | 1 + .config/nvim/after/plugin/lsp.lua | 68 ++++++++++++++++++++++++ .config/nvim/after/plugin/lualine.lua | 41 ++++++++++++++ .config/nvim/after/plugin/swap.lua | 6 +++ .config/nvim/after/plugin/telescope.lua | 7 +++ .config/nvim/after/plugin/treesitter.lua | 21 ++++++++ .config/nvim/after/plugin/undotree.lua | 1 + .config/nvim/init.lua | 1 + .config/nvim/lua/user/init.lua | 4 ++ .config/nvim/lua/user/packer.lua | 65 ++++++++++++++++++++++ .config/nvim/lua/user/remap.lua | 26 +++++++++ .config/nvim/lua/user/set.lua | 34 ++++++++++++ .config/nvim/plugin/.gitignore | 2 + 14 files changed, 285 insertions(+) create mode 100644 .config/nvim/after/plugin/colors.lua create mode 100644 .config/nvim/after/plugin/fugitive.lua create mode 100644 .config/nvim/after/plugin/lsp.lua create mode 100644 .config/nvim/after/plugin/lualine.lua create mode 100644 .config/nvim/after/plugin/swap.lua create mode 100644 .config/nvim/after/plugin/telescope.lua create mode 100644 .config/nvim/after/plugin/treesitter.lua create mode 100644 .config/nvim/after/plugin/undotree.lua create mode 100644 .config/nvim/init.lua create mode 100644 .config/nvim/lua/user/init.lua create mode 100644 .config/nvim/lua/user/packer.lua create mode 100644 .config/nvim/lua/user/remap.lua create mode 100644 .config/nvim/lua/user/set.lua create mode 100644 .config/nvim/plugin/.gitignore diff --git a/.config/nvim/after/plugin/colors.lua b/.config/nvim/after/plugin/colors.lua new file mode 100644 index 0000000..a8d3d31 --- /dev/null +++ b/.config/nvim/after/plugin/colors.lua @@ -0,0 +1,8 @@ +local dracula = require("dracula") +dracula.setup({ + -- show the '~' characters after the end of buffers + show_end_of_buffer = true, -- default false + -- use transparent background + transparent_bg = true, -- default false +}) +vim.cmd('colorscheme dracula') diff --git a/.config/nvim/after/plugin/fugitive.lua b/.config/nvim/after/plugin/fugitive.lua new file mode 100644 index 0000000..80c9070 --- /dev/null +++ b/.config/nvim/after/plugin/fugitive.lua @@ -0,0 +1 @@ +vim.keymap.set("n", "gs", vim.cmd.Git) diff --git a/.config/nvim/after/plugin/lsp.lua b/.config/nvim/after/plugin/lsp.lua new file mode 100644 index 0000000..37df7f8 --- /dev/null +++ b/.config/nvim/after/plugin/lsp.lua @@ -0,0 +1,68 @@ +local lsp = require("lsp-zero") + +lsp.preset("recommended") + +lsp.ensure_installed({ + -- 'bashls', + -- 'lua_ls', + -- 'pylsp', + -- 'rnix', +}) + +-- Fix Undefined global 'vim' +require('lspconfig').lua_ls.setup({ + settings = { + Lua = { + diagnostics = { + globals = { 'vim' } + } + } + } +}) + +local cmp = require('cmp') +local cmp_select = { behavior = cmp.SelectBehavior.Select } +local cmp_mappings = lsp.defaults.cmp_mappings({ + [''] = cmp.mapping.select_prev_item(cmp_select), + [''] = cmp.mapping.select_next_item(cmp_select), + [''] = cmp.mapping.confirm({ select = true }), + [""] = cmp.mapping.complete(), +}) + +cmp_mappings[''] = nil +cmp_mappings[''] = nil + +lsp.setup_nvim_cmp({ + mapping = cmp_mappings +}) + +lsp.set_preferences({ + suggest_lsp_servers = false, + sign_icons = { + error = 'E', + warn = 'W', + hint = 'H', + info = 'I' + } +}) + +lsp.on_attach(function(client, bufnr) + local opts = { buffer = bufnr, remap = false } + + vim.keymap.set("n", "gd", function() vim.lsp.buf.definition() end, opts) + vim.keymap.set("n", "K", function() vim.lsp.buf.hover() end, opts) + vim.keymap.set("n", "vws", function() vim.lsp.buf.workspace_symbol() end, opts) + vim.keymap.set("n", "vd", function() vim.diagnostic.open_float() end, opts) + vim.keymap.set("n", "[d", function() vim.diagnostic.goto_next() end, opts) + vim.keymap.set("n", "]d", function() vim.diagnostic.goto_prev() end, opts) + vim.keymap.set("n", "vca", function() vim.lsp.buf.code_action() end, opts) + vim.keymap.set("n", "vrr", function() vim.lsp.buf.references() end, opts) + vim.keymap.set("n", "vrn", function() vim.lsp.buf.rename() end, opts) + vim.keymap.set("i", "", function() vim.lsp.buf.signature_help() end, opts) +end) + +lsp.setup() + +vim.diagnostic.config({ + virtual_text = true +}) diff --git a/.config/nvim/after/plugin/lualine.lua b/.config/nvim/after/plugin/lualine.lua new file mode 100644 index 0000000..16849cc --- /dev/null +++ b/.config/nvim/after/plugin/lualine.lua @@ -0,0 +1,41 @@ +local function window() + return vim.api.nvim_win_get_number(0) +end + +require('lualine').setup({ + options = { + icons_enabled = true, + theme = 'dracula', + }, + sections = { + lualine_a = { 'mode' }, + lualine_b = { 'branch', 'diff', 'diagnostics' }, + lualine_c = { { + 'filename', + path = 1, + } }, + lualine_x = { 'encoding', '%<0x%B', 'fileformat' }, + lualine_y = { 'filetype' }, + lualine_z = { 'location', window } + }, + inactive_sections = { + lualine_a = {}, + lualine_b = {}, + lualine_c = { 'filename' }, + lualine_x = { 'location', window }, + lualine_y = {}, + lualine_z = {} + }, + tabline = { + lualine_a = { { + 'tabs', + max_length = vim.o.columns / 2, + mode = 2 + } }, + lualine_b = {}, + lualine_c = {}, + lualine_x = {}, + lualine_y = { 'branch' }, + lualine_z = {} + } +}) diff --git a/.config/nvim/after/plugin/swap.lua b/.config/nvim/after/plugin/swap.lua new file mode 100644 index 0000000..621d915 --- /dev/null +++ b/.config/nvim/after/plugin/swap.lua @@ -0,0 +1,6 @@ +local swap = require('sibling-swap') +swap.setup({ + use_default_keymaps = true +}) +vim.keymap.set('n', 'g<', swap.swap_with_left, {}) +vim.keymap.set('n', 'g>', swap.swap_with_right, {}) diff --git a/.config/nvim/after/plugin/telescope.lua b/.config/nvim/after/plugin/telescope.lua new file mode 100644 index 0000000..f9a9a36 --- /dev/null +++ b/.config/nvim/after/plugin/telescope.lua @@ -0,0 +1,7 @@ +local builtin = require('telescope.builtin') +vim.keymap.set('n', 'pf', builtin.find_files, {}) +vim.keymap.set('n', '', builtin.git_files, {}) +vim.keymap.set('n', 'ps', function() + builtin.grep_string({ search = vim.fn.input("Grep > ") }) +end) +vim.keymap.set('n', 'vh', builtin.help_tags, {}) diff --git a/.config/nvim/after/plugin/treesitter.lua b/.config/nvim/after/plugin/treesitter.lua new file mode 100644 index 0000000..b90bdcd --- /dev/null +++ b/.config/nvim/after/plugin/treesitter.lua @@ -0,0 +1,21 @@ +require'nvim-treesitter.configs'.setup { + -- A list of parser names, or "all" (the five listed parsers should always be installed) + ensure_installed = { "c", "lua", "vim", "vimdoc", "query" }, + + -- Install parsers synchronously (only applied to `ensure_installed`) + sync_install = false, + + -- Automatically install missing parsers when entering buffer + -- Recommendation: set to false if you don't have `tree-sitter` CLI installed locally + auto_install = true, + + highlight = { + enable = true, + + -- Setting this to true will run `:h syntax` and tree-sitter at the same time. + -- Set this to `true` if you depend on 'syntax' being enabled (like for indentation). + -- Using this option may slow down your editor, and you may see some duplicate highlights. + -- Instead of true it can also be a list of languages + additional_vim_regex_highlighting = false, + }, +} diff --git a/.config/nvim/after/plugin/undotree.lua b/.config/nvim/after/plugin/undotree.lua new file mode 100644 index 0000000..b6b9276 --- /dev/null +++ b/.config/nvim/after/plugin/undotree.lua @@ -0,0 +1 @@ +vim.keymap.set("n", "u", vim.cmd.UndotreeToggle) diff --git a/.config/nvim/init.lua b/.config/nvim/init.lua new file mode 100644 index 0000000..ea49ffa --- /dev/null +++ b/.config/nvim/init.lua @@ -0,0 +1 @@ +require("user") diff --git a/.config/nvim/lua/user/init.lua b/.config/nvim/lua/user/init.lua new file mode 100644 index 0000000..6fe4977 --- /dev/null +++ b/.config/nvim/lua/user/init.lua @@ -0,0 +1,4 @@ +require("user.set") +require("user.remap") + +require("user.packer") diff --git a/.config/nvim/lua/user/packer.lua b/.config/nvim/lua/user/packer.lua new file mode 100644 index 0000000..ad68d89 --- /dev/null +++ b/.config/nvim/lua/user/packer.lua @@ -0,0 +1,65 @@ +-- This file can be loaded by calling `lua require('plugins')` from your init.vim + +-- Only required if you have packer configured as `opt` +vim.cmd [[packadd packer.nvim]] + +return require('packer').startup(function(use) + -- Packer can manage itself + use('wbthomason/packer.nvim') + + use({ + 'nvim-telescope/telescope.nvim', + tag = '0.1.0', + requires = { { 'nvim-lua/plenary.nvim' } } + }) + + use({ + 'nvim-treesitter/nvim-treesitter', + run = ':TSUpdate' + }) + + use("mbbill/undotree") + use("Wansmer/sibling-swap.nvim") + + use({ + 'VonHeikemen/lsp-zero.nvim', + branch = 'v1.x', + requires = { + -- LSP Support + { 'neovim/nvim-lspconfig' }, + { 'williamboman/mason.nvim' }, + { 'williamboman/mason-lspconfig.nvim' }, + + -- Autocompletion + { 'hrsh7th/nvim-cmp' }, + { 'hrsh7th/cmp-buffer' }, + { 'hrsh7th/cmp-path' }, + { 'saadparwaiz1/cmp_luasnip' }, + { 'hrsh7th/cmp-nvim-lsp' }, + { 'hrsh7th/cmp-nvim-lua' }, + + -- Snippets + { 'L3MON4D3/LuaSnip' }, + { 'rafamadriz/friendly-snippets' }, + } + }) + + use({ + 'lewis6991/gitsigns.nvim', + config = function() + require('gitsigns').setup() + end + }) + + use({ + 'nvim-lualine/lualine.nvim', + requires = { 'nvim-tree/nvim-web-devicons', opt = true } + }) + + use('Mofiqul/dracula.nvim') + + local wakatime_api_key = os.getenv("WAKATIME_API_KEY") + if wakatime_api_key then + use('wakatime/vim-wakatime') + end +end) diff --git a/.config/nvim/lua/user/remap.lua b/.config/nvim/lua/user/remap.lua new file mode 100644 index 0000000..15c67c5 --- /dev/null +++ b/.config/nvim/lua/user/remap.lua @@ -0,0 +1,26 @@ +vim.g.mapleader = " " + +vim.keymap.set("n", "pv", vim.cmd.Ex) + +vim.keymap.set("v", "J", ":m '>+1gv=gv") +vim.keymap.set("v", "K", ":m '<-2gv=gv") + +-- keep cursor centered in screen +vim.keymap.set("n", "", "zz") +vim.keymap.set("n", "", "zz") +vim.keymap.set("n", "n", "nzzzv") +vim.keymap.set("n", "N", "Nzzzv") + +-- paste, but don't overwrite buffer +vim.keymap.set("x", "p", "\"_dP") + +vim.keymap.set("n", "", "noh") + +vim.keymap.set("n", "f", vim.lsp.buf.format) + +vim.keymap.set("n", "", "cnextzz") +vim.keymap.set("n", "", "cprevzz") +vim.keymap.set("n", "k", "lnextzz") +vim.keymap.set("n", "j", "lprevzz") + +vim.keymap.set("n", "s", [[:%s/\<\>//gI]]) diff --git a/.config/nvim/lua/user/set.lua b/.config/nvim/lua/user/set.lua new file mode 100644 index 0000000..a63a6f2 --- /dev/null +++ b/.config/nvim/lua/user/set.lua @@ -0,0 +1,34 @@ +vim.opt.guicursor = "" + +vim.opt.nu = true +vim.opt.relativenumber = true + +vim.opt.tabstop = 4 +vim.opt.softtabstop = 4 +vim.opt.shiftwidth = 4 +vim.opt.expandtab = false + +vim.opt.splitbelow = true +vim.opt.splitright = true + +vim.opt.smartindent = true + +vim.opt.wrap = false + +vim.opt.swapfile = false +vim.opt.backup = false +vim.opt.undodir = os.getenv("HOME") .. "/.cache/vim/undo" +vim.opt.undofile = true + +vim.opt.hlsearch = true +vim.opt.incsearch = true + +vim.opt.termguicolors = true + +vim.opt.scrolloff = 8 +vim.opt.signcolumn = "yes" +vim.opt.isfname:append("@-@") + +vim.opt.updatetime = 50 + +vim.opt.colorcolumn = "80" diff --git a/.config/nvim/plugin/.gitignore b/.config/nvim/plugin/.gitignore new file mode 100644 index 0000000..d6b7ef3 --- /dev/null +++ b/.config/nvim/plugin/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore