From b194e639fdc681166b009373a3663a942e947159 Mon Sep 17 00:00:00 2001 From: ViViDboarder Date: Wed, 1 Sep 2021 10:03:05 -0700 Subject: [PATCH] Neovim lua: Refactor more plugin loading and add better language support --- neovim/ftplugin/fish.vim | 8 ++++ neovim/ftplugin/go.vim | 9 +++++ neovim/ftplugin/markdown.vim | 5 +++ neovim/ftplugin/python.vim | 1 + neovim/ftplugin/yaml.vim | 2 + neovim/init.vim | 4 +- neovim/lua/_colors.lua | 56 ++++++++++++++++++++++++++ neovim/lua/init.lua | 72 +++++----------------------------- neovim/lua/plugins.lua | 65 ++++++++++++------------------ neovim/lua/plugins/airline.lua | 38 ++++++++++++++++++ neovim/lua/plugins/ale.lua | 38 ++++++++++++++++++ neovim/lua/plugins/lualine.lua | 17 ++++---- 12 files changed, 202 insertions(+), 113 deletions(-) create mode 100644 neovim/ftplugin/fish.vim create mode 100644 neovim/ftplugin/go.vim create mode 100644 neovim/ftplugin/markdown.vim create mode 100644 neovim/ftplugin/python.vim create mode 100644 neovim/ftplugin/yaml.vim create mode 100644 neovim/lua/_colors.lua create mode 100644 neovim/lua/plugins/airline.lua create mode 100644 neovim/lua/plugins/ale.lua diff --git a/neovim/ftplugin/fish.vim b/neovim/ftplugin/fish.vim new file mode 100644 index 0000000..c6b56a0 --- /dev/null +++ b/neovim/ftplugin/fish.vim @@ -0,0 +1,8 @@ +" Set up :make to use fish for syntax checking. +compiler fish + +" Set this to have long lines wrap inside comments. +setlocal textwidth=79 + +" Enable folding of block structures in fish. +setlocal foldmethod=expr diff --git a/neovim/ftplugin/go.vim b/neovim/ftplugin/go.vim new file mode 100644 index 0000000..ed22bf8 --- /dev/null +++ b/neovim/ftplugin/go.vim @@ -0,0 +1,9 @@ +let g:argwrap_tail_comma = 1 +let g:ale_fix_on_save = 1 +" Disable some vim-go settings when Ale is installed +if exists('g:ale_fixers') + let g:go_def_mapping_enabled = 0 + let g:go_version_warning = 0 + let g:go_fmt_autosave = 0 + let g:go_imports_autosave = 0 +end diff --git a/neovim/ftplugin/markdown.vim b/neovim/ftplugin/markdown.vim new file mode 100644 index 0000000..5e94e3c --- /dev/null +++ b/neovim/ftplugin/markdown.vim @@ -0,0 +1,5 @@ +" Set Markdown indent to 2 so single indented text doesn't become 'code' +set shiftwidth=2 + +" From plasticboy/vim-markdown via sheerun/vim-polyglot +let g:vim_markdown_new_list_item_indent = 0 diff --git a/neovim/ftplugin/python.vim b/neovim/ftplugin/python.vim new file mode 100644 index 0000000..c6240f2 --- /dev/null +++ b/neovim/ftplugin/python.vim @@ -0,0 +1 @@ +let g:argwrap_tail_comma = 1 diff --git a/neovim/ftplugin/yaml.vim b/neovim/ftplugin/yaml.vim new file mode 100644 index 0000000..24fea35 --- /dev/null +++ b/neovim/ftplugin/yaml.vim @@ -0,0 +1,2 @@ +" Set YAML indent to 2 because list objects are weird otherwise +set shiftwidth=2 diff --git a/neovim/init.vim b/neovim/init.vim index e0f43ff..ba0e6ee 100644 --- a/neovim/init.vim +++ b/neovim/init.vim @@ -2,8 +2,6 @@ if has('nvim-0.5') lua require('init') else - " set runtimepath-='~/.local/share/nvim/site/pack/packer/**' - " set runtimepath='~/.vim' - set runtimepath+='~/.vim" + set runtimepath+='~/.vim' source ~/.vim/init.vim end diff --git a/neovim/lua/_colors.lua b/neovim/lua/_colors.lua new file mode 100644 index 0000000..eca65e0 --- /dev/null +++ b/neovim/lua/_colors.lua @@ -0,0 +1,56 @@ +utils = require("utils") + +-- TODO: Determine if I want to keep this or remove it in favor of dark-notify +_G.update_colors = function() + local function maybe_set(scope, name, val) + if vim[scope][name] ~= val then + vim[scope][name] = val + return true + end + return false + end + + -- Set colorscheme based on env + local default_color = "solarized" + local env_color = utils.env_default("VIM_COLOR", default_color) + env_color = utils.env_default("NVIM_COLOR", env_color) + + -- Read dark mode + local mode = vim.env.IS_DARKMODE + if vim.g.is_mac == 1 then + local cmd = "defaults read -g AppleInterfaceStyle 2>/dev/null || echo Light" + mode = vim.fn.system(cmd):gsub("\n", ""):lower() + end + + -- Update background and theme + local change = false + if mode == "dark" then + env_color = utils.env_default("VIM_COLOR_DARK", env_color) + env_color = utils.env_default("NVIM_COLOR_DARK", env_color) + change = maybe_set("o", "background", "dark") + change = maybe_set("g", "colors_name", env_color) or change + elseif mode == "light" then + env_color = utils.env_default("VIM_COLOR_LIGHT", env_color) + env_color = utils.env_default("NVIM_COLOR_LIGHT", env_color) + change = maybe_set("o", "background", "light") + change = maybe_set("g", "colors_name", env_color) or change + end + + -- Update status line theme + if change and vim.fn.exists(":AirlineRefresh") == 1 then + vim.cmd(":AirlineRefresh") + elseif change and _G["packer_plugins"] ~= nil and packer_plugins["lualine"] and packer_plugins["lualine"].loaded then + local lualine_theme = vim.g.colors_name + if lualine_theme == "solarized" then + lualine_theme = lualine_theme .. "_" .. mode + end + require("plugins.lualine").config_lualine(lualine_theme) + end + + return changed and "Changed color to " .. env_color .. " with mode " .. mode or "No change" +end +-- utils.autocmd("auto_colors", "FocusGained * call v:lua.update_colors()") + +-- Initial set of colors +-- TODO: if update_colors() is removed, use the env color fetching and set the colorscheme here +update_colors() diff --git a/neovim/lua/init.lua b/neovim/lua/init.lua index 7a0eb83..ce8cb54 100644 --- a/neovim/lua/init.lua +++ b/neovim/lua/init.lua @@ -1,77 +1,23 @@ local o, wo, bo = vim.o, vim.wo, vim.bo -- Helpers - require "_settings" require "_bindings" -utils = require("utils") - --- Modify visual presentation +require "_colors" -- Create commands vim.cmd "command! TagsUpdate !ctags -R ." vim.cmd "command! Todo grep TODO" -- Use better grep programs -if vim.fn.executable('rg') == 1 then - vim.o.grepprg = "rg --vimgrep --no-heading --color=never" - vim.o.grepformat = "%f:%l:%c:%m,%f:%l:%m" -elseif vim.fn.executable('ag') == 1 then - vim.o.grepprg = "ag --vimgrep --nogroup --nocolor" -elseif vim.fn.executable('ack') == 1 then - vim.o.grepprg = "ack" +if vim.fn.executable("rg") == 1 then + o.grepprg = "rg --vimgrep --no-heading --color=never" + o.grepformat = "%f:%l:%c:%m,%f:%l:%m" +elseif vim.fn.executable("ag") == 1 then + o.grepprg = "ag --vimgrep --nogroup --nocolor" +elseif vim.fn.executable("ack") == 1 then + o.grepprg = "ack" end --- TODO: Determine if I want to keep this or remove it in favor of dark-notify -_G.update_colors = function() - local function maybe_set(scope, name, val) - if vim[scope][name] ~= val then - vim[scope][name] = val - return true - end - return false - end - - -- Set colorscheme based on env - local default_color = "solarized" - local env_color = utils.env_default("VIM_COLOR", default_color) - - -- Read dark mode - local mode = vim.env.IS_DARKMODE - if vim.g.is_mac == 1 then - cmd = "defaults read -g AppleInterfaceStyle 2>/dev/null || echo Light" - mode = vim.fn.system(cmd):gsub("\n", ""):lower() - end - - -- Update background and theme - local change = false - if mode == "dark" then - env_color = utils.env_default("VIM_COLOR_DARK", env_color) - change = maybe_set("o", "background", "dark") - change = maybe_set("g", "colors_name", env_color) or change - elseif mode == "light" then - env_color = utils.env_default("VIM_COLOR_LIGHT", env_color) - change = maybe_set("o", "background", "light") - change = maybe_set("g", "colors_name", env_color) or change - end - - -- Update status line theme - if change and vim.fn.exists(":AirlineRefresh") == 1 then - vim.cmd(":AirlineRefresh") - elseif change and _G["packer_plugins"] ~= nil and packer_plugins["lualine"] and packer_plugins["lualine"].loaded then - local lualine_theme = vim.g.colors_name - if lualine_theme == "solarized" then - lualine_theme = lualine_theme .. "_" .. mode - end - require("plugins.lualine").config_lualine(lualine_theme) - end - - return changed and "Changed color to " .. env_color .. " with mode " .. mode or "No change" -end --- utils.autocmd("auto_colors", "FocusGained * call v:lua.update_colors()") - --- Initial set of colors --- TODO: if update_colors() is removed, use the env color fetching and set the colorscheme here -update_colors() - +-- Plugins require("plugins") diff --git a/neovim/lua/plugins.lua b/neovim/lua/plugins.lua index 4630129..7ee9843 100644 --- a/neovim/lua/plugins.lua +++ b/neovim/lua/plugins.lua @@ -10,44 +10,6 @@ end -- Requires :PackerCompile for "config" to be loaded --- TODO: Get rid of if airline goes -local function config_airline() - -- Use short-form mode text - vim.g.airline_mode_map = { - ['__'] = '-', - ['n'] = 'N', - ['i'] = 'I', - ['R'] = 'R', - ['c'] = 'C', - ['v'] = 'V', - ['V'] = 'V', - [''] = 'V', - ['s'] = 'S', - ['S'] = 'S', - [''] = 'S', - ['t'] = 'T', - } - - -- abbreviate trailing whitespace and mixed indent - vim.g["airline#extensions#whitespace#trailing_format"] = "tw[%s]" - vim.g["airline#extensions#whitespace#mixed_indent_format"] = "i[%s]" - -- Vertical separators for all - vim.g.airline_left_sep='' - vim.g.airline_left_alt_sep='' - vim.g.airline_right_sep='' - vim.g.airline_right_alt_sep='' - vim.g["airline#extensions#tabline#enabled"] = 1 - vim.g["airline#extensions#tabline#left_sep"] = " " - vim.g["airline#extensions#tabline#left_alt_sep"] = "|" - -- Slimmer section z - vim.g.airline_section_z = "%2l/%L:%2v" - -- Skip most common encoding - vim.g["airline#parts#ffenc#skip_expected_string"] = "utf-8[unix]" - -- If UTF-8 symbols don't work, use ASCII - -- vim.g.airline_symbols_ascii = 1 - vim.g["airline#extensions#nvimlsp#enabled"] = 1 -end - -- Configures dark-notify to use colors from my environment local function config_dark_notify() local default_color = "solarized" @@ -95,7 +57,7 @@ return require('packer').startup(function() } use { "tpope/vim-fugitive", - cmd = { "Git", "Gstatus", "Gblame", "Gpush", "Gpull" }, + -- cmd = { "Git", "Gstatus", "Gblame", "Gpush", "Gpull" }, } use { "milkypostman/vim-togglelist", @@ -106,8 +68,17 @@ return require('packer').startup(function() } -- UI + use "~/workspace/ez-colors.nvim/wombat" + use { + "~/workspace/wombuddy", + requires = "tjdevries/colorbuddy.vim", + } use "vim-scripts/wombat256.vim" use "ishan9299/nvim-solarized-lua" + use { + "norcalli/nvim-colorizer.lua", + config = function() require("colorizer").setup() end, + } --[[ use { "shaunsingh/solarized.nvim", @@ -125,7 +96,7 @@ return require('packer').startup(function() --[[ use { "vim-airline/vim-airline", - config = config_airline, + config = function() require("plugins.airline") end, requires = { "vim-airline/vim-airline-themes", opt = true }, } --]] @@ -155,6 +126,15 @@ return require('packer').startup(function() "glepnir/lspsaga.nvim", requires = { "neovim/nvim-lspconfig" }, } + --[[ + use { + "SmiteshP/nvim-gps", + requires = "nvim-treesitter/nvim-treesitter" + } + --]] + + -- Writing + -- abolish/pencil -- Treesitter use { @@ -254,6 +234,11 @@ return require('packer').startup(function() } --]] + use { + "dense-analysis/ale", + config = function() require("utils").require_with_local("plugins.ale") end, + } + -- Debuging nvim config use { "tweekmonster/startuptime.vim", diff --git a/neovim/lua/plugins/airline.lua b/neovim/lua/plugins/airline.lua new file mode 100644 index 0000000..da51dfc --- /dev/null +++ b/neovim/lua/plugins/airline.lua @@ -0,0 +1,38 @@ +local function config_airline() + -- Use short-form mode text + vim.g.airline_mode_map = { + ['__'] = '-', + ['n'] = 'N', + ['i'] = 'I', + ['R'] = 'R', + ['c'] = 'C', + ['v'] = 'V', + ['V'] = 'V', + [''] = 'V', + ['s'] = 'S', + ['S'] = 'S', + [''] = 'S', + ['t'] = 'T', + } + + -- abbreviate trailing whitespace and mixed indent + vim.g["airline#extensions#whitespace#trailing_format"] = "tw[%s]" + vim.g["airline#extensions#whitespace#mixed_indent_format"] = "i[%s]" + -- Vertical separators for all + vim.g.airline_left_sep='' + vim.g.airline_left_alt_sep='' + vim.g.airline_right_sep='' + vim.g.airline_right_alt_sep='' + vim.g["airline#extensions#tabline#enabled"] = 1 + vim.g["airline#extensions#tabline#left_sep"] = " " + vim.g["airline#extensions#tabline#left_alt_sep"] = "|" + -- Slimmer section z + vim.g.airline_section_z = "%2l/%L:%2v" + -- Skip most common encoding + vim.g["airline#parts#ffenc#skip_expected_string"] = "utf-8[unix]" + -- If UTF-8 symbols don't work, use ASCII + -- vim.g.airline_symbols_ascii = 1 + vim.g["airline#extensions#nvimlsp#enabled"] = 1 +end + +config_airline() diff --git a/neovim/lua/plugins/ale.lua b/neovim/lua/plugins/ale.lua new file mode 100644 index 0000000..900f7ae --- /dev/null +++ b/neovim/lua/plugins/ale.lua @@ -0,0 +1,38 @@ +vim.g["airline#extensions#ale#enabled"] = 1 +vim.g.ale_lint_on_enter = 0 +vim.g.ale_linters = { + -- go = { 'gopls', 'golint', 'golangci-lint' }, + go = { "golangci-lint" }, + -- rust = { 'rls', 'cargo' }, + rust = { "cargo" }, + -- sh = { 'language_server', 'shell', 'shellcheck' }, + sh = { "shell", "shellcheck" }, + text = { "proselint", "alex" }, +} +vim.g.ale_linter_aliases = { + markdown = { "text" }, +} +local pretty_trim_fixer = { + "prettier", + "trim_whitespace", + "remove_trailing_lines" +} +vim.g.ale_fixers = { + ["*"] = { "trim_whitespace", "remove_trailing_lines" }, + -- go = { "gofmt", "goimports" }, + json = pretty_trim_fixer, + -- rust = { "rustfmt" }, + --[[ + python = { + "black", + "autopep8", + "reorder-python-imports", + "remove_trailing_lines", + "trim_whitespace", + }, + --]] + markdown = pretty_trim_fixer, + yaml = { "prettier", "remove_trailing_lines" }, + css = pretty_trim_fixer, + javascript = pretty_trim_fixer, +} diff --git a/neovim/lua/plugins/lualine.lua b/neovim/lua/plugins/lualine.lua index 36319c4..7214841 100644 --- a/neovim/lua/plugins/lualine.lua +++ b/neovim/lua/plugins/lualine.lua @@ -46,9 +46,9 @@ function M.mixed_indent() end function M.trailing_whitespace() - local count = vim.fn.search([[\s\+$]], 'nw') - if count ~= 0 then - return "tw:" .. count + local line = vim.fn.search([[\s\+$]], 'nw') + if line ~= 0 then + return "tw:" .. line end return nil @@ -56,29 +56,32 @@ end -- Configure lualine witha provided theme function M.config_lualine(theme_name) + -- Theme name transformations if theme_name == nil then theme_name = "auto" elseif theme_name == "wombat256mod" then theme_name = "wombat" + elseif theme_name == "wombuddy" then + theme_name = "wombat" end - require("lualine").setup { options = { theme = theme_name, icons_enabled = false, component_separators = {"|", "|"}, - section_separators = {" ", " "}, + section_separators = {"", ""}, }, sections = { lualine_a = { M.single_letter_mode }, - lualine_b = { "branch", "diff" }, + lualine_b = { "FugitiveHead", "diff" }, lualine_c = { "filename" }, lualine_x = { M.custom_ffenc, "filetype" }, lualine_y = { "progress", "location" }, lualine_z = { { "diagnostics", sources = { "nvim_lsp" } }, - M.mixed_indent, M.trailing_whitespace, + { M.mixed_indent, color = { bg = "#de4f1f" } }, + { M.trailing_whitespace, color = { bg = "#de4f1f" } }, }, }, }