more stuff too lazy to seperate

This commit is contained in:
2023-11-24 21:38:31 -05:00
parent ed205a9545
commit 550cac1035
33 changed files with 488 additions and 246 deletions

9
lua/.luarc.json Normal file
View File

@ -0,0 +1,9 @@
{
"diagnostics.globals": [
"g",
"o",
"a",
"vim",
],
"workspace.checkThirdParty": false
}

View File

@ -1,7 +1,5 @@
local path = vim.fn.stdpath("data") .. "/site/pack/deps/opt/dep"
local path = vim.fn.stdpath("data").."/site/pack/deps/opt/dep"
if vim.fn.empty(vim.fn.glob(path)) > 0 then
vim.fn.system({ "git", "clone", "--depth=1", "https://git.squi.bid/dep", path })
end
vim.cmd("packadd dep")

View File

@ -1,71 +0,0 @@
-- helper functions that can come in handy ------------------------------------
local function run(cmd)
local x = io.popen(cmd)
if not x then return 1 end
local y = x:read("*a")
x:close()
return y
end
-- custom menu for simpler neovim managment -----------------------------------
local function genmenu()
local list = {}
local function add(name, plug)
if not plug then
table.insert(list, name)
return
end
if package.loaded[plug] then
table.insert(list, name)
end
end
add('edit config', nil)
add('update plugins', 'dep')
add('show keybinds', 'telescope')
add('change colorscheme', 'telescope')
add('new plugins', 'telescope')
return list
end
local function configmenu()
local list = genmenu()
vim.ui.select(list, { vpt = 'Config Menu' },
function(choice)
if choice == 'edit config' then
vim.cmd('e $XDG_CONFIG_HOME/nvim/init.lua')
end
if choice == 'update plugins' then
require('dep').sync()
if package.loaded['nvim-treesitter'] then
vim.cmd('TSUpdate')
end
if package.loaded['mason'] then
require('mason.api.command').MasonUpdate()
end
end
if choice == 'show keybinds' then
require('telescope.builtin').keymaps()
end
if choice == 'change colorscheme' then
vim.cmd("Colorscheme")
end
-- search though plugins (powered by nvim.sh)
if choice == 'new plugins' then
local result = run("curl -s https://nvim.sh/s")
local array = {}
for s in string.gmatch(result, "[^\r\n]+") do
table.insert(array, s)
end
local header = table.remove(array, 1)
vim.ui.select(array, { vpt = header }, function(choice)
end)
end
end)
end
vim.keymap.set('n', '<leader>m', configmenu, {
desc = "Neovim config manager menu",
})
vim.api.nvim_create_user_command("ConfigMenu", configmenu, {})

85
lua/conf/auto.lua Normal file
View File

@ -0,0 +1,85 @@
local function auto(event, opts)
a.nvim_create_autocmd(event, opts)
end
local function augroup(name, opts)
opts = opts or {}
opts['clear'] = true
a.nvim_create_augroup(name, opts)
end
local winchange = augroup('winchange')
local bufcheck = augroup('bufcheck')
local toggles = augroup('toggles')
auto({ "FocusGained", "TermClose", "TermLeave" }, {
group = bufcheck,
desc = 'Update contents of file.',
command = "checktime",
})
auto("VimResized", {
group = winchange,
desc = 'Resize splits when window is resized.',
callback = function()
local current_tab = vim.fn.tabpagenr()
vim.cmd("tabdo wincmd =")
vim.cmd("tabnext " .. current_tab)
end,
})
auto('TextYankPost', {
group = bufcheck,
pattern = '*',
desc = 'Highlight on yank.',
callback = function()
vim.highlight.on_yank{ timeout = 250 }
end
})
auto('BufRead', {
pattern = '*',
group = bufcheck,
desc = 'Return to the last place the buffer was closed in.',
callback = function() vim.cmd([[call setpos(".", getpos("'\""))]]) end
})
auto('FileType', {
pattern = { 'gitcommit', 'markdown' },
desc = 'Spell checking and wrapping in commit buffers and markdown files.',
callback = function()
vim.opt_local.wrap = true
vim.opt_local.spell = true
end
})
auto('BufWritePre', {
pattern = '*',
group = bufcheck,
desc = 'Basically mkdir -p.',
callback = function(ctx)
if ctx.match:match("^%w%w+://") then return end
local dir = vim.fn.fnamemodify(ctx.file, ':p:h')
vim.fn.mkdir(dir, 'p')
end
})
auto('WinLeave', {
pattern = '!Alpha',
desc = 'Unset cursorline',
group = toggles,
callback = function() vim.opt.cursorline = false end
})
auto('WinEnter', {
pattern = '!Alpha',
desc = 'Set cursorline',
group = toggles,
callback = function() vim.opt.cursorline = true end
})
auto('ColorScheme', {
desc = 'Update statusline on colorscheme change',
group = winchange,
callback = function() require('el').reset_windows() end
})

View File

@ -1,3 +1,5 @@
local conf = require('core.conf')
local function map(mode, bind, cmd, opts)
opts = opts or {}
opts['noremap'] = true
@ -52,6 +54,9 @@ map('n', '][', '<cmd>tabc<CR>')
map('n', '[[', '<cmd>tabp<CR>')
map('n', ']]', '<cmd>tabN<CR>')
-- config binds ---------------------------------------------------------------
map('n', '<leader>m', conf.configmenu, { desc = 'Neovim config manager menu', })
-- plugin binds ---------------------------------------------------------------
-- pretty lsp view
@ -78,7 +83,7 @@ if pcall(require, "telescope") then
{ desc = 'Find LSP Symbols.' })
-- search for keybinds
map('n', '<leader>sk', telebuilt.keymaps,
{ desc = 'Find nvim Highlights.' })
{ desc = 'Find nvim Keymaps.' })
-- search for highlights
map('n', '<leader>sh', telebuilt.highlights,
{ desc = 'Find nvim Highlights.' })
@ -89,7 +94,13 @@ if pcall(require, "telescope") then
map('n', '<leader>sv', telebuilt.vim_options, { desc = 'Find vim options.' })
-- search for string in project
map('n', '<leader>sp', function()
telebuilt.grep_string({ search = vim.fn.input('Find string in project > ')})
vim.ui.input({ prompt = 'Find string in project' }, function(input)
if not input or input == '' then
vim.notify('No query!', vim.log.levels.WARN, { title = misc.appid })
return nil
end
telebuilt.grep_string({ search = input })
end)
end, { desc = 'Find string in project.' })
-- Code Actions (requires telescope)
if pcall(require, "actions-preview") then
@ -141,17 +152,18 @@ end
-- venn
function _G.Toggle_venn()
local mapb = vim.api.nvim_buf_set_keymap
local venn_enabled = vim.inspect(vim.b.venn_enabled)
if venn_enabled == "nil" then
vim.b.venn_enabled = true
vim.cmd([[setlocal ve=all]])
-- draw a line on HJKL keystokes
vim.api.nvim_buf_set_keymap(0, "n", "J", "<C-v>j:VBox<CR>", {noremap = true})
vim.api.nvim_buf_set_keymap(0, "n", "K", "<C-v>k:VBox<CR>", {noremap = true})
vim.api.nvim_buf_set_keymap(0, "n", "L", "<C-v>l:VBox<CR>", {noremap = true})
vim.api.nvim_buf_set_keymap(0, "n", "H", "<C-v>h:VBox<CR>", {noremap = true})
mapb(0, "n", "J", "<C-v>j:VBox<CR>", { noremap = true })
mapb(0, "n", "K", "<C-v>k:VBox<CR>", { noremap = true })
mapb(0, "n", "L", "<C-v>l:VBox<CR>", { noremap = true })
mapb(0, "n", "H", "<C-v>h:VBox<CR>", { noremap = true })
-- draw a box by pressing "f" with visual selection
vim.api.nvim_buf_set_keymap(0, "v", "f", ":VBox<CR>", {noremap = true})
mapb(0, "v", "f", ":VBox<CR>", { noremap = true })
else
vim.cmd[[setlocal ve=]]
vim.cmd[[mapclear <buffer>]]
@ -159,4 +171,4 @@ function _G.Toggle_venn()
end
end
-- toggle keymappings for venn using <leader>v
vim.api.nvim_set_keymap('n', '<leader>v', ":lua Toggle_venn()<CR>", { noremap = true})
map('n', '<leader>v', ":lua Toggle_venn()<CR>")

4
lua/conf/init.lua Normal file
View File

@ -0,0 +1,4 @@
misc.include('conf.plugins') -- load plugins first to allow colorscheme to be set in opts
misc.include('conf.opts')
misc.include('conf.binds')
misc.include('conf.auto')

View File

@ -31,11 +31,11 @@ o.softtabstop = tabwidth
-- colorscheme
o.termguicolors = true
vim.cmd('colorscheme mellow') -- mellow
vim.cmd('colorscheme mellow+') -- some changes
misc.colorscheme('mellow')
-- better editing -------------------------------------------------------------
o.clipboard = 'unnamedplus' -- system clipboard
o.splitkeep = "screen" -- keep same text on screen when spliting
-- file saving ----------------------------------------------------------------
o.swapfile = false

View File

@ -1,15 +1,11 @@
require 'dep' {
sync = "always",
require('dep') {
-- dep manages dep ----------------------------------------------------------
{ 'squibid/dep',
url = 'https://git.squi.bid/dep',
pin = true,
-- branch = 'dev'
},
{ 'squibid/git-yodel',
url = 'https://git.squi.bid/git-yodel'
},
-- colorschemes -------------------------------------------------------------
{ 'kvrohit/mellow.nvim',
requires = 'nvim-treesitter/nvim-treesitter'
@ -20,19 +16,24 @@ require 'dep' {
{ 'folke/which-key.nvim' }, -- key map help
{ 'rcarriga/nvim-notify' }, -- notifications
{ 'tjdevries/express_line.nvim', -- status bar
requires = 'nvim-lua/plenary.nvim',
requires = 'nvim-lua/plenary.nvim'
},
{ 'goolord/alpha-nvim' }, -- start page
{ 'dinhhuy258/sfm.nvim', -- tree view
deps = 'dinhhuy258/sfm-git.nvim',
deps = 'dinhhuy258/sfm-git.nvim'
},
{ 'matbme/JABS.nvim' }, -- buffer switcher
{ 'tomiis4/Hypersonic.nvim' }, -- regex helper/displayer
{ 'stevearc/dressing.nvim', -- nice ui selectors
requires = 'nvim-telescope/telescope.nvim'
},
{ 'lukas-reineke/headlines.nvim',
requires = 'nvim-neorg/neorg'
},
-- functional plugins -------------------------------------------------------
{ 'lewis6991/gitsigns.nvim' }, -- very helpful git things
{ 'squibid/git-yodel', -- git cache diff preview when in commit buffer
url = 'https://git.squi.bid/git-yodel'
url = 'https://git.squi.bid/git-yodel',
},
{ 'chentoast/marks.nvim' }, -- marks in gutter
{ 'vidocqh/auto-indent.nvim' }, -- better tabbing into indents
@ -65,23 +66,28 @@ require 'dep' {
requires = 'nvim-lua/plenary.nvim',
deps = {
'nvim-telescope/telescope-file-browser.nvim',
'nvim-telescope/telescope-ui-select.nvim',
'nvim-telescope/telescope-symbols.nvim',
'axieax/urlview.nvim',
'axieax/urlview.nvim'
}
},
{ 'nvim-telescope/telescope-fzf-native.nvim',
config = function()
vim.cmd('make')
end,
requires = 'nvim-telescope/telescope.nvim'
},
-- treesitter + colorizing --------------------------------------------------
{ 'nvim-treesitter/nvim-treesitter',
deps = {
'm-demare/hlargs.nvim',
'Wansmer/treesj',
'nvim-treesitter/nvim-treesitter-context',
'nvim-treesitter/nvim-treesitter-context'
}
},
{ 'NvChad/nvim-colorizer.lua' },
{ 'folke/todo-comments.nvim',
requires = 'nvim-lua/plenary.nvim',
requires = 'nvim-lua/plenary.nvim'
},
-- cmp ----------------------------------------------------------------------
@ -91,23 +97,24 @@ require 'dep' {
'hrsh7th/cmp-buffer', -- buffers
'FelipeLema/cmp-async-path', -- path
'hrsh7th/cmp-calc', -- calculator
'saadparwaiz1/cmp_luasnip', -- snippets
'hrsh7th/cmp-nvim-lsp', -- lsp
'uga-rosa/cmp-dictionary', -- dictionary
'hrsh7th/cmp-nvim-lua', -- nvim lua api
{ 'doxnit/cmp-luasnip-choice', -- luasnip
requires = 'L3MON4D3/LuaSnip'
}
},
},
-- snippets -----------------------------------------------------------------
{ 'L3MON4D3/LuaSnip',
deps = 'rafamadriz/friendly-snippets',
deps = 'rafamadriz/friendly-snippets'
},
{ 'doxnit/cmp-luasnip-choice' },
-- lsp ----------------------------------------------------------------------
{ 'neovim/nvim-lspconfig' }, -- setup lsp
{ 'j-hui/fidget.nvim', -- shows lsp progress
branch = 'legacy',
branch = 'legacy'
},
{ 'ray-x/lsp_signature.nvim' }, -- see information about the current function
@ -121,14 +128,14 @@ require 'dep' {
},
{ 'whynothugo/lsp_lines.nvim',
url = 'https://git.sr.ht/~whynothugo/lsp_lines.nvim',
url = 'https://git.sr.ht/~whynothugo/lsp_lines.nvim'
},
-- mason --------------------------------------------------------------------
{ 'williamboman/mason.nvim',
deps = {
'WhoIsSethDaniel/mason-tool-installer.nvim',
'williamboman/mason-lspconfig.nvim',
'williamboman/mason-lspconfig.nvim'
}
}
}

View File

@ -1,30 +0,0 @@
local function auto(event, opts)
a.nvim_create_autocmd(event, opts)
end
a.nvim_create_augroup('bufcheck', { clear = true })
auto('TextYankPost', { -- highlight yanks
group = 'bufcheck',
pattern = '*',
desc = 'Highlight on yank.',
callback = function()
vim.highlight.on_yank{ timeout = 250 }
end
})
auto('BufRead', { -- return to last place
pattern = '*',
command = [[call setpos(".", getpos("'\""))]],
desc = 'Return to the last place the buffer was closed in.',
})
auto('BufWritePre', { -- make dirs when they don't exist
pattern = '*',
group = vim.api.nvim_create_augroup('auto_create_dir', { clear = true }),
desc = 'Basically mkdir -p.',
callback = function(ctx)
local dir = vim.fn.fnamemodify(ctx.file, ':p:h')
vim.fn.mkdir(dir, 'p')
end
})

View File

@ -1,8 +0,0 @@
local function cmd(name, exec, opts)
opts = opts or {}
vim.api.nvim_create_user_command(name, exec, opts)
end
cmd('Colorscheme', function()
require('telescope.builtin').colorscheme()
end)

81
lua/core/conf.lua Normal file
View File

@ -0,0 +1,81 @@
local pickers = require("telescope.pickers")
local finders = require("telescope.finders")
local previewers = require("telescope.previewers")
local conf = require("telescope.config").values
local actions = require("telescope.actions")
local action_state = require("telescope.actions.state")
local M = {}
local function genmenu()
local list = {}
local function add(name, plug)
if not plug then
table.insert(list, name)
elseif package.loaded[plug] then
table.insert(list, name)
end
end
add('Edit Config', nil)
add('Update Plugins', 'dep')
add('Keybinds', 'telescope')
add('Colorscheme', 'telescope')
return list
end
function M.configmenu()
pickers.new({
prompt_title = "Nvim Config Menu",
finder = finders.new_table { results = genmenu() },
sorter = conf.generic_sorter(),
previewer = previewers.new_buffer_previewer {
define_preview = function(self, entry)
local lines = {
'a'
}
if entry.value == "Edit Config" then
lines = misc.readf(os.getenv('XDG_CONFIG_HOME')..'/nvim/init.lua')
local ft = vim.filetype.match({
filename = os.getenv('XDG_CONFIG_HOME')..'/nvim/init.lua' })
require("telescope.previewers.utils").highlighter(self.state.bufnr, ft)
elseif entry.value == "Colorscheme" then
lines = vim.fn.getcompletion('', 'color')
for k, v in pairs(lines) do
if v.find(v, '.ext') then
table.remove(lines, k)
break
end
end
end
vim.api.nvim_buf_set_lines(self.state.bufnr, 0, -1, false, lines)
end
},
attach_mappings = function(bufnr, map)
actions.select_default:replace(function()
actions.close(bufnr)
local selection = action_state.get_selected_entry()
if selection[1] == 'Edit Config' then
vim.cmd('e $XDG_CONFIG_HOME/nvim/init.lua')
elseif selection[1] == 'Update Plugins' then
require('dep').sync()
if package.loaded['nvim-treesitter'] then
vim.cmd('TSUpdate')
end
if package.loaded['mason'] then
require('mason.api.command').MasonUpdate()
end
elseif selection[1] == 'Keybinds' then
require('telescope.builtin').keymaps()
elseif selection[1] == 'Colorscheme' then
require('core.theme').switcher()
end
end)
return true
end,
}):find()
end
return M

View File

@ -1,5 +0,0 @@
require('core.plugins') -- load plugins first to allow colorscheme to be set in opts
require('core.opts')
require('core.binds')
require('core.auto')
require('core.cmds')

30
lua/core/misc.lua Normal file
View File

@ -0,0 +1,30 @@
local M = {}
M.appid = "Nvim Config"
function M.colorscheme(name)
vim.cmd('colorscheme '..name)
for k, v in pairs(vim.fn.getcompletion('', 'color')) do
if v == name..'.ext' then
vim.cmd('colorscheme '..name..'.ext')
end
end
end
function M.include(fn)
if not pcall(require, fn) then
vim.notify('Could not find '..fn, vim.log.levels.WARN, { title = M.appid })
end
end
function M.readf(fn)
local f = io.open(fn, "r")
if not f then return nil end
local tab = {}
for l in f:lines() do
table.insert(tab, l)
end
return tab
end
return M

76
lua/core/theme.lua Normal file
View File

@ -0,0 +1,76 @@
local pickers = require("telescope.pickers")
local finders = require("telescope.finders")
local previewers = require("telescope.previewers")
local conf = require("telescope.config").values
local actions = require("telescope.actions")
local action_set = require("telescope.actions.set")
local action_state = require("telescope.actions.state")
local misc = require('core.misc')
local M = {}
function M.switcher()
local bufnr = vim.api.nvim_get_current_buf()
-- show current buffer content in previewer
local colors = vim.fn.getcompletion('', 'color')
for k, v in pairs(colors) do
if v.find(v, '.ext') then
table.remove(colors, k)
break
end
end
-- our picker function: colors
pickers.new({
prompt_title = "Set Nvim Colorscheme",
finder = finders.new_table { results = colors },
sorter = conf.generic_sorter(),
previewer = previewers.new_buffer_previewer {
define_preview = function(self, entry)
-- add content
local lines = vim.api.nvim_buf_get_lines(bufnr, 0, -1, false)
vim.api.nvim_buf_set_lines(self.state.bufnr, 0, -1, false, lines)
-- add syntax highlighting in previewer
local ft = (vim.filetype.match { buf = bufnr } or "diff"):match "%w+"
require("telescope.previewers.utils").highlighter(self.state.bufnr, ft)
end
},
attach_mappings = function(prompt_bufnr, map)
-- reload theme while typing
vim.schedule(function()
vim.api.nvim_create_autocmd("TextChangedI", {
buffer = prompt_bufnr,
callback = function()
if action_state.get_selected_entry() then
misc.colorscheme(action_state.get_selected_entry()[1])
end
end,
})
end)
-- reload theme on cycling
actions.move_selection_previous:replace(function()
action_set.shift_selection(prompt_bufnr, -1)
misc.colorscheme(action_state.get_selected_entry()[1])
end)
actions.move_selection_next:replace(function()
action_set.shift_selection(prompt_bufnr, 1)
misc.colorscheme(action_state.get_selected_entry()[1])
end)
-- reload theme on selection
actions.select_default:replace(function()
if action_state.get_selected_entry() then
actions.close(prompt_bufnr)
misc.colorscheme(action_state.get_selected_entry()[1])
end
end)
return true
end,
}):find()
end
return M

View File

@ -54,4 +54,26 @@ ls.add_snippets('c', {
}
)
),
s({
name = 'Variadic function parser',
trig = 'infinite vars',
dscr = 'Parse an infinite number of arguments passed to a function',
},
{
t({
"/*",
" * NOTE: the function must have a int before the ... argument",
" * and you need to include <stdarg.h> for this to work",
" */",
"va_list ptr;",
"va_start(ptr, ", i(1, "n"),
");",
"for (int i = 0; i < ", ri(1),
"; i++) {",
i(2),
"}",
"va_end(ptr);",
}),
}
)
})