From 629d64295233ee5d82c9a83069c3cda907bbc22e Mon Sep 17 00:00:00 2001 From: Max Hohlfeld Date: Sun, 8 Sep 2024 12:09:52 +0200 Subject: [PATCH] feat: general overhaul and additional tweaks --- roles/nvim/files/init_pc.lua | 173 +++++++++++++++++++++++------------ 1 file changed, 116 insertions(+), 57 deletions(-) diff --git a/roles/nvim/files/init_pc.lua b/roles/nvim/files/init_pc.lua index f546b7c..453bf81 100644 --- a/roles/nvim/files/init_pc.lua +++ b/roles/nvim/files/init_pc.lua @@ -13,43 +13,44 @@ if fn.empty(fn.glob(install_path)) > 0 then end require('packer').startup(function() - use 'wbthomason/packer.nvim' -- Package Manager - use 'nvim-lua/plenary.nvim' -- Lua Library - use 'neovim/nvim-lspconfig' -- Language Server Config + use 'wbthomason/packer.nvim' -- Package Manager + use 'nvim-lua/plenary.nvim' -- Lua Library + use 'neovim/nvim-lspconfig' -- Language Server Config use { - 'hrsh7th/nvim-cmp', -- Completion + 'hrsh7th/nvim-cmp', -- Completion requires = { - 'hrsh7th/cmp-buffer', -- Completion source buffer - 'hrsh7th/cmp-nvim-lsp', -- Completion source LSP - 'hrsh7th/cmp-path', -- Completion source filepaths - 'hrsh7th/cmp-cmdline', -- Completion source for commandline + 'hrsh7th/cmp-buffer', -- Completion source buffer + 'hrsh7th/cmp-nvim-lsp', -- Completion source LSP + 'hrsh7th/cmp-path', -- Completion source filepaths + 'hrsh7th/cmp-cmdline', -- Completion source for commandline 'saadparwaiz1/cmp_luasnip', -- Completion source snippets - 'ray-x/lsp_signature.nvim' -- Signature when typing + 'ray-x/lsp_signature.nvim' -- Signature when typing } } - use { 'L3MON4D3/LuaSnip' } -- Snippets + use { 'L3MON4D3/LuaSnip' } -- Snippets use { 'nvim-treesitter/nvim-treesitter', -- Syntax Highlighting run = ':TSUpdate' } - use 'tpope/vim-surround' -- Surrounding - use 'tpope/vim-repeat' -- Repeat Surrounding - use 'tpope/vim-sleuth' -- Detect Spacing - use 'kdheepak/lazygit.nvim' -- Git Client - use "tversteeg/registers.nvim" -- Preview Registers - use 'windwp/nvim-autopairs' -- Autopairs - use 'windwp/nvim-ts-autotag' -- HTML Autopairs + use 'tpope/vim-surround' -- Surrounding + use 'tpope/vim-repeat' -- Repeat Surrounding + use 'tpope/vim-sleuth' -- Detect Spacing + use 'kdheepak/lazygit.nvim' -- Git Client + use "tversteeg/registers.nvim" -- Preview Registers + use 'windwp/nvim-autopairs' -- Autopairs + use 'windwp/nvim-ts-autotag' -- HTML Autopairs use 'nvim-telescope/telescope.nvim' -- Fuzzy Finder - use 'tamago324/lir.nvim' -- Filebrowser - use 'jakewvincent/mkdnflow.nvim' -- Notetaking - use 'norcalli/nvim-colorizer.lua' -- render Color Codes - use 'aklt/plantuml-syntax' -- Plantuml Syntax, till treesitter supports Plantuml - use 'ggandor/leap.nvim' -- Jump around in file - use 'mfussenegger/nvim-dap' -- Debugger Adapter Protocol - use 'rcarriga/nvim-dap-ui' -- UI for DAP - use 'nvim-neotest/nvim-nio' -- for nvim-dap-ui - use 'phha/zenburn.nvim' -- zenburn coloursheme - use 'rmagatti/auto-session' -- session management + use 'tamago324/lir.nvim' -- Filebrowser + use 'jakewvincent/mkdnflow.nvim' -- Notetaking + use 'norcalli/nvim-colorizer.lua' -- render Color Codes + use 'aklt/plantuml-syntax' -- Plantuml Syntax, till treesitter supports Plantuml + use 'ggandor/leap.nvim' -- Jump around in file + use 'mfussenegger/nvim-dap' -- Debugger Adapter Protocol + use 'rcarriga/nvim-dap-ui' -- UI for DAP + use 'nvim-neotest/nvim-nio' -- for nvim-dap-ui + use '~/projekte/zenburn.nvim' -- zenburn coloursheme + use 'rmagatti/auto-session' -- session management + use 'gbprod/substitute.nvim' -- substitue objects with yanked register without copying into register end) -- General Editor Settings @@ -67,6 +68,7 @@ opt.completeopt = 'menuone,noinsert,noselect' map('n', 'w', 'w', { noremap = true }) map('n', 'q', 'wq', { noremap = true }) +map('n', 'Q', 'wqa', { noremap = true }) map('n', '', 'let @/ = ""', { noremap = true }) -- fix interpreting C-I as Tab @@ -93,6 +95,36 @@ autocmd({ 'BufNewFile', 'BufRead' }, { vim.cmd("au BufRead *.yaml,*.yml if search('hosts:\\|tasks:\\|ansible.builtin', 'nw') | set ft=yaml.ansible | endif") +autocmd("FileType", { + desc = "Close some file types with q", + pattern = { + "help", + "lspinfo", + "notify", + "qf", + "query", + "checkhealth", + }, + callback = function(event) + vim.bo[event.buf].buflisted = false + buf_map(event.buf, + 'n', + 'q', + 'close', + { silent = true, noremap = true } + ) + end, +}) + +autocmd({ "VimResized" }, { + desc = "Resize splits if window got resized", + callback = function() + local current_tab = vim.fn.tabpagenr() + vim.cmd("tabdo wincmd =") + vim.cmd("tabnext " .. current_tab) + end, +}) + -- Spellcheck _G.enable_spell = function(lang) vim.bo.spelllang = lang @@ -151,7 +183,8 @@ end local capabilities = require("cmp_nvim_lsp").default_capabilities() -local servers = { 'rust_analyzer', 'texlab', 'pyright', 'tsserver', 'ccls', 'html', 'yamlls', 'ansiblels', 'hls', 'cssls', 'eslint' } +local servers = { 'rust_analyzer', 'texlab', 'pyright', 'ts_ls', 'ccls', 'html', 'yamlls', 'ansiblels', 'hls', 'cssls', + 'eslint' } for _, server in ipairs(servers) do lsp[server].setup { on_attach = on_attach, @@ -196,9 +229,6 @@ lsp.lua_ls.setup { }, } --- Autopairs -require 'nvim-autopairs'.setup {} - -- Snippets local ls = require('luasnip') local types = require('luasnip.util.types') @@ -290,13 +320,21 @@ require('nvim-treesitter.configs').setup { highlight = { enable = true, additional_vim_regex_highlighting = false, - }, - autotag = { - enable = true, - filetypes = { 'html', 'htmldjango', 'xml', 'javascript', 'typescript', 'javascriptreact', 'typescriptreact', 'svelte', 'vue' } } } +-- Treesitter Autotag +require('nvim-ts-autotag').setup({ + opts = { + enable_close = true, + enable_rename = true, + enable_close_on_slash = false + } +}) + +-- Autopairs +require 'nvim-autopairs'.setup {} + -- Telescope map('n', 'ff', 'lua require("telescope.builtin").find_files()', { noremap = true }) map('n', 'fg', 'lua require("telescope.builtin").live_grep()', { noremap = true }) @@ -311,7 +349,7 @@ require('mkdnflow').setup({ }, mappings = { MkdnEnter = { { 'i', 'n', 'v' }, '' }, - MkdnCreateLinkFromClipboard = {{'n', 'v'}, 'l'}, + MkdnCreateLinkFromClipboard = { { 'n', 'v' }, 'l' }, }, perspective = { priority = 'current', @@ -328,6 +366,18 @@ require('mkdnflow').setup({ } }) +vim.keymap.set('n', 'wd', function() + local date_string = os.date("%Y-%m-%d") + local path = '/home/max/dokumente/wiki/todos/' .. date_string .. '.md' + + vim.cmd.tabedit(path) + if vim.fn.getfsize(path) < 1 then + vim.api.nvim_put({ "# Todo - " .. date_string, "- [ ] " }, 'c', false, true) + end + vim.cmd.write() +end, { noremap = true }) + + autocmd({ 'BufRead', 'BufNewFile' }, { desc = 'Set note taking settings for nvim in wiki directory', pattern = { '*/dokumente/wiki/**' }, @@ -350,16 +400,16 @@ require('lir').setup { [''] = actions.vsplit, [''] = actions.tabedit, - ['h'] = actions.up, - ['q'] = actions.quit, + ['h'] = actions.up, + ['q'] = actions.quit, - ['nd'] = actions.mkdir, - ['nf'] = actions.newfile, - ['R'] = actions.rename, - ['@'] = actions.cd, - ['Y'] = actions.yank_path, - ['.'] = actions.toggle_show_hidden, - ['x'] = actions.delete, + ['nd'] = actions.mkdir, + ['nf'] = actions.newfile, + ['R'] = actions.rename, + ['@'] = actions.cd, + ['Y'] = actions.yank_path, + ['.'] = actions.toggle_show_hidden, + ['x'] = actions.delete, }, float = { winblend = 0, @@ -383,21 +433,23 @@ vim.g.loaded_netrwPlugin = 1 -- Colorizer require('colorizer').setup({ - '*'; + '*', }, { - RGB = true; -- #RGB hex codes - RRGGBB = true; -- #RRGGBB hex codes - names = false; -- "Name" codes like Blue - RRGGBBAA = true; -- #RRGGBBAA hex codes - rgb_fn = true; -- CSS rgb() and rgba() functions - hsl_fn = true; -- CSS hsl() and hsla() functions - css = false; -- Enable all CSS features: rgb_fn, hsl_fn, names, RGB, RRGGBB - css_fn = false; -- Enable all CSS *functions*: rgb_fn, hsl_fn - mode = 'background'; -- Set the display mode. + RGB = true, -- #RGB hex codes + RRGGBB = true, -- #RRGGBB hex codes + names = false, -- "Name" codes like Blue + RRGGBBAA = true, -- #RRGGBBAA hex codes + rgb_fn = true, -- CSS rgb() and rgba() functions + hsl_fn = true, -- CSS hsl() and hsla() functions + css = false, -- Enable all CSS features: rgb_fn, hsl_fn, names, RGB, RRGGBB + css_fn = false, -- Enable all CSS *functions*: rgb_fn, hsl_fn + mode = 'background', -- Set the display mode. }) -- Leap -require('leap').add_default_mappings() +vim.keymap.set({ 'n', 'x', 'o' }, 'ö', '(leap-forward)') +vim.keymap.set({ 'n', 'x', 'o' }, 'Ö', '(leap-backward)') +vim.keymap.set({ 'n', 'x', 'o' }, 'gö', '(leap-from-window)') -- Debugger Adapter Protocol local dap = require('dap') @@ -443,4 +495,11 @@ require("auto-session").setup { log_level = "error" } --- opt.sessionoptions = "blank,buffers,curdir,folds,help,tabpages,winsize,winpos,terminal" +opt.sessionoptions = "blank,buffers,curdir,folds,help,tabpages,winsize,terminal,localoptions" + +-- Substitute +require("substitute").setup() +vim.keymap.set('n', 's', require('substitute').operator, { noremap = true }) +vim.keymap.set('n', 'ss', require('substitute').line, { noremap = true }) +vim.keymap.set('n', 'S', require('substitute').eol, { noremap = true }) +vim.keymap.set('x', 's', require('substitute').visual, { noremap = true })