I should probably make this a git repo

This commit is contained in:
gnat
2024-07-30 10:06:43 -07:00
commit ecfa4a1774
45 changed files with 1100 additions and 0 deletions

45
lua/core/diagnostics.lua Normal file
View File

@ -0,0 +1,45 @@
function capitalize_head_exclusive(str)
str = string.lower(str)
str = string.gsub(str, "^%l", string.upper)
return str
end
local signs = { Error = "", Warn = "", Hint = "", Info = "" }
for type, icon in pairs(signs) do
local hl = "DiagnosticSign" .. type
vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = hl })
end
local max_width = math.min(math.floor(vim.o.columns * 0.7), 100)
local max_height = math.min(math.floor(vim.o.lines * 0.3), 30)
vim.diagnostic.config({
underline = true,
update_in_insert = true,
severity_sort = true,
virtual_text = false and {
spacing = 1,
prefix = '', -- TODO: in nvim-0.10.0 this can be a function, so format won't be necessary
format = function(d)
local level = vim.diagnostic.severity[d.severity]
return string.format('%s %s', signs[capitalize_head_exclusive(level)], d.message)
end,
},
float = {
max_width = max_width,
max_height = max_height,
border = border_style,
title = { { '', 'DiagnosticFloatTitleIcon' }, { 'Problems ', 'DiagnosticFloatTitle' } },
focusable = false,
scope = 'line',
source = 'if_many',
prefix = function(diag)
local level = vim.diagnostic.severity[diag.severity]
local prefix = string.format('%s ', signs[capitalize_head_exclusive(level)])
return prefix, 'Diagnostic' .. level:gsub('^%l', string.upper)
end,
},
})
vim.cmd [[ autocmd! CursorHold * lua vim.diagnostic.open_float()]]

89
lua/core/keys.lua Normal file
View File

@ -0,0 +1,89 @@
vim.g.mapleader = " "
local opts = { noremap = true, silent = true }
local term_opts = { silent = true }
local keymap = vim.keymap.set
keymap('t', '<S-Esc>', '<C-\\><C-n>', { noremap = true })
-- window navigation
keymap("n", "<C-h>", "<C-w>h", opts)
keymap("n", "<C-j>", "<C-w>j", opts)
keymap("n", "<C-k>", "<C-w>k", opts)
keymap("n", "<C-l>", "<C-w>l", opts)
-- window resizing
keymap("n", "<C-S-k>", ":resize -2<CR>", opts)
keymap("n", "<C-S-j>", ":resize +2<CR>", opts)
keymap("n", "<C-S-h>", ":vertical resize -2<CR>", opts)
keymap("n", "<C-S-l>", ":vertical resize +2<CR>", opts)
-- buffer navigation
keymap("n", "<C-8>", ":bnext<CR>", opts)
keymap("n", "<C-9>", ":bprevious<CR>", opts)
-- move selection up or down
keymap("n", "<A-j>", ":m .+1<CR>==", opts)
keymap("n", "<A-k>", ":m .-2<CR>==", opts)
-- don't exit visual mode
keymap("v", "<", "<gv^", opts)
keymap("v", ">", ">gv^", opts)
-- Move text up and down
keymap("v", "<A-j>", ":m '>+1<CR>gv=gv", opts)
keymap("v", "<A-k>", ":m '<-2<CR>gv=gv", opts)
keymap("v", "p", '"_dP', opts)
-- Move text up and down
keymap("x", "J", ":m '>+1<CR>gv=gv", opts)
keymap("x", "K", ":m '<-2<CR>gv=gv", opts)
keymap("x", "<A-j>", ":m '>+1<CR>gv=gv", opts)
keymap("x", "<A-k>", ":m '<-2<CR>gv=gv", opts)
-- force me to use vim keys
keymap('n', '<Up>', '<Nop>', opts)
keymap('n', '<Down>', '<Nop>', opts)
keymap('n', '<Left>', '<Nop>', opts)
keymap('n', '<Right>', '<Nop>', opts)
keymap('i', '<Up>', '<Nop>', opts)
keymap('i', '<Down>', '<Nop>', opts)
keymap('i', '<Left>', '<Nop>', opts)
keymap('i', '<Right>', '<Nop>', opts)
keymap('i', '<A-h>', '<Left>', opts)
keymap('i', '<A-j>', '<Down>', opts)
keymap('i', '<A-k>', '<Up>', opts)
keymap('i', '<A-l>', '<Right>', opts)
keymap('x', '<Up>', '<Nop>', opts)
keymap('x', '<Down>', '<Nop>', opts)
keymap('x', '<Left>', '<Nop>', opts)
keymap('x', '<Right>', '<Nop>', opts)
-- split windows
keymap('n', '<C-s>v', ':vsplit<CR>', opts)
keymap('n', '<C-s>h', ':split<CR>', opts)
keymap('n', '<A-l>', ':nohlsearch<CR>', opts)
keymap('n', '<C-space>s', ':lua if vim.o.spell then vim.o.spell = false else vim.o.spell = true end<CR>',
{ noremap = true, silent = true })
keymap('n', '<C-space>c', ':ColorizerToggle<CR>', opts)
-- Tabs
keymap('n', '<C-t>', ':tabnew<CR>', opts)
keymap('n', '<C-w>', ':tabclose<CR>', opts)
keymap('n', '<A-j>', ':tabp<CR>', opts)
keymap('n', '<A-k>', ':tabn<CR>', opts)
-- Trouble.lua
keymap('n', '<C-space>t', ':TroubleToggle<CR>', opts)
-- lsp diagnostic movement
keymap('n', '>d', ':lua vim.diagnostic.goto_next()<CR>', opts)
keymap('n', '<d', ':lua vim.diagnostic.goto_prev()<CR>', opts)
-- source init
keymap('n', 'ri', ':luafile ~/.config/nvim/init.lua<CR>', opts) -- ri: reload init

17
lua/core/lazy.lua Normal file
View File

@ -0,0 +1,17 @@
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
vim.fn.system({
"git",
"clone",
"--filter=blob:none",
"https://github.com/folke/lazy.nvim.git",
"--branch=stable",
lazypath,
})
end
vim.opt.rtp:prepend(lazypath)
require('lazy').setup({
import='plugins',
})

33
lua/core/opts.lua Normal file
View File

@ -0,0 +1,33 @@
local opt = vim.opt
opt.expandtab = true
opt.smarttab = true
opt.shiftwidth = 4
opt.tabstop = 4
opt.hlsearch = true
opt.incsearch = true
opt.ignorecase = true
opt.smartcase = true
opt.splitbelow = true
opt.splitright = true
opt.wrap = false
opt.scrolloff = 5
opt.fileencoding = 'utf-8'
opt.termguicolors = true
opt.relativenumber = true
opt.cursorline = true
opt.number = true
opt.spelllang = { 'en_us' }
opt.background = 'light'
opt.updatetime = 50
border_style = 'rounded'
vim.cmd('set showtabline=2')
vim.cmd('colorscheme gruvbox')
vim.cmd('hi SpellBad gui=undercurl guifg=#cc241c')

123
lua/core/statusline.lua Normal file
View File

@ -0,0 +1,123 @@
function get_mode_highlight(mode)
local mode_highlights = {
n = "%#MyNormalMode#",
i = "%#MyInsertMode#",
t = "%#MyInsertMode#",
v = "%#MyVisualMode#",
V = "%#MyVisualMode#",
[""] = "%#MyVisualMode#",
c = "%#MyDefaultMode#",
s = "%#MyDefaultMode#",
S = "%#MyDefaultMode#",
[""] = "%#MyDefaultMode#",
R = "%#MyDefaultMode#",
Rv = "%#yDefaultMode#",
}
return mode_highlights[mode] or "MyDefaultMode"
end
function get_mode_name(mode)
local mode_map = {
n = "Normal",
i = "Insert",
t = "Terminal",
v = "Visual",
V = "V-Line",
[""] = "V-Block",
c = "Command",
s = "Select",
S = "S-Line",
[""] = "S-Block",
R = "Replace",
Rv = "V-Replace",
}
return mode_map[mode]
end
function format_filename()
return vim.fn.expand('%:t') ~= '' and vim.fn.expand('%:t') or 'nil'
end
function get_line_chars()
return string.format('%s:%s', vim.fn.col('.')-1, vim.fn.col('$')-1)
end
function get_diagnostic_count()
local bufnr = vim.api.nvim_get_current_buf()
local diagnostics = vim.diagnostic.get(bufnr)
local warning_count = 0
local error_count = 0
for _, diagnostic in ipairs(diagnostics) do
if diagnostic.severity == vim.lsp.protocol.DiagnosticSeverity.Warning then
warning_count = warning_count + 1
elseif diagnostic.severity == vim.lsp.protocol.DiagnosticSeverity.Error then
error_count = error_count + 1
end
end
if warning_count + error_count == 0 then
return ''
elseif error_count == 0 then
return '[%#CustomWarnHl#' .. '' .. warning_count .. '%*]'
elseif warning_count == 0 then
return "[%#CustomErrorHl# " .. error_count .. '%*]'
end
return "[%#CustomErrorHl# " .. error_count .. '%*] [%#CustomWarnHl#' .. '' .. warning_count .. '%*]'
end
function get_buffer_perms()
local readable = vim.loop.fs_access(vim.fn.expand('%'), 'R')
local writable = vim.loop.fs_access(vim.fn.expand('%'), 'W')
local executable = vim.loop.fs_access(vim.fn.expand('%'), 'X')
local permissions = ""
if readable then
permissions = permissions .. "r"
end
if writable then
permissions = permissions .. "w"
end
if executable then
permissions = permissions .. "x"
end
return permissions
end
local function statusline()
local file_name = " %f"
local modified = "%m"
local align_right = "%="
local fileencoding = " %{&fileencoding?&fileencoding:&encoding}"
local filetype = " %y"
local percentage = "(%p%%)"
local linecol = "[%l:%L][%{luaeval('get_line_chars()')}]"
local perms = ' %{luaeval("get_buffer_perms()")}'
local diagnostics = ' %{% luaeval("get_diagnostic_count()")%}'
local mode_name = '%{luaeval("get_mode_name(vim.fn.mode())")}'
local buffer = " %{luaeval('format_filename()')}" -- vim.fn.expand('%:t') ~= '' and vim.fn.expand('%:t') or 'nil'
local mode_highlight = '%{%(luaeval("get_mode_highlight(vim.fn.mode())"))%}'
local rm_highlight = '%*'
return string.format(
"%s [%s] %s%s%s%s%s%s%s%s%s ",
mode_highlight,
mode_name,
rm_highlight,
buffer,
modified,
linecol,
percentage,
diagnostics,
align_right,
filetype,
fileencoding,
perms
)
end
vim.opt.statusline = statusline()

23
lua/core/tabline.lua Normal file
View File

@ -0,0 +1,23 @@
function custom_tabline()
local current_tab = vim.fn.tabpagenr()
local tabline = ''
for t = 1, vim.fn.tabpagenr('$') do
local win_count = vim.fn.tabpagewinnr(t, '$')
local buflist = vim.fn.tabpagebuflist(t)
local bufnr = buflist[1]
tabline = tabline .. (t == current_tab and '%#tabSepInactive2#' or '%#tabSepInactive2#')
tabline = tabline .. (t == current_tab and '%#tabSepSpecial#' or '')
tabline = tabline .. (t == current_tab and '%#tabActive#' or '%#tabInactive#')
tabline = tabline .. ' ' .. (t-1)..': '
--tabline = tabline .. ' '
tabline = tabline .. ' ' .. vim.fn.fnamemodify(vim.fn.bufname(bufnr), ':t') .. ' '
tabline = tabline .. ' '
tabline = tabline .. (t == current_tab and '%#tabSepActive#' or '%#tabSepInactive#')
tabline = tabline .. '%*'
end
return tabline .. '%*'
end
-- vim.o.tabline = '%{%luaeval("custom_tabline()")%}'