My current neovim config

This commit is contained in:
2022-10-10 18:12:32 -07:00
commit ec3acd5976
7 changed files with 308 additions and 0 deletions
+35
View File
@@ -0,0 +1,35 @@
local job_id, job_buffer
local function job_exit(jobId, exit_code, _)
job_id = nil
echo("Job done")
end
local function has_buffer()
return job_buffer and vim.fn.buflisted(job_buffer) == 1
end
function save_all_and_build()
if job_id then
echo ("Job processing")
return
end
local opts = {}
vim.api.nvim_exec('wa', opts)
if not has_buffer() then
job_buffer = vim.api.nvim_create_buf(true, true)
end
local job_window = vim.fn.bufwinnr(job_buffer)
if job_window ~= -1 then
vim.cmd(job_window .. ' wincmd w')
else
vim.cmd('buffer ' .. job_buffer)
end
vim.api.nvim_buf_set_option(job_buffer, 'filetype', 'build')
vim.api.nvim_buf_set_option(job_buffer, 'modified', false)
-- TODO: if I want to get fancy I can set a build string per language.
job_id = vim.fn.termopen("zig build", {on_exit = job_exit})
vim.api.nvim_buf_set_name(job_buffer, '[build]')
end
+44
View File
@@ -0,0 +1,44 @@
require('buildcmd')
local tbuiltin = require('telescope.builtin')
vim.g.mapleader = ' ' --space
local function project_files()
local opts = {}
local ok = pcall(tbuiltin.git_files, opts)
if not ok then tbuiltin.find_files(opts) end
end
-- Mappings, mostly taken from nvim-lspconfig
local opts = { noremap=true, silent=true }
vim.keymap.set('n', '<leader>q', vim.diagnostic.open_float, opts)
vim.keymap.set('n', '<leader>e', '<cmd>Ex<CR>', opts)
vim.keymap.set('n', '<leader>ff', project_files, opts)
vim.keymap.set('n', '<leader>fb', '<cmd>Telescope buffers<cr>', opts)
vim.keymap.set('n', '<leader>bb', save_all_and_build, opts)
-- TODO: get fancy and read the commentstring and user
-- Would love to have this be alt but that doesn't work...
vim.keymap.set('i', '<A-t>', '// TODO(twig): ', opts)
vim.keymap.set('i', '<A-y>', '// NOTE(twig): ', opts)
local on_attach = function(client, bufnr)
vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc')
-- Mappings
local bufopts = { noremap=true, silent=true, buffer=bufnr }
-- Replace these with telescope equivalent
vim.keymap.set('n', '<leader>rb', vim.lsp.buf.declaration, bufopts)
vim.keymap.set('n', '<leader>rd', vim.lsp.buf.definition, bufopts)
vim.keymap.set('n', '<leader>rf', tbuiltin.lsp_references, bufopts)
vim.keymap.set('n', '<leader>rs', tbuiltin.lsp_document_symbols, bufopts)
vim.keymap.set('n', '<leader>rr', vim.lsp.buf.rename, bufopts)
end
local lsp_flags = {
debounce_text_changes = 150, --wtf is this
}
require('lspconfig')['zls'].setup {
on_attach = on_attach,
flags = lsp_flags
}
--TODO: other languages I care about.
+15
View File
@@ -0,0 +1,15 @@
vim.cmd [[packadd packer.nvim]]
return require('packer').startup(function(use)
-- Packer can manage itself
use 'wbthomason/packer.nvim'
use 'sainnhe/everforest'
use 'sainnhe/sonokai'
use { 'nvim-treesitter/nvim-treesitter' }
use 'neovim/nvim-lspconfig'
use 'nvim-treesitter/nvim-treesitter-context'
use { 'nvim-telescope/telescope.nvim', tag = '0.1.0', requires = {{'nvim-lua/plenary.nvim'}} }
use { 'windwp/nvim-autopairs' }
use { 'tomasr/molokai' }
use 'morhetz/gruvbox'
end)
+147
View File
@@ -0,0 +1,147 @@
local modes = {
["n"] = "NORMAL",
["no"] = "NORMAL",
["v"] = "VISUAL",
["V"] = "VISUAL LINE",
[""] = "VISUAL BLOCK",
["s"] = "SELECT",
["S"] = "SELECT LINE",
[""] = "SELECT BLOCK",
["i"] = "INSERT",
["ic"] = "INSERT",
["R"] = "REPLACE",
["Rv"] = "VISUAL REPLACE",
["c"] = "COMMAND",
["cv"] = "VIM EX",
["ce"] = "EX",
["r"] = "PROMPT",
["rm"] = "MOAR",
["r?"] = "CONFIRM",
["!"] = "SHELL",
["t"] = "TERMINAL",
}
local function mode()
local current_mode = vim.api.nvim_get_mode().mode
return string.format(" %s ", modes[current_mode]):upper()
end
local function update_mode_colors()
local current_mode = vim.api.nvim_get_mode().mode
local mode_color = "%#StatusLineAccent#"
if current_mode == "n" then
mode_color = "%#StatuslineAccent#"
elseif current_mode == "i" or current_mode == "ic" then
mode_color = "%#Search#"
elseif current_mode == "v" or current_mode == "V" or current_mode == "" then
mode_color = "%#DiffText#"
elseif current_mode == "R" then
mode_color = "%#Visual#"
elseif current_mode == "c" then
mode_color = "%#Cursor#"
elseif current_mode == "t" then
mode_color = "%#FloatShadow#"
end
return mode_color
end
local function filepath()
local fpath = vim.fn.fnamemodify(vim.fn.expand "%", ":~:.:h")
if fpath == "" or fpath == "." then
return " "
end
return string.format(" %%<%s/", fpath)
end
local function filename()
local fname = vim.fn.expand "%:t"
-- wtf
if fname == "" then
return ""
end
return fname .. " "
end
local function lsp()
local count = {}
local levels = {
errors = "Error",
warnings = "Warn",
info = "Info",
hints = "Hint",
}
for k, level in pairs(levels) do
count[k] = vim.tbl_count(vim.diagnostic.get(0, {severity = level }))
end
local errors = ""
local warnings = ""
local hints = ""
local info = ""
if count["errors"] ~= 0 then
errors = " %#LspDiagnosticsSignError# " .. count["errors"]
end
if count["warnings"] ~= 0 then
warnings = " %#LspDiagnosticsSignHint# " .. count["warnings"]
end
if count["hints"] ~= 0 then
hints = " %#LspDiagnosticsSignHint# " .. count["hints"]
end
if count["info"] ~= 0 then
info = " %#LspDiagnosticsSignInformation# " .. count["info"]
end
return errors .. warnings .. hints .. info .. "%#Normal#"
end
local function filetype()
return string.format(" %s ", vim.bo.filetype):upper()
end
local function lineinfo()
if vim.bo.filetype == "alpha" then
return ""
end
return " %l:%c %P %"
end
Statusline = {}
Statusline.active = function()
return table.concat {
"%#Statusline#",
update_mode_colors(),
mode(),
"%#Statusline# ",
filepath(),
filename(),
"%#Normal#",
lsp(),
"%=%#StatusLineExtra#",
filetype(),
lineinfo(),
}
end
function Statusline.inactive()
return " %#Statusline#%F"
end
function Statusline.short()
return "%#StatusLineNC#  NvimTree"
end
vim.api.nvim_exec([[
augroup Statusline
au!
au WinEnter,BufEnter * setlocal statusline=%!v:lua.Statusline.active()
au WinLeave,BufLeave * setlocal statusline=%!v:lua.Statusline.inactive()
au WinEnter,BufEnter,FileType NvimTree setlocal statusline=%!v:lua.Statusline.short()
augroup END
]], false)