From b902dae54988f232bf9d66bdf6a4a14d31302dfc Mon Sep 17 00:00:00 2001 From: Georg Krause Date: Thu, 7 Dec 2023 17:27:34 +0100 Subject: [PATCH] Add neovim config --- .config/nvim/.netrwhist | 9 ++ .config/nvim/ftdetect/html.j2.vim | 1 + .config/nvim/init.lua | 65 +++++++++++ .config/nvim/lua/gitsigns-config.lua | 40 +++++++ .config/nvim/lua/lsp.lua | 50 ++++++++ .config/nvim/lua/nvim-tree.config.lua | 0 .config/nvim/lua/plugins.lua | 17 +++ .config/nvim/plugin/packer_compiled.lua | 149 ++++++++++++++++++++++++ 8 files changed, 331 insertions(+) create mode 100644 .config/nvim/.netrwhist create mode 100644 .config/nvim/ftdetect/html.j2.vim create mode 100644 .config/nvim/init.lua create mode 100644 .config/nvim/lua/gitsigns-config.lua create mode 100644 .config/nvim/lua/lsp.lua create mode 100644 .config/nvim/lua/nvim-tree.config.lua create mode 100644 .config/nvim/lua/plugins.lua create mode 100644 .config/nvim/plugin/packer_compiled.lua diff --git a/.config/nvim/.netrwhist b/.config/nvim/.netrwhist new file mode 100644 index 0000000..167c2c2 --- /dev/null +++ b/.config/nvim/.netrwhist @@ -0,0 +1,9 @@ +let g:netrw_dirhistmax =10 +let g:netrw_dirhistcnt =7 +let g:netrw_dirhist_7='/home/georg/workspace' +let g:netrw_dirhist_6='/home/georg/workspace/openAV-Luppp/src' +let g:netrw_dirhist_5='/home/georg/workspace/openAV-Luppp' +let g:netrw_dirhist_4='/home/georg/workspace' +let g:netrw_dirhist_3='/home/georg' +let g:netrw_dirhist_2='/home/georg/backup-handy' +let g:netrw_dirhist_1='/home/georg' diff --git a/.config/nvim/ftdetect/html.j2.vim b/.config/nvim/ftdetect/html.j2.vim new file mode 100644 index 0000000..bab18db --- /dev/null +++ b/.config/nvim/ftdetect/html.j2.vim @@ -0,0 +1 @@ +au BufRead,BufNewFile *.html.j2 set filetype=html diff --git a/.config/nvim/init.lua b/.config/nvim/init.lua new file mode 100644 index 0000000..b617d46 --- /dev/null +++ b/.config/nvim/init.lua @@ -0,0 +1,65 @@ +vim.opt.termguicolors = true +vim.opt.number = true +vim.opt.relativenumber = true +vim.opt.hlsearch = true +vim.opt.ignorecase = true +vim.opt.tabstop = 2 +vim.opt.shiftwidth = 2 +vim.opt.expandtab = true + +vim.g.loaded_netrw = 1 +vim.g.loaded_netrwPlugin = 1 + +vim.g.neon_style = "doom" +vim.g.neon_italic_keyword = true +vim.g.neon_italic_function = true +vim.g.neon_transparent = true + +vim.cmd[[colorscheme neon]] + +require('plugins') +require('gitsigns-config') +require('lsp') +require('nvim-tree').setup({ + update_focused_file = { + enable = true + } +}) + +local function open_nvim_tree(data) + + -- buffer is a [No Name] + local no_name = data.file == "" and vim.bo[data.buf].buftype == "" + + -- buffer is a directory + local directory = vim.fn.isdirectory(data.file) == 1 + + if not no_name and not directory then + return + end + + -- change to the directory + if directory then + vim.cmd.cd(data.file) + end + + -- open the tree + require("nvim-tree.api").tree.open() +end + +vim.api.nvim_create_autocmd({ "VimEnter" }, { callback = open_nvim_tree }) + +require'nvim-treesitter.configs'.setup { + highlight = { + enable = true, + additional_vim_regex_highlighting = false, + }, + indent = { + enable = true + } +} + +-- Configure highlighting of current file +local c = require("neon.colors") +vim.opt.cursorline = true +vim.api.nvim_set_hl(0, "CursorLine", { bg=c.bg0, underline = None }) diff --git a/.config/nvim/lua/gitsigns-config.lua b/.config/nvim/lua/gitsigns-config.lua new file mode 100644 index 0000000..be7bc47 --- /dev/null +++ b/.config/nvim/lua/gitsigns-config.lua @@ -0,0 +1,40 @@ +return require('gitsigns').setup{ + on_attach = function(bufnr) + local gs = package.loaded.gitsigns + + local function map(mode, l, r, opts) + opts = opts or {} + opts.buffer = bufnr + vim.keymap.set(mode, l, r, opts) + end + + -- Navigation + map('n', ']c', function() + if vim.wo.diff then return ']c' end + vim.schedule(function() gs.next_hunk() end) + return '' + end, {expr=true}) + + map('n', '[c', function() + if vim.wo.diff then return '[c' end + vim.schedule(function() gs.prev_hunk() end) + return '' + end, {expr=true}) + + -- Actions + map({'n', 'v'}, 'hs', ':Gitsigns stage_hunk') + map({'n', 'v'}, 'hr', ':Gitsigns reset_hunk') + map('n', 'hS', gs.stage_buffer) + map('n', 'hu', gs.undo_stage_hunk) + map('n', 'hR', gs.reset_buffer) + map('n', 'hp', gs.preview_hunk) + map('n', 'hb', function() gs.blame_line{full=true} end) + map('n', 'tb', gs.toggle_current_line_blame) + map('n', 'hd', gs.diffthis) + map('n', 'hD', function() gs.diffthis('~') end) + map('n', 'td', gs.toggle_deleted) + + -- Text object + map({'o', 'x'}, 'ih', ':Gitsigns select_hunk') + end +} diff --git a/.config/nvim/lua/lsp.lua b/.config/nvim/lua/lsp.lua new file mode 100644 index 0000000..2e5da3c --- /dev/null +++ b/.config/nvim/lua/lsp.lua @@ -0,0 +1,50 @@ +-- Mappings. +-- 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, opts) +vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, opts) +vim.keymap.set('n', ']d', vim.diagnostic.goto_next, opts) +vim.keymap.set('n', 'q', vim.diagnostic.setloclist, 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') + + -- Mappings. + -- 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', '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) + vim.keymap.set('n', 'gr', vim.lsp.buf.references, bufopts) + vim.keymap.set('n', 'f', function() vim.lsp.buf.format { async = true } end, bufopts) +end + +local lsp_flags = { + -- This is the default in Nvim 0.7+ + debounce_text_changes = 150, +} +require('lspconfig')['pyright'].setup{ + on_attach = on_attach, + flags = lsp_flags, +} +require('lspconfig')['tsserver'].setup{ + on_attach = on_attach, + flags = lsp_flags, +} +require('lspconfig')['svelte'].setup{ + on_attach = on_attach, + flags = lsp_flags, +} diff --git a/.config/nvim/lua/nvim-tree.config.lua b/.config/nvim/lua/nvim-tree.config.lua new file mode 100644 index 0000000..e69de29 diff --git a/.config/nvim/lua/plugins.lua b/.config/nvim/lua/plugins.lua new file mode 100644 index 0000000..ee9e17d --- /dev/null +++ b/.config/nvim/lua/plugins.lua @@ -0,0 +1,17 @@ +vim.cmd [[packadd packer.nvim]] + +return require('packer').startup(function(use) + use 'wbthomason/packer.nvim' + use 'lewis6991/gitsigns.nvim' + use 'posva/vim-vue' + use 'editorconfig/editorconfig-vim' + use 'neovim/nvim-lspconfig' + use 'nvim-tree/nvim-tree.lua' + use 'nvim-tree/nvim-web-devicons' + use 'nvim-treesitter/nvim-treesitter' + use 'rafamadriz/neon' + use { + 'nvim-telescope/telescope.nvim', + requires = { {'nvim-lua/plenary.nvim'} } + } +end) diff --git a/.config/nvim/plugin/packer_compiled.lua b/.config/nvim/plugin/packer_compiled.lua new file mode 100644 index 0000000..15ff109 --- /dev/null +++ b/.config/nvim/plugin/packer_compiled.lua @@ -0,0 +1,149 @@ +-- Automatically generated packer.nvim plugin loader code + +if vim.api.nvim_call_function('has', {'nvim-0.5'}) ~= 1 then + vim.api.nvim_command('echohl WarningMsg | echom "Invalid Neovim version for packer.nvim! | echohl None"') + return +end + +vim.api.nvim_command('packadd packer.nvim') + +local no_errors, error_msg = pcall(function() + +_G._packer = _G._packer or {} +_G._packer.inside_compile = true + +local time +local profile_info +local should_profile = false +if should_profile then + local hrtime = vim.loop.hrtime + profile_info = {} + time = function(chunk, start) + if start then + profile_info[chunk] = hrtime() + else + profile_info[chunk] = (hrtime() - profile_info[chunk]) / 1e6 + end + end +else + time = function(chunk, start) end +end + +local function save_profiles(threshold) + local sorted_times = {} + for chunk_name, time_taken in pairs(profile_info) do + sorted_times[#sorted_times + 1] = {chunk_name, time_taken} + end + table.sort(sorted_times, function(a, b) return a[2] > b[2] end) + local results = {} + for i, elem in ipairs(sorted_times) do + if not threshold or threshold and elem[2] > threshold then + results[i] = elem[1] .. ' took ' .. elem[2] .. 'ms' + end + end + if threshold then + table.insert(results, '(Only showing plugins that took longer than ' .. threshold .. ' ms ' .. 'to load)') + end + + _G._packer.profile_output = results +end + +time([[Luarocks path setup]], true) +local package_path_str = "/home/georg/.cache/nvim/packer_hererocks/2.1.1700008891/share/lua/5.1/?.lua;/home/georg/.cache/nvim/packer_hererocks/2.1.1700008891/share/lua/5.1/?/init.lua;/home/georg/.cache/nvim/packer_hererocks/2.1.1700008891/lib/luarocks/rocks-5.1/?.lua;/home/georg/.cache/nvim/packer_hererocks/2.1.1700008891/lib/luarocks/rocks-5.1/?/init.lua" +local install_cpath_pattern = "/home/georg/.cache/nvim/packer_hererocks/2.1.1700008891/lib/lua/5.1/?.so" +if not string.find(package.path, package_path_str, 1, true) then + package.path = package.path .. ';' .. package_path_str +end + +if not string.find(package.cpath, install_cpath_pattern, 1, true) then + package.cpath = package.cpath .. ';' .. install_cpath_pattern +end + +time([[Luarocks path setup]], false) +time([[try_loadstring definition]], true) +local function try_loadstring(s, component, name) + local success, result = pcall(loadstring(s), name, _G.packer_plugins[name]) + if not success then + vim.schedule(function() + vim.api.nvim_notify('packer.nvim: Error running ' .. component .. ' for ' .. name .. ': ' .. result, vim.log.levels.ERROR, {}) + end) + end + return result +end + +time([[try_loadstring definition]], false) +time([[Defining packer_plugins]], true) +_G.packer_plugins = { + ["editorconfig-vim"] = { + loaded = true, + path = "/home/georg/.local/share/nvim/site/pack/packer/start/editorconfig-vim", + url = "https://github.com/editorconfig/editorconfig-vim" + }, + ["gitsigns.nvim"] = { + loaded = true, + path = "/home/georg/.local/share/nvim/site/pack/packer/start/gitsigns.nvim", + url = "https://github.com/lewis6991/gitsigns.nvim" + }, + neon = { + loaded = true, + path = "/home/georg/.local/share/nvim/site/pack/packer/start/neon", + url = "https://github.com/rafamadriz/neon" + }, + ["nvim-lspconfig"] = { + loaded = true, + path = "/home/georg/.local/share/nvim/site/pack/packer/start/nvim-lspconfig", + url = "https://github.com/neovim/nvim-lspconfig" + }, + ["nvim-tree.lua"] = { + loaded = true, + path = "/home/georg/.local/share/nvim/site/pack/packer/start/nvim-tree.lua", + url = "https://github.com/nvim-tree/nvim-tree.lua" + }, + ["nvim-treesitter"] = { + loaded = true, + path = "/home/georg/.local/share/nvim/site/pack/packer/start/nvim-treesitter", + url = "https://github.com/nvim-treesitter/nvim-treesitter" + }, + ["nvim-web-devicons"] = { + loaded = true, + path = "/home/georg/.local/share/nvim/site/pack/packer/start/nvim-web-devicons", + url = "https://github.com/nvim-tree/nvim-web-devicons" + }, + ["packer.nvim"] = { + loaded = true, + path = "/home/georg/.local/share/nvim/site/pack/packer/start/packer.nvim", + url = "https://github.com/wbthomason/packer.nvim" + }, + ["plenary.nvim"] = { + loaded = true, + path = "/home/georg/.local/share/nvim/site/pack/packer/start/plenary.nvim", + url = "https://github.com/nvim-lua/plenary.nvim" + }, + ["telescope.nvim"] = { + loaded = true, + path = "/home/georg/.local/share/nvim/site/pack/packer/start/telescope.nvim", + url = "https://github.com/nvim-telescope/telescope.nvim" + }, + ["vim-vue"] = { + loaded = true, + path = "/home/georg/.local/share/nvim/site/pack/packer/start/vim-vue", + url = "https://github.com/posva/vim-vue" + } +} + +time([[Defining packer_plugins]], false) + +_G._packer.inside_compile = false +if _G._packer.needs_bufread == true then + vim.cmd("doautocmd BufRead") +end +_G._packer.needs_bufread = false + +if should_profile then save_profiles() end + +end) + +if not no_errors then + error_msg = error_msg:gsub('"', '\\"') + vim.api.nvim_command('echohl ErrorMsg | echom "Error in packer_compiled: '..error_msg..'" | echom "Please check your config for correctness" | echohl None') +end