From 02fe0217158bbcf686479e875b01e71794d37abb Mon Sep 17 00:00:00 2001 From: matt1432 Date: Fri, 27 Oct 2023 01:15:33 -0400 Subject: [PATCH] refactor(nvim): organise configs by plugin and some other stuff --- common/modules/neovim/base.vim | 26 ++++ common/modules/neovim/config/base.vim | 55 -------- common/modules/neovim/config/config.lua | 111 --------------- common/modules/neovim/default.nix | 135 ++++++++++++------- common/modules/neovim/plugins/autopairs.lua | 16 +++ common/modules/neovim/plugins/dracula.vim | 10 ++ common/modules/neovim/plugins/indent.lua | 21 +++ common/modules/neovim/plugins/lualine.lua | 6 + common/modules/neovim/plugins/minimap.lua | 13 ++ common/modules/neovim/plugins/neotree.lua | 37 +++++ common/modules/neovim/plugins/neotree.vim | 11 ++ common/modules/neovim/plugins/snippets.vim | 13 ++ common/modules/neovim/plugins/treesitter.vim | 17 +++ 13 files changed, 256 insertions(+), 215 deletions(-) create mode 100644 common/modules/neovim/base.vim delete mode 100644 common/modules/neovim/config/base.vim delete mode 100644 common/modules/neovim/config/config.lua create mode 100644 common/modules/neovim/plugins/autopairs.lua create mode 100644 common/modules/neovim/plugins/dracula.vim create mode 100644 common/modules/neovim/plugins/indent.lua create mode 100644 common/modules/neovim/plugins/lualine.lua create mode 100644 common/modules/neovim/plugins/minimap.lua create mode 100644 common/modules/neovim/plugins/neotree.lua create mode 100644 common/modules/neovim/plugins/neotree.vim create mode 100644 common/modules/neovim/plugins/snippets.vim create mode 100644 common/modules/neovim/plugins/treesitter.vim diff --git a/common/modules/neovim/base.vim b/common/modules/neovim/base.vim new file mode 100644 index 00000000..461559d0 --- /dev/null +++ b/common/modules/neovim/base.vim @@ -0,0 +1,26 @@ +" by default, the indent is 2 spaces. +set smartindent +set expandtab +set shiftwidth=2 +set softtabstop=2 +set tabstop=2 + +" for html/rb files, 2 spaces +autocmd Filetype html setlocal ts=2 sw=2 expandtab +autocmd Filetype ruby setlocal ts=2 sw=2 expandtab + +" for js/coffee/jade files, 4 spaces +autocmd Filetype javascript setlocal ts=4 sw=4 sts=0 expandtab +autocmd Filetype java setlocal ts=4 sw=4 sts=0 expandtab + +" support scss @ +autocmd FileType scss setl iskeyword+=@-@ + +set number +set relativenumber + +set undofile +set undodir=/home/matt/.cache/nvim/ + +" remove highlight on words +nnoremap :noh diff --git a/common/modules/neovim/config/base.vim b/common/modules/neovim/config/base.vim deleted file mode 100644 index b9097e43..00000000 --- a/common/modules/neovim/config/base.vim +++ /dev/null @@ -1,55 +0,0 @@ -" by default, the indent is 2 spaces. -set smartindent -set expandtab -set shiftwidth=2 -set softtabstop=2 -set tabstop=2 - -" for html/rb files, 2 spaces -autocmd Filetype html setlocal ts=2 sw=2 expandtab -autocmd Filetype ruby setlocal ts=2 sw=2 expandtab - -" for js/coffee/jade files, 4 spaces -autocmd Filetype javascript setlocal ts=4 sw=4 sts=0 expandtab -autocmd Filetype java setlocal ts=4 sw=4 sts=0 expandtab - -set number -set relativenumber - -set undofile -set undodir=/home/matt/.cache/nvim/ - -" set dot icon in place of trailing whitespaces -set list listchars=tab:\ \ ,nbsp:␣,trail:•,extends:⟩,precedes:⟨ - -" use vscode keybinds for snippets completion -inoremap - \ coc#pum#visible() ? coc#_select_confirm() : - \ coc#expandableOrJumpable() ? "\=coc#rpc#request('doKeymap', ['snippets-expand-jump',''])\" : - \ CheckBackspace() ? "\" : - \ coc#refresh() - -function! CheckBackspace() abort - let col = col('.') - 1 - return !col || getline('.')[col - 1] =~# '\s' -endfunction - -let g:coc_snippet_next = '' - -" support scss @ -autocmd FileType scss setl iskeyword+=@-@ - -" remove highlight on words -nnoremap :noh - -" Auto open Neo-Tree on big enough window -function! OpenTree() abort - if &columns > 100 - Neotree show - Neotree close - Neotree show - endif - lua MiniMap.open() -endfunction - -autocmd VimEnter * call OpenTree() diff --git a/common/modules/neovim/config/config.lua b/common/modules/neovim/config/config.lua deleted file mode 100644 index fad30cdc..00000000 --- a/common/modules/neovim/config/config.lua +++ /dev/null @@ -1,111 +0,0 @@ -vim.opt.fillchars = {eob = " "} -vim.cmd[[colorscheme dracula]] - --- https://github.com/AstroNvim/AstroNvim/issues/648#issuecomment-1511728897 - -vim.g.loaded_netrw = 0 -vim.g.loaded_netrwPlugin = 0 - --- https://github.com/nvim-neo-tree/neo-tree.nvim/issues/983#issuecomment-1637372234 - - -require'nvim-treesitter.configs'.setup { - 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, - }, -} - -require('gitsigns').setup() -require('lualine').setup { - options = { - theme = 'dracula', - globalstatus = true - } -} -require("neo-tree").setup({ - close_if_last_window = true, - enable_refresh_on_write = true, - window = { - width = 25, - }, - filesystem = { - use_libuv_file_watcher = true, - filtered_items = { - visible = false, - hide_dotfiles = false, - hide_gitignored = true, - hide_by_name = {}, - hide_by_pattern = {}, - always_show = {}, - never_show = {}, - never_show_by_pattern = {}, - }, - }, - source_selector = { - winbar = true, - statusline = false - }, - follow_current_file = { - enabled = true, - leave_dirs_open = true, - } -}) -require('todo-comments').setup() - --- Auto indent when pressing Enter between brackets -local remap = vim.api.nvim_set_keymap -local npairs = require('nvim-autopairs') -npairs.setup({map_cr=false}) - -_G.MUtils= {} - -MUtils.completion_confirm=function() - if vim.fn["coc#pum#visible"]() ~= 0 then - return vim.fn["coc#pum#confirm"]() - else - return npairs.autopairs_cr() - end -end - -remap('i' , '','v:lua.MUtils.completion_confirm()', {expr = true , noremap = true}) - --- Indent Blanklines -local highlight = { - "RainbowRed", - "RainbowYellow", - "RainbowBlue", - "RainbowOrange", - "RainbowGreen", - "RainbowViolet", - "RainbowCyan", -} - -local hooks = require "ibl.hooks" -hooks.register(hooks.type.HIGHLIGHT_SETUP, function() - vim.api.nvim_set_hl(0, "RainbowRed", { fg = "#E06C75" }) - vim.api.nvim_set_hl(0, "RainbowYellow", { fg = "#E5C07B" }) - vim.api.nvim_set_hl(0, "RainbowBlue", { fg = "#61AFEF" }) - vim.api.nvim_set_hl(0, "RainbowOrange", { fg = "#D19A66" }) - vim.api.nvim_set_hl(0, "RainbowGreen", { fg = "#98C379" }) - vim.api.nvim_set_hl(0, "RainbowViolet", { fg = "#C678DD" }) - vim.api.nvim_set_hl(0, "RainbowCyan", { fg = "#56B6C2" }) -end) - -require("ibl").setup { indent = { highlight = highlight } } - -local map = require('mini.map') - map.setup({ - integrations = { - map.gen_integration.builtin_search(), - map.gen_integration.gitsigns(), - map.gen_integration.diagnostic(), - }, - window = { - width = 7, - }, - }) diff --git a/common/modules/neovim/default.nix b/common/modules/neovim/default.nix index 1a2539f8..576ec7f3 100644 --- a/common/modules/neovim/default.nix +++ b/common/modules/neovim/default.nix @@ -9,13 +9,14 @@ inherit rev owner repo hash; }; }; -in - -{ - xdg.configFile = { - "../.gradle/gradle.properties".source = pkgs.writeText "gradle.properties" '' - org.gradle.java.home = ${pkgs.temurin-bin-17} - ''; + fileContents = lib.strings.fileContents; +in { + # TODO: make a gradle module and have java in hostvars.nix + xdg.dataFile = { + ".gradle/gradle.properties".source = + pkgs.writeText "gradle.properties" '' + org.gradle.java.home = ${pkgs.temurin-bin-17} + ''; }; home.packages = with pkgs; [ gradle @@ -40,14 +41,6 @@ in viAlias = true; vimAlias = true; - extraConfig = with lib.strings; '' - ${fileContents ./config/base.vim} - ''; - - extraLuaConfig = with lib.strings; '' - ${fileContents ./config/config.lua} - ''; - extraPackages = with pkgs; [ nodejs_latest nodePackages.npm @@ -75,7 +68,7 @@ in "eslint.format.enable" = true; "eslint.autoFixOnSave" = true; - # Stylelint FIXME: not working + # Stylelint "stylelintplus.enable" = true; "stylelintplus.cssInJs" = true; "stylelintplus.autoFixOnSave" = true; @@ -115,54 +108,98 @@ in }; }; + extraConfig = fileContents ./base.vim; + plugins = with pkgs.vimPlugins; [ - vim-which-key - - coc-java + # Coc configured coc-css + coc-eslint + coc-java + coc-sh + coc-stylelintplus + { + plugin = coc-snippets; + type = "viml"; + config = fileContents ./plugins/snippets.vim; + } - # Lua + ## Lua coc-sumneko-lua neodev-nvim + ## Fzf + coc-fzf + fzfWrapper + fzf-vim + coc-highlight coc-json coc-pyright - coc-sh - coc-snippets coc-vimlsp coc-yaml coc-toml coc-markdownlint coc-tsserver - coc-eslint - coc-stylelintplus - - coc-fzf - fzfWrapper - fzf-vim - - nvim-treesitter - nvim-treesitter.withAllGrammars - nvim-autopairs - - dracula-nvim - (plugin "lukas-reineke" - "indent-blankline.nvim" - "046e2cf04e08ece927bacbfb87c5b35c0b636546" - "sha256-bhoep8aTYje5K/dZ/XmpwBPn4PBEMPrmw33QJdfFe6M=") - gitsigns-nvim - lualine-nvim - (plugin "echasnovski" - "mini.map" - "75b7ca9443e17c852b24055b32f74a880cf48053" - "sha256-CoMc6yQXXAW1wzcD9eJGuM+kcOJghuwHjKrqEMxZBec=") - - neo-tree-nvim - - # to explore more fugitive - todo-comments-nvim + + { + plugin = dracula-nvim; + type = "viml"; + config = fileContents ./plugins/dracula.vim; + } + { + plugin = lualine-nvim; + type = "lua"; + config = fileContents ./plugins/lualine.lua; + } + { + plugin = todo-comments-nvim; + type = "lua"; + config = "require('todo-comments').setup()"; + } + { + plugin = gitsigns-nvim; + type = "lua"; + config = "require('gitsigns').setup()"; + } + { + plugin = nvim-autopairs; + type = "lua"; + config = fileContents ./plugins/autopairs.lua; + } + { + plugin = nvim-treesitter-context; + } + { + plugin = nvim-treesitter.withAllGrammars; + type = "viml"; + config = fileContents ./plugins/treesitter.vim; + } + { + plugin = (plugin "lukas-reineke" "indent-blankline.nvim" + "046e2cf04e08ece927bacbfb87c5b35c0b636546" + "sha256-bhoep8aTYje5K/dZ/XmpwBPn4PBEMPrmw33QJdfFe6M="); + type = "lua"; + config = fileContents ./plugins/indent.lua; + } + { + plugin = (plugin "echasnovski" "mini.map" + "75b7ca9443e17c852b24055b32f74a880cf48053" + "sha256-CoMc6yQXXAW1wzcD9eJGuM+kcOJghuwHjKrqEMxZBec="); + type = "lua"; + config = fileContents ./plugins/minimap.lua; + } + { + plugin = neo-tree-nvim; + type = "viml"; + config = '' + ${fileContents ./plugins/neotree.vim} + + lua << EOF + ${fileContents ./plugins/neotree.lua} + EOF + ''; + } ]; }; }; diff --git a/common/modules/neovim/plugins/autopairs.lua b/common/modules/neovim/plugins/autopairs.lua new file mode 100644 index 00000000..89604963 --- /dev/null +++ b/common/modules/neovim/plugins/autopairs.lua @@ -0,0 +1,16 @@ +-- Auto indent when pressing Enter between brackets +local remap = vim.api.nvim_set_keymap +local npairs = require('nvim-autopairs') +npairs.setup({map_cr=false}) + +_G.MUtils= {} + +MUtils.completion_confirm=function() + if vim.fn["coc#pum#visible"]() ~= 0 then + return vim.fn["coc#pum#confirm"]() + else + return npairs.autopairs_cr() + end +end + +remap('i' , '','v:lua.MUtils.completion_confirm()', {expr = true , noremap = true}) diff --git a/common/modules/neovim/plugins/dracula.vim b/common/modules/neovim/plugins/dracula.vim new file mode 100644 index 00000000..255b9182 --- /dev/null +++ b/common/modules/neovim/plugins/dracula.vim @@ -0,0 +1,10 @@ +" set dot icon in place of trailing whitespaces +set list listchars=tab:\ \ ,nbsp:␣,trail:•,extends:⟩,precedes:⟨ + + +lua << EOF +-- Add visual indicator for trailing whitespaces +vim.opt.fillchars = {eob = " "} + +vim.cmd[[colorscheme dracula]] +EOF diff --git a/common/modules/neovim/plugins/indent.lua b/common/modules/neovim/plugins/indent.lua new file mode 100644 index 00000000..71b492e9 --- /dev/null +++ b/common/modules/neovim/plugins/indent.lua @@ -0,0 +1,21 @@ +local highlight = { + "RainbowRed", + "RainbowYellow", + "RainbowBlue", + "RainbowOrange", + "RainbowGreen", + "RainbowViolet", + "RainbowCyan", +} +local hooks = require('ibl.hooks') +hooks.register(hooks.type.HIGHLIGHT_SETUP, function() + vim.api.nvim_set_hl(0, "RainbowRed", { fg = "#E06C75" }) + vim.api.nvim_set_hl(0, "RainbowYellow", { fg = "#E5C07B" }) + vim.api.nvim_set_hl(0, "RainbowBlue", { fg = "#61AFEF" }) + vim.api.nvim_set_hl(0, "RainbowOrange", { fg = "#D19A66" }) + vim.api.nvim_set_hl(0, "RainbowGreen", { fg = "#98C379" }) + vim.api.nvim_set_hl(0, "RainbowViolet", { fg = "#C678DD" }) + vim.api.nvim_set_hl(0, "RainbowCyan", { fg = "#56B6C2" }) +end) + +require('ibl').setup({ indent = { highlight = highlight } }) diff --git a/common/modules/neovim/plugins/lualine.lua b/common/modules/neovim/plugins/lualine.lua new file mode 100644 index 00000000..9fbfa9ed --- /dev/null +++ b/common/modules/neovim/plugins/lualine.lua @@ -0,0 +1,6 @@ +require('lualine').setup({ + options = { + theme = 'dracula', + globalstatus = true + } +}) diff --git a/common/modules/neovim/plugins/minimap.lua b/common/modules/neovim/plugins/minimap.lua new file mode 100644 index 00000000..3dcda911 --- /dev/null +++ b/common/modules/neovim/plugins/minimap.lua @@ -0,0 +1,13 @@ +local map = require('mini.map') +map.setup({ + integrations = { + map.gen_integration.builtin_search(), + map.gen_integration.gitsigns(), + map.gen_integration.diagnostic(), + }, + window = { + focusable = true, + width = 7, + winblend = 75, + }, +}) diff --git a/common/modules/neovim/plugins/neotree.lua b/common/modules/neovim/plugins/neotree.lua new file mode 100644 index 00000000..225cc4b5 --- /dev/null +++ b/common/modules/neovim/plugins/neotree.lua @@ -0,0 +1,37 @@ +-- Override netrw +vim.g.loaded_netrw = 0 +vim.g.loaded_netrwPlugin = 0 + +require('neo-tree').setup({ + close_if_last_window = true, + enable_refresh_on_write = true, + + window = { + width = 22, + }, + + filesystem = { + use_libuv_file_watcher = true, + + filtered_items = { + visible = false, + hide_dotfiles = false, + hide_gitignored = true, + hide_by_name = {}, + hide_by_pattern = {}, + always_show = {}, + never_show = {}, + never_show_by_pattern = {}, + }, + }, + + source_selector = { + winbar = true, + statusline = false + }, + + follow_current_file = { + enabled = true, + leave_dirs_open = true, + } +}) diff --git a/common/modules/neovim/plugins/neotree.vim b/common/modules/neovim/plugins/neotree.vim new file mode 100644 index 00000000..a02474b7 --- /dev/null +++ b/common/modules/neovim/plugins/neotree.vim @@ -0,0 +1,11 @@ +" Auto open Neo-Tree on big enough window +function! OpenTree() abort + if &columns > 100 + Neotree show + Neotree close + Neotree show + endif + lua MiniMap.open() +endfunction + +autocmd VimEnter * call OpenTree() diff --git a/common/modules/neovim/plugins/snippets.vim b/common/modules/neovim/plugins/snippets.vim new file mode 100644 index 00000000..3df084b6 --- /dev/null +++ b/common/modules/neovim/plugins/snippets.vim @@ -0,0 +1,13 @@ +" use vscode keybinds for snippets completion +inoremap + \ coc#pum#visible() ? coc#_select_confirm() : + \ coc#expandableOrJumpable() ? "\=coc#rpc#request('doKeymap', ['snippets-expand-jump',''])\" : + \ CheckBackspace() ? "\" : + \ coc#refresh() + +function! CheckBackspace() abort + let col = col('.') - 1 + return !col || getline('.')[col - 1] =~# '\s' +endfunction + +let g:coc_snippet_next = '' diff --git a/common/modules/neovim/plugins/treesitter.vim b/common/modules/neovim/plugins/treesitter.vim new file mode 100644 index 00000000..2801be8d --- /dev/null +++ b/common/modules/neovim/plugins/treesitter.vim @@ -0,0 +1,17 @@ +lua << EOF + +require('nvim-treesitter.configs').setup({ + highlight = { enable = true }, + indent = { enable = true } +}) + +require('treesitter-context').setup({ + enable = true, + max_lines = 3, + min_window_height = 20, +}) + +EOF + +" Add line under context +hi TreesitterContextBottom gui=underline guisp=Grey