Neovim lua: Refactor more plugin loading and add better language support

This commit is contained in:
ViViDboarder 2021-09-01 10:03:05 -07:00
parent 1ac22e81b2
commit b194e639fd
12 changed files with 202 additions and 113 deletions

8
neovim/ftplugin/fish.vim Normal file
View File

@ -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

9
neovim/ftplugin/go.vim Normal file
View File

@ -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

View File

@ -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

View File

@ -0,0 +1 @@
let g:argwrap_tail_comma = 1

2
neovim/ftplugin/yaml.vim Normal file
View File

@ -0,0 +1,2 @@
" Set YAML indent to 2 because list objects are weird otherwise
set shiftwidth=2

View File

@ -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

56
neovim/lua/_colors.lua Normal file
View File

@ -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()

View File

@ -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")

View File

@ -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",

View File

@ -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()

View File

@ -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,
}

View File

@ -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" } },
},
},
}