From c0e5b1749e17f323ceb20f1028e67fc95c5ff6ab Mon Sep 17 00:00:00 2001 From: Felipe Contreras-Salinas Date: Mon, 27 Mar 2023 16:09:35 -0300 Subject: [PATCH] config refactor + ale -> nvim-lint --- .gitmodules | 6 +-- init.lua | 101 ++++++++++++++++------------------- pack/general/start/ale | 1 - pack/general/start/nvim-lint | 1 + 4 files changed, 51 insertions(+), 58 deletions(-) delete mode 160000 pack/general/start/ale create mode 160000 pack/general/start/nvim-lint diff --git a/.gitmodules b/.gitmodules index 020c2dd..b710ff9 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,3 @@ -[submodule "pack/general/start/ale"] - path = pack/general/start/ale - url = https://github.com/dense-analysis/ale [submodule "pack/general/start/gruvbox.nvim"] path = pack/general/start/gruvbox.nvim url = https://github.com/npxbr/gruvbox.nvim @@ -85,3 +82,6 @@ [submodule "pack/general/start/vim-helm"] path = pack/general/start/vim-helm url = https://github.com/towolf/vim-helm +[submodule "pack/general/start/nvim-lint"] + path = pack/general/start/nvim-lint + url = https://github.com/mfussenegger/nvim-lint diff --git a/init.lua b/init.lua index b2b955e..7e2a948 100644 --- a/init.lua +++ b/init.lua @@ -2,7 +2,6 @@ local cmd = vim.cmd local g = vim.g local opt = vim.opt -local o = vim.o ---- General Config ---- opt.mouse = 'a' @@ -10,7 +9,6 @@ opt.tabstop = 4 opt.shiftwidth = 4 opt.number = true opt.breakindent = true ---vim.o.inccomand = 'nosplit' opt.showmatch = true opt.ignorecase = true opt.smartcase = true @@ -25,11 +23,14 @@ opt.shortmess:append({ I = true }) --opt.whichwrap = {'<','>','[',']'} opt.cmdheight = 2 opt.showcmd = true -opt.showcmd = true g.mapleader = ' ' ---- Terminal ---- -cmd 'autocmd TermOpen * setlocal nonumber' +vim.api.nvim_create_autocmd({ "TermOpen" }, { + callback = function() + vim.l.number = false + end, +}) ---- Theming ---- opt.termguicolors = true @@ -55,10 +56,10 @@ local function map(mode, lhs, rhs, opts) if opts then options = vim.tbl_extend('force', options, opts) end vim.keymap.set(mode, lhs, rhs, options) end -map('!','','') -map('v','>','>gv') -map('v','<','',':nohlsearch') +vim.keymap.set('!','','') +vim.keymap.set('v','>','>gv') +vim.keymap.set('v','<','',':nohlsearch') ---- Treesitter ---- local ts = require 'nvim-treesitter.configs' @@ -153,36 +154,34 @@ local servers = { -- overrides the previous calls. -- Auto format on save -vim.cmd [[autocmd BufWritePre * lua vim.lsp.buf.format()]] +vim.api.nvim_create_autocmd({ "BufWritePre" }, { + callback = function() + vim.lsp.buf.format() + end, +}) ---- Plugins ---- ----- ale -g.ale_linters = { - bash = {'shellcheck'}, - c = {}, - cpp = {}, - css = {'stylelint'}, - go = {'gobuild', 'golangci-lint'}, - html = {'tidy'}, - javascript = {'eslint'}, - python = {'flake8', 'isort'}, - terraform = {}, - tex = {}, - typescript = {}, - vim = {'vint'}, - zsh = {'shell', 'shellcheck'}, -} -g.ale_sign_error = '✘' -g.ale_sign_warning = '▲' -g.ale_set_highlights = 1 -- Go g.ale_go_golangci_lint_options = '' g.ale_go_golangci_lint_package = 1 --- Mappings -map('n', '[W', '(ale_first)') -map('n', '[w', '(ale_previous_wrap)') -map('n', ']w', '(ale_next_wrap)') -map('n', ']W', '(ale_last)') +---- nvim-lint ---- +local lint = require 'lint' +linters = { + bash = {'shellcheck'}, + go = {'golangcilint',}, + python = {'flake8'}, + yaml = {'yamllint'}, + zsh = {'shellcheck'}, +} +-- set linters -- +lint.linters_by_ft = linters +-- set autocommands -- +vim.api.nvim_create_autocmd({ "BufWritePost" }, { + callback = function() + lint.try_lint() + end, +}) + ---- completion-nvim local cmp = require'cmp' @@ -217,7 +216,7 @@ cmp.setup({ local capabilities = vim.lsp.protocol.make_client_capabilities() lsp.util.default_config = vim.tbl_deep_extend( 'force', lsp.util.default_config, { capabilities = capabilities, }) -for _, server in ipairs(servers) do +for _, server in pairs(servers) do lsp[server].setup { on_attach = on_lsp_attach, flags = { @@ -232,40 +231,34 @@ 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() + vim.keymap.set('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() + vim.keymap.set('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) + vim.keymap.set({'n', 'v'}, 'hs', ':Gitsigns stage_hunk') + vim.keymap.set({'n', 'v'}, 'hr', ':Gitsigns reset_hunk') + vim.keymap.set('n', 'hS', gs.stage_buffer) + vim.keymap.set('n', 'hu', gs.undo_stage_hunk) + vim.keymap.set('n', 'hR', gs.reset_buffer) + vim.keymap.set('n', 'hp', gs.preview_hunk) + vim.keymap.set('n', 'hb', function() gs.blame_line{full=true} end) + vim.keymap.set('n', 'tb', gs.toggle_current_line_blame) + vim.keymap.set('n', 'hd', gs.diffthis) + vim.keymap.set('n', 'hD', function() gs.diffthis('~') end) + vim.keymap.set('n', 'td', gs.toggle_deleted) -- Text object - map({'o', 'x'}, 'ih', ':Gitsigns select_hunk') + vim.keymap.set({'o', 'x'}, 'ih', ':Gitsigns select_hunk') end } ---- Comment.nvim diff --git a/pack/general/start/ale b/pack/general/start/ale deleted file mode 160000 index 7dbd3c9..0000000 --- a/pack/general/start/ale +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 7dbd3c96ac1eb3a1981e740423a31500108f6e25 diff --git a/pack/general/start/nvim-lint b/pack/general/start/nvim-lint new file mode 160000 index 0000000..b16e6e4 --- /dev/null +++ b/pack/general/start/nvim-lint @@ -0,0 +1 @@ +Subproject commit b16e6e424ddfb12d4b3a699c1dc41ba0f3b503da