Refactor the entire configuration

With the release of the Nvidia 555 beta drivers and their improvements to
the Wayland experience I've finally decided to return to NixOS with
Hyprland again after 2 years of running Gentoo and Opensuse Tumbleweed
on X11. So this is me committing the work done so far from the last
couple of days. Future commits will be more incremental.
This commit is contained in:
caem 2024-05-24 21:33:00 +02:00
parent 97c86fb014
commit 75b13ac379
Signed by: caem
GPG key ID: 69A830D03203405F
72 changed files with 2045 additions and 196 deletions

View file

@ -0,0 +1,3 @@
require"settings"
require"plugins"

View file

@ -0,0 +1,7 @@
return {
"m4xshen/autoclose.nvim",
config = function()
require"autoclose".setup()
end
}

View file

@ -0,0 +1,55 @@
return {
"hrsh7th/nvim-cmp",
dependencies = {
"L3MON4D3/LuaSnip",
"saadparwaiz1/cmp_luasnip",
"hrsh7th/cmp-buffer",
"hrsh7th/cmp-path",
"hrsh7th/cmp-nvim-lsp",
{
"tamago324/cmp-zsh",
config = function()
require"cmp_zsh".setup {
zshrc = true,
filetypes = { "bash", "zsh", "sh" },
}
end,
},
"ray-x/cmp-treesitter",
"hrsh7th/cmp-nvim-lua",
"andersevenrud/cmp-tmux",
},
config = function()
local cmp = require"cmp"
cmp.setup {
snippet = {
expand = function(args)
require"luasnip".lsp_expand(args.body)
end,
},
view = {
entries = "native",
},
mapping = cmp.mapping.preset.insert {
['<C-k>'] = cmp.mapping.select_prev_item(),
['<C-j>'] = cmp.mapping.select_next_item(),
['<A-j>'] = cmp.mapping.scroll_docs(4),
['<A-k>'] = cmp.mapping.scroll_docs(-4),
['<S-CR>'] = cmp.mapping.complete(),
['<C-Space>'] = cmp.mapping.confirm({ select = true }),
['<C-e>'] = cmp.mapping.abort(),
},
sources = {
{ name = "path" },
{ name = "luasnip" },
{ name = "zsh" },
{ name = "nvim_lsp" },
{ name = "buffer" },
{ name = "treesitter" },
{ name = "nvim-lua" },
{ name = "tmux" },
},
}
end
}

View file

@ -0,0 +1,5 @@
return {
"numToStr/Comment.nvim",
opts = {},
lazy = false
}

View file

@ -0,0 +1,4 @@
return {
"stevearc/dressing.nvim",
opts = {}
}

View file

@ -0,0 +1,12 @@
return {
"ellisonleao/gruvbox.nvim",
priority = 1000,
config = function()
require"gruvbox".setup {
transparent_mode = true,
contrast = "soft",
}
vim.cmd("colorscheme gruvbox")
end,
}

View file

@ -0,0 +1,11 @@
return {
"lukas-reineke/indent-blankline.nvim",
main = "ibl",
opts = {},
opts = {
indent = {
char = ""
}
}
}

View file

@ -0,0 +1,22 @@
if vim.fn.executable("git") ~= 1 then
vim.notify("git is not installed. Skipping plugins.", vim.log.levels.WARN)
return
end
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not (vim.uv or vim.loop).fs_stat(lazypath) then
vim.fn.system({
"git",
"clone",
"--filter=blob:none",
"https://github.com/folke/lazy.nvim.git",
"--branch=stable", -- latest stable release
lazypath,
})
end
vim.opt.rtp:prepend(lazypath)
plugins = require"util.require_dir"(vim.fn.stdpath("config").."/lua/plugins/", true)
require"lazy".setup(plugins)

View file

@ -0,0 +1,12 @@
return {}
-- Currently using gruvbox
--[[return {
"rebelot/kanagawa.nvim",
config = function()
require"kanagawa".setup {
transparent = true
}
vim.cmd("colorscheme kanagawa-dragon")
end
}
]]--

View file

@ -0,0 +1,5 @@
return function ()
require"lspconfig".clangd.setup {
capabilities = require"cmp_nvim_lsp".default_capabilities()
}
end

View file

@ -0,0 +1,24 @@
return function()
require'lspconfig'.lua_ls.setup {
capabilities = require"cmp_nvim_lsp".default_capabilities(),
on_init = function(client)
local path = client.workspace_folders[1].name
if vim.loop.fs_stat(path..'/.luarc.json') or vim.loop.fs_stat(path..'/.luarc.jsonc') then
return
end
client.config.settings.Lua = vim.tbl_deep_extend('force', client.config.settings.Lua, {
runtime = {
version = 'LuaJIT'
},
workspace = {
checkThirdParty = false,
library = vim.api.nvim_get_runtime_file("", true)
}
})
end,
settings = {
Lua = {}
}
}
end

View file

@ -0,0 +1,6 @@
return function ()
require"lspconfig".nil_ls.setup {
capabilities = require"cmp_nvim_lsp".default_capabilities()
}
end

View file

@ -0,0 +1,5 @@
return function ()
require"lspconfig".intelephense. setup {
capabilities = require"cmp_nvim_lsp".default_capabilities(),
}
end

View file

@ -0,0 +1,29 @@
return {
"neovim/nvim-lspconfig",
config = function()
local require_dir = require"util.require_dir"
local lspees = require_dir(vim.fn.stdpath("config").."/lua/plugins/lsp/", "plugins.lsp")
for _, lspee in ipairs(lspees) do
lspee()
end
local map = require"util.map"
local vlb = vim.lsp.buf
local format = function()
vlb.format { async = true }
end
vim.api.nvim_create_autocmd("LspAttach", {
group = vim.api.nvim_create_augroup("UserLspConfig", {}),
callback = function()
map("n", "<leader>lgD", vlb.declaration, "[l]sp [g]o to [D]eclaration")
map("n", "<leader>lgd", vlb.definition, "[l]sp [g]o to [d]definition")
map("n", "<leader>lgi", vlb.implementation, "[l]sp [g]o to [i]mplementation")
map("n", "<leader>lgr", vlb.references, "[l]sp [g]o to [r]eferences")
map("n", "<leader>lh", vlb.hover, "[l]sp [h]over over selection")
map("n", "<leader>lfm", format, "[l]sp [f]or[m]at file")
map("n", "<leader>lca", vlb.code_action, "[l]sp [C]ode [a]ction")
end,
})
end
}

View file

@ -0,0 +1,139 @@
return {
"nvim-lualine/lualine.nvim",
dependencies = {
"nvim-tree/nvim-web-devicons",
},
config = function()
-- Inspired by https://github.com/nvim-lualine/lualine.nvim/blob/master/examples/evil_lualine.lua
local rgb_to_hex = require"util.rgb_to_hex"
local hl = require"util.hl"
local config = {
options = {
component_separators = "",
section_separators = "",
theme = {
normal = {
c = {
fg = rgb_to_hex(hl("Normal").fg),
bg = rgb_to_hex(hl("Normal").bg),
},
},
inactive = {
c = {
fg = rgb_to_hex(hl("Normal").fg),
bg = rgb_to_hex(hl("Normal").bg),
},
},
},
},
sections = {
lualine_a = {}, lualine_b = {}, lualine_y = {}, lualine_z = {}, -- Remove defaults
lualine_c = {}, lualine_x = {}, -- Extend these later
},
inactive_sections = {
lualine_a = {}, lualine_b = {}, lualine_c = {}, lualine_x = {}, lualine_y = {}, lualine_z = {},
},
}
local function buffer_not_empty()
return vim.fn.empty(vim.fn.expand("%:t")) ~= 1
end
local function ins_l(component)
table.insert(config.sections.lualine_c, component)
end
local function ins_r(component)
table.insert(config.sections.lualine_x, component)
end
local distro = require"util.get_distro"()
ins_l {
function()
return ""
end,
padding = {
left = 0,
right = 0,
},
color = {
fg = rgb_to_hex(hl("Comment").fg),
},
}
ins_l {
function()
return distro.traits.icon
end,
color = {
fg = distro.traits.color,
},
}
ins_l {
"filename",
cond = buffer_not_empty,
color = {
fg = rgb_to_hex(hl("Operator").fg),
}
}
ins_l {
"filesize",
cond = buffer_not_empty,
}
ins_l {
"o:encoding",
cond = buffer_not_empty,
}
ins_l {
"fileformat",
icons_enabled = false,
cond = buffer_not_empty,
}
ins_r { "diagnostics" }
ins_r { "diff" }
ins_r {
"branch",
padding = {
right = 0,
},
color = {
fg = rgb_to_hex(hl("Constant").fg)
}
}
ins_r {
"location",
}
ins_r {
"mode",
fmt = string.lower,
color = {
fg = rgb_to_hex(hl("String").fg),
}
}
ins_r {
function()
return ""
end,
padding = {
left = 0,
right = 0,
},
color = {
fg = rgb_to_hex(hl("Comment").fg),
}
}
require"lualine".setup(config)
end
}

View file

@ -0,0 +1,6 @@
return {
"norcalli/nvim-colorizer.lua",
config = function()
require"colorizer".setup()
end,
}

View file

@ -0,0 +1,30 @@
return {
"nvim-telescope/telescope.nvim",
dependencies = { "nvim-lua/plenary.nvim" },
config = function()
require"telescope".setup {}
local tb = require"telescope.builtin"
local map = require"util.map"
-- Default pickers
map("n", "<leader>tf", function()
if vim.fn.isdirectory(".git") ~= 0 then
tb.git_files()
else
tb.find_files()
end
end, "[T]elescope [f]iles")
map("n", "<leader>tg", tb.live_grep, "[T]elescope [g]rep")
map("n", "<leader>tb", tb.buffers, "[T]elescope [b]uffers")
map("n", "<leader>tm", function()
tb.man_pages({ "ALL" })
end, "[T]elescope [m]an pages")
map("n", "<leader>tk", tb.keymaps, "[T]elescope [k]eymaps")
map("n", "<leader>tk", tb.keymaps, "[T]elescope [k]eymaps")
-- LSP pickers
map("n", "<leader>tld", tb.diagnostics, "[T]elescope [l]sp [d]iagnostics")
map("n", "<leader>tlr", tb.lsp_references, "[T]elescope [l]sp [r]eferences")
end,
}

View file

@ -0,0 +1,15 @@
return {
"nvim-treesitter/nvim-treesitter",
config = function()
require"nvim-treesitter.configs".setup {
ensure_installed = "all", -- pipebomb
highlight = {
enable = true,
},
indent = {
enable = true,
},
}
end,
run = ":TSUpdate",
}

View file

@ -0,0 +1,10 @@
-- 2 indentation languages
vim.api.nvim_create_autocmd({"BufEnter", "BufWinEnter"}, {
pattern = {"*.lua", "*.nix"},
callback = function()
vim.opt.tabstop = 2
vim.opt.softtabstop = 2
vim.opt.shiftwidth = 2
end
})

View file

@ -0,0 +1,3 @@
require"settings.options"
require"settings.autocmds"
require"settings.keymaps"

View file

@ -0,0 +1,7 @@
local map = require"util.map"
map("n", "<Space>", "<Nop>", "Mapleader")
vim.g.mapleader = " "
map("n", "<leader>df", vim.diagnostic.open_float, "[D]iagnostics [f]loat")

View file

@ -0,0 +1,25 @@
local options = {
tabstop = 4,
softtabstop = 4,
shiftwidth = 4,
expandtab = true,
number = true,
relativenumber = true,
fileencoding = "utf-8",
cursorline = true,
wrap = false,
signcolumn = "yes",
swapfile = false,
errorbells = false,
undofile = true,
incsearch = true,
hlsearch = false,
backup = false,
}
for option, value in pairs(options) do
pcall(function()
vim.opt[option] = value
end)
end

View file

@ -0,0 +1,59 @@
local function distro_traits(name)
local icons = {
[ "unknown" ] = {
icon = "",
color = "#f3be25",
},
[ "debian" ] = {
icon = "",
color = "#d70a53",
},
[ "gentoo" ] = {
icon = "",
color = "#54487A",
},
[ "nixos" ] = {
icon = "",
color = "#5277C3",
},
[ "\"opensuse-tumbleweed\"" ] = {
icon = "",
color = "#73ba25",
},
}
local icon = icons[name]
if icon == nil then
icon = icons["unknown"]
end
return icon
end
return function()
local release_file = io.open("/etc/os-release", "rb")
if release_file == nil then
return {
name = "unknown",
traits = distro_traits("unknown"),
}
end
local content = vim.split(release_file:read("*a"), "\n")
local distro_id = nil
for _, line in ipairs(content) do
if string.sub(line, 0, 3) == "ID=" then
distro_id = string.sub(line, 4, -1)
goto distro_id_found
end
end
::distro_id_found::
release_file:close()
return {
name = distro_id,
traits = distro_traits(distro_id)
}
end

View file

@ -0,0 +1,7 @@
return function (name)
local hl = vim.api.nvim_get_hl(0, { name = name })
while hl.link ~= nil do
hl = vim.api.nvim_get_hl(0, { name = hl.link })
end
return hl
end

View file

@ -0,0 +1,9 @@
return function(mode, key, mapping, comment)
local opts = {
noremap = true,
silent = true,
desc = comment
}
vim.keymap.set(mode, key, mapping, opts)
end

View file

@ -0,0 +1,27 @@
return function(dir, skip_init)
local returns = {}
local lua_files = vim.split(vim.fn.glob(dir.."/*.lua"), "\n")
local namespace = string.gsub(dir, vim.fn.stdpath("config").."/lua/", "")
namespace = string.gsub(namespace, "%/", ".")
for _, file in ipairs(lua_files) do
file = string.gsub(file, "%.lua", "")
file = string.gsub(file, dir.."/", namespace)
if skip_init and file == namespace.."init" then
goto continue
end
local require_ok, require_return = pcall(require, file)
if require_ok then
table.insert(returns, require_return)
else
vim.notify("Could not require file: '"..file.."': "..require_return, vim.log.levels.WARNING)
end
::continue::
end
return returns
end

View file

@ -0,0 +1,11 @@
return function(rgb)
if rgb == nil then
return nil
end
local r = string.format("%02x", (rgb / 65536) % 256)
local g = string.format("%02x", (rgb / 256) % 256)
local b = string.format("%02x", rgb % 256)
return "#"..r..g..b
end

View file

@ -0,0 +1,22 @@
{ pkgs, config, ... }:
{
programs.neovim = {
enable = true;
defaultEditor = true;
extraPackages = with pkgs; [
lua-language-server
nodePackages.intelephense
clang-tools
ripgrep
nil
gcc
];
};
home.file."${config.xdg.configHome}/nvim" = {
source = ./config;
recursive = true;
};
}