From e511f8e110fa5200d667ebee2e7403dbe98721ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Ko=C4=8D=C3=AD?= Date: Wed, 13 Mar 2024 10:52:06 +0100 Subject: nvim: switch from ale and other tweaks --- config/nvim/ftplugin/c.vim | 7 -- config/nvim/ftplugin/cpp.vim | 8 -- config/nvim/ftplugin/json.vim | 1 - config/nvim/ftplugin/lua.vim | 2 - config/nvim/ftplugin/nix.vim | 5 -- config/nvim/ftplugin/python.vim | 2 - config/nvim/ftplugin/sh.vim | 2 - config/nvim/ftplugin/tex.vim | 1 - config/nvim/init.vim | 47 ++++++---- config/nvim/lua/plugins.lua | 191 +++++++++++++++++++++++++++------------- 10 files changed, 164 insertions(+), 102 deletions(-) delete mode 100644 config/nvim/ftplugin/c.vim delete mode 100644 config/nvim/ftplugin/cpp.vim delete mode 100644 config/nvim/ftplugin/json.vim delete mode 100644 config/nvim/ftplugin/lua.vim delete mode 100644 config/nvim/ftplugin/nix.vim delete mode 100644 config/nvim/ftplugin/python.vim delete mode 100644 config/nvim/ftplugin/sh.vim delete mode 100644 config/nvim/ftplugin/tex.vim diff --git a/config/nvim/ftplugin/c.vim b/config/nvim/ftplugin/c.vim deleted file mode 100644 index 3769d80..0000000 --- a/config/nvim/ftplugin/c.vim +++ /dev/null @@ -1,7 +0,0 @@ -let b:ale_linters = ['cppcheck', 'flawfinder'] -let b:ale_fixers = ['clang-format', 'remove_trailing_lines', 'trim_whitespace'] -let g:ale_c_parse_compile_commands = 1 -let g:ale_c_clangd_options = '--header-insertion=never' - -nmap :ALENext -nmap :ALEPrevious diff --git a/config/nvim/ftplugin/cpp.vim b/config/nvim/ftplugin/cpp.vim deleted file mode 100644 index 89944ea..0000000 --- a/config/nvim/ftplugin/cpp.vim +++ /dev/null @@ -1,8 +0,0 @@ -" This is for C but vim defines *.h as cpp type so here we have it -let b:ale_linters = ['ccls', 'cppcheck', 'flawfinder'] -let b:ale_fixers = ['clang-format', 'remove_trailing_lines', 'trim_whitespace'] -let g:ale_cpp_ccls_init_options = {'cache': {'directory': '/tmp/ccls/cache'}} -let g:ale_cpp_parse_compile_commands = 1 - -nmap :ALENext -nmap :ALEPrevious diff --git a/config/nvim/ftplugin/json.vim b/config/nvim/ftplugin/json.vim deleted file mode 100644 index 829a37e..0000000 --- a/config/nvim/ftplugin/json.vim +++ /dev/null @@ -1 +0,0 @@ -let b:ale_fixers = ['jq'] diff --git a/config/nvim/ftplugin/lua.vim b/config/nvim/ftplugin/lua.vim deleted file mode 100644 index 733962a..0000000 --- a/config/nvim/ftplugin/lua.vim +++ /dev/null @@ -1,2 +0,0 @@ -let b:ale_linters = ['luacheck', 'selene', 'luac'] -let b:ale_fixers = ['stylua', 'remove_trailing_lines', 'trim_whitespace'] diff --git a/config/nvim/ftplugin/nix.vim b/config/nvim/ftplugin/nix.vim deleted file mode 100644 index 48be358..0000000 --- a/config/nvim/ftplugin/nix.vim +++ /dev/null @@ -1,5 +0,0 @@ -let b:ale_linters = ['nix', 'statix'] -let b:ale_fixers = ['alejandra', 'remove_trailing_lines', 'trim_whitespace'] - -nmap :ALENext -nmap :ALEPrevious diff --git a/config/nvim/ftplugin/python.vim b/config/nvim/ftplugin/python.vim deleted file mode 100644 index 94b035a..0000000 --- a/config/nvim/ftplugin/python.vim +++ /dev/null @@ -1,2 +0,0 @@ -let b:ale_linters = ['pylint', 'mypy', 'pydocstyle'] -let b:ale_fixers = ['isort', 'black', 'remove_trailing_lines', 'trim_whitespace'] diff --git a/config/nvim/ftplugin/sh.vim b/config/nvim/ftplugin/sh.vim deleted file mode 100644 index 8cc42e2..0000000 --- a/config/nvim/ftplugin/sh.vim +++ /dev/null @@ -1,2 +0,0 @@ -let b:ale_linters = ['shell', 'shellcheck'] -let b:ale_fixers = ['shfmt', 'trim_whitespace', 'remove_trailing_lines'] diff --git a/config/nvim/ftplugin/tex.vim b/config/nvim/ftplugin/tex.vim deleted file mode 100644 index 5eb1926..0000000 --- a/config/nvim/ftplugin/tex.vim +++ /dev/null @@ -1 +0,0 @@ -let b:ale_linters = ['lacheck'] diff --git a/config/nvim/init.vim b/config/nvim/init.vim index 1d0e6c6..491ae47 100644 --- a/config/nvim/init.vim +++ b/config/nvim/init.vim @@ -28,11 +28,36 @@ set backspace=indent,eol,start set completeopt=menu,menuone,preview,noselect,noinsert colorscheme nord -let g:lightline = { 'colorscheme': 'nord' } +let g:lightline = { +\ 'colorscheme': 'nord', +\ 'active': { +\ 'left': [ +\ [ 'mode', 'paste' ], +\ [ 'lsp_info', 'lsp_hints', 'lsp_errors', 'lsp_warnings', 'lsp_ok' ], +\ [ 'lsp_status' ], +\ [ 'readonly', 'filename', 'modified' ], +\ ] +\ }, +\ 'component': { +\ 'lineinfo': ' %3l:%-2v', +\ }, +\ 'component_function': { +\ 'readonly': 'LightlineReadonly', +\ }, +\ 'separator': { 'left': '', 'right': '' }, +\ 'subseparator': { 'left': '', 'right': '' } +\ } +function! LightlineReadonly() + return &readonly ? '' : '' +endfunction +call lightline#lsp#register() +set laststatus=2 +set noshowmode set number set colorcolumn=80 set textwidth=80 +nmap :noh " Tabs setting. In default we want 4 spaces tab, but allows also 8 spaced tabs @@ -74,6 +99,9 @@ nnoremap :Explore nnoremap l :bnext nnoremap h :bprev +" Format +nmap f :lua require("conform").format() + " Setup gitgutter set updatetime=100 highlight GitGutterAdd ctermfg=2 @@ -84,9 +112,6 @@ highlight GitGutterDelete ctermfg=1 " Note: to start use "\ t m" let g:table_mode_corner='|' -" Open tagbar with -nmap :TagbarOpen fc - " Spell checking map :setlocal spell! function LangToggle() @@ -109,20 +134,15 @@ let g:UltiSnipsExpandTrigger='' let g:UltiSnipsJumpForwardTrigger='' let g:UltiSnipsJumpBackwardTrigger='' -" ALE -let g:ale_set_baloons = 1 -let g:ale_floating_preview = 1 -let g:ale_use_neovim_diagnostics_api = 1 -nmap f (ale_fix) - " Telescope nnoremap :Telescope buffers -nnoremap ":call TelescopeFiles()".expand('%:h')."/" +nnoremap :call TelescopeFiles() nnoremap :Telescope lsp_document_symbols nmap ] :Telescope lsp_definitions nmap ] :Telescope lsp_type_definitions nmap [ :Telescope lsp_implementations nmap [ :Telescope lsp_references +nmap :Telescope diagnostics bufnr=0 function TelescopeFiles() if stridx(system('git rev-parse --is-inside-work-tree 2>/dev/null || true'), 'true') != -1 lua require('telescope.builtin').git_files{use_file_path=true,git_command={"sh","-c","git ls-files -c --recurse-submodules && git ls-files -o --exclude-standard"}} @@ -132,7 +152,4 @@ function TelescopeFiles() endfunction " Copy line location -" TODO this should work but it doesn't for some reason -" nmap c :let @+=expand("%:p") . ":" . line(".") -nmap c :exec "!wl-copy '" . expand("%:p") . ":" . line(".") . "'" - +nmap c :let @+=expand("%:p") . ":" . line(".") diff --git a/config/nvim/lua/plugins.lua b/config/nvim/lua/plugins.lua index fa736e3..6e33f5b 100644 --- a/config/nvim/lua/plugins.lua +++ b/config/nvim/lua/plugins.lua @@ -4,18 +4,68 @@ if vim.fn.empty(vim.fn.glob(install_path)) > 0 then vim.cmd([[packadd packer.nvim]]) end +local treesitter_formaters = { + "c", + "lua", + "kconfig", + "make", + "markdown", + "markdown_inline", + "meson", + "ninja", + "ini", + "gitcommit", + "git_rebase", + "git_config", + "nix", + "python", + "toml", + "vim", + "vimdoc", + "yaml", +} + require("packer").startup(function(use) use("wbthomason/packer.nvim") - -- Visual + -- Visual ------------------------------------------------------------------ use("shaunsingh/nord.nvim") use("MunifTanjim/nui.nvim") - use({ "nvim-treesitter/nvim-treesitter", run = ":TSUpdate" }) - use("lukas-reineke/indent-blankline.nvim") + use({ + "nvim-treesitter/nvim-treesitter", + run = ":TSUpdate", + config = function() + require("nvim-treesitter.configs").setup({ + ensure_installed = treesitter_formaters, + highlight = { + enable = true, + additional_vim_regex_highlighting = false, + }, + }) + end, + }) + use({ + "lukas-reineke/indent-blankline.nvim", + config = function() + local highlight = { "CursorColumn", "Whitespace" } + require("ibl").setup({ + indent = { highlight = highlight, char = "" }, + whitespace = { + highlight = highlight, + remove_blankline_trail = false, + }, + scope = { enabled = false }, + }) + end, + }) use("itchyny/lightline.vim") - -- Files navigation - use("nvim-lua/plenary.nvim") - use("nvim-telescope/telescope.nvim") - -- Git + use("josa42/nvim-lightline-lsp") + use({ + "nvim-telescope/telescope.nvim", + config = function() + require("mytelescope") + end, + }) + -- Git --------------------------------------------------------------------- use("tpope/vim-fugitive") use("airblade/vim-gitgutter") use({ @@ -30,71 +80,94 @@ require("packer").startup(function(use) run = function() require("gitlab.server").build(true) end, + config = function() + require("diffview").setup() + require("gitlab").setup() + end, }) - -- Programming + -- Programming ------------------------------------------------------------- use("neovim/nvim-lspconfig") use("p00f/clangd_extensions.nvim") - use("w0rp/ale") - use("maximbaz/lightline-ale") + use({ + "mfussenegger/nvim-lint", + config = function() + local lint = require("lint") + lint.linters_by_ft = { + c = { "cppcheck", "flawfinder", "editorconfig-checker" }, + lua = { "selene", "editorconfig-checker" }, + markdown = { "vale" }, + nix = { "statix", "deadnix", "nix", "editorconfig-checker" }, + python = { "pylint", "mypy", "pydocstyle", "editorconfig-checker" }, + sh = { "shellcheck", "editorconfig-checker" }, + } + lint.linters.deadnix = { + cmd = "deadnix", + stdin = false, + args = { "--output-format", "json" }, + stream = "stdout", + parser = function(output) + local lines = vim.fn.split(output, "\n") + local diagnostics = {} + for _, line in ipairs(lines) do + local ok, decoded = pcall(vim.json.decode, line) + if ok and decoded.file ~= nil then + for _, result in ipairs(decoded.results) do + table.insert(diagnostics, { + lnum = result.line, + end_lnum = result.line, + col = result.column, + end_col = result.endColumn, + severity = vim.diagnostic.severity.HINT, + source = "deadnix", + message = result.message, + }) + end + end + end + return diagnostics + end, + } + vim.api.nvim_create_autocmd({ "BufReadPost", "BufWrite", "InsertLeave" }, { + callback = function() + lint.try_lint() + end, + }) + end, + }) + use({ + "stevearc/conform.nvim", + config = function() + require("conform").setup({ + formatters_by_ft = { + c = { "clang-format", "trim_newlines", "twim_whitespace" }, + json = { "jq", "trim_newlines", "twim_whitespace" }, + lua = { "stylua", "trim_newlines", "twim_whitespace" }, + nix = { "alejandra", "trim_newlines", "twim_whitespace" }, + python = { "isort", "black", "trim_newlines", "twim_whitespace" }, + sh = { "shfmt", "trim_newlines", "twim_whitespace" }, + yaml = { "yq", "trim_newlines", "twim_whitespace" }, + }, + }) + end, + }) use("SirVer/ultisnips") use("honza/vim-snippets") use("craigemery/vim-autotag") use("scrooloose/nerdcommenter") - -- Movement, format and others + -- Movement, format and others --------------------------------------------- use("tpope/vim-surround") use("tpope/vim-repeat") use("dhruvasagar/vim-table-mode") + -- Filetypes --------------------------------------------------------------- + use("tmhedberg/SimpylFold") + use("LnL7/vim-nix") + use("kaarmu/typst.vim") + use("aliou/bats.vim") - -- Indent blanklike character specificaiton - local highlight = { "CursorColumn", "Whitespace" } - require("ibl").setup({ - indent = { highlight = highlight, char = "" }, - whitespace = { - highlight = highlight, - remove_blankline_trail = false, - }, - scope = { enabled = false }, - }) - -- Treesitter - require("nvim-treesitter.configs").setup({ - ensure_installed = { - "c", - "lua", - "kconfig", - "make", - "markdown", - "markdown_inline", - "meson", - "ninja", - "ini", - "gitcommit", - "git_rebase", - "git_config", - "nix", - "python", - "toml", - "vim", - "vimdoc", - "yaml", - }, - highlight = { - enable = true, - -- TODO why we must set this to true? - additional_vim_regex_highlighting = true, - }, - }) - - -- LSP + -- LSP --------------------------------------------------------------------- local lspconfig = require("lspconfig") lspconfig.clangd.setup({}) - lspconfig.rnix.setup({}) + lspconfig.nil_ls.setup({}) lspconfig.pylsp.setup({}) lspconfig.bashls.setup({}) - - -- Telescope - require("mytelescope") - - -- Gitlab - require("diffview").setup() - require("gitlab").setup() end) -- cgit v1.2.3