Move files out of their respective fs structure into program dirs in root and symlink dotfils using HM.

This commit is contained in:
Martin Larsson 2025-01-16 23:49:38 +00:00
parent 10bab010b7
commit fb2adb4547
72 changed files with 9 additions and 0 deletions

5
nvim/.luarc.json Normal file
View file

@ -0,0 +1,5 @@
{
"diagnostics.globals": [
"vim"
]
}

48
nvim/init.lua Normal file
View file

@ -0,0 +1,48 @@
local function setup_yank_highlight()
vim.api.nvim_set_hl(0, "YankHighlight", { bg = "#e0af68" })
local yank_autocommand = vim.api.nvim_create_augroup("YankHighlightAutocommand", { clear = true })
vim.api.nvim_create_autocmd("TextYankPost", {
callback = function()
vim.highlight.on_yank({
timeout = 250,
higroup = "YankHighlight",
})
end,
group = yank_autocommand,
})
end
-- Load keymaps before loading any plugins
require("keymaps")
-- change and personalize native vim settings
vim.opt = require("vim_opt")
-- Initialize Lazy package manager
require("lazy_init")
-- Initialize the sticky terminal window at the bottom
require("terminal")
-- Initialize the custom window management functionality
require("window_management").setup()
-- Initializes custom commands and keybindings for handling code formatting
require("format_handler").setup()
-- Set configs for servers and enable them in the Neovim LSP Client
require("lsp/setup")
-- Set configs for nvim-dap so we can debug
require("dap/setup")
-- See ":help vim.highlight.on_yank()"
setup_yank_highlight()
--[[
-- Annoyances in Neovim environment:
-- 1. codelldb doesn't terminate C++ program after debugging. : Don't know how to fix, have asked for help.
-- 2. Sometimes very seldomly the cursor stops rendering, the only fix I found is to restsart Neovim.
-- 3. Add PR to lspsaga so you can add keybindings for closing hover_doc, rename, finder, incoming_calls, and code actions using many configurable keybindings. I'm after "<Esc>" and "q".
--]]

47
nvim/lazy-lock.json Normal file
View file

@ -0,0 +1,47 @@
{
"arrow.nvim": { "branch": "master", "commit": "5438c977e729a29d96bd54c8da3103154e80dbd1" },
"auto-session": { "branch": "main", "commit": "021b64ed7d4ac68a37be3ad28d8e1cba5bec582c" },
"blink.cmp": { "branch": "main", "commit": "1cc3b1a908fbcfd15451c4772759549724f38524" },
"codecompanion.nvim": { "branch": "main", "commit": "e3c528aab52f32513fdb771e3e27d93efe57e12a" },
"codesnap.nvim": { "branch": "main", "commit": "6400480aa6cc366cbd931146c429aaa64680dab9" },
"copilot.vim": { "branch": "release", "commit": "87038123804796ca7af20d1b71c3428d858a9124" },
"diffview.nvim": { "branch": "main", "commit": "4516612fe98ff56ae0415a259ff6361a89419b0a" },
"dressing.nvim": { "branch": "master", "commit": "3a45525bb182730fe462325c99395529308f431e" },
"fzf-lua": { "branch": "main", "commit": "6f7249741168c0751356e3b6c5c1e3bade833b6b" },
"gitsigns.nvim": { "branch": "main", "commit": "76d88f3b584e1f83b2aa51663a32cc6ee8d97eff" },
"incline.nvim": { "branch": "main", "commit": "16fc9c073e3ea4175b66ad94375df6d73fc114c0" },
"indent-blankline.nvim": { "branch": "master", "commit": "7a698a1d7ed755af9f5a88733b23ca246ce2df28" },
"lazy.nvim": { "branch": "main", "commit": "d8f26efd456190241afd1b0f5235fe6fdba13d4a" },
"leap.nvim": { "branch": "main", "commit": "c6bfb191f1161fbabace1f36f578a20ac6c7642c" },
"lspsaga.nvim": { "branch": "main", "commit": "7dae6e92c82964a8889d3cd999dfd4f271e3a873" },
"lua-utils.nvim": { "branch": "main", "commit": "e565749421f4bbb5d2e85e37c3cef9d56553d8bd" },
"lualine.nvim": { "branch": "master", "commit": "2a5bae925481f999263d6f5ed8361baef8df4f83" },
"mason-tool-installer.nvim": { "branch": "main", "commit": "c5e07b8ff54187716334d585db34282e46fa2932" },
"mason.nvim": { "branch": "main", "commit": "e2f7f9044ec30067bc11800a9e266664b88cda22" },
"mini.diff": { "branch": "main", "commit": "00f072250061ef498f91ed226918c9ec31a416a4" },
"neogit": { "branch": "master", "commit": "060a625660b2816649d83dbd6c7ab1b4345ea8bc" },
"neorg": { "branch": "main", "commit": "29993a7bb8279ffa0ba473a3f393daa28c645825" },
"neovim-ayu": { "branch": "master", "commit": "283badaa983234c90e857c12c1f1c18e1544360a" },
"noice.nvim": { "branch": "main", "commit": "eaed6cc9c06aa2013b5255349e4f26a6b17ab70f" },
"nui.nvim": { "branch": "main", "commit": "53e907ffe5eedebdca1cd503b00aa8692068ca46" },
"nvim-colorizer.lua": { "branch": "master", "commit": "a065833f35a3a7cc3ef137ac88b5381da2ba302e" },
"nvim-dap": { "branch": "master", "commit": "99807078c5089ed30e0547aa4b52c5867933f426" },
"nvim-dap-go": { "branch": "main", "commit": "1bacf2fa7d4dc6a8a4f6cc390f1544e5b34c35a4" },
"nvim-dap-python": { "branch": "master", "commit": "34282820bb713b9a5fdb120ae8dd85c2b3f49b51" },
"nvim-dap-repl-highlights": { "branch": "master", "commit": "a7512fc0a0de0c0be8d58983939856dda6f72451" },
"nvim-dap-ui": { "branch": "master", "commit": "727c032a8f63899baccb42a1c26f27687e62fc5e" },
"nvim-dap-virtual-text": { "branch": "master", "commit": "df66808cd78b5a97576bbaeee95ed5ca385a9750" },
"nvim-nio": { "branch": "master", "commit": "a428f309119086dc78dd4b19306d2d67be884eee" },
"nvim-notify": { "branch": "master", "commit": "a3020c2cf4dfc4c4f390c4a21e84e35e46cf5d17" },
"nvim-surround": { "branch": "main", "commit": "9f0cb495f25bff32c936062d85046fbda0c43517" },
"nvim-treesitter": { "branch": "master", "commit": "984214ef8e4ca18d77639663319aabdfba89632f" },
"nvim-treesitter-context": { "branch": "master", "commit": "d0dd7ce5a9d0be1f28086e818e52fdc5c78975df" },
"nvim-treesitter-textobjects": { "branch": "master", "commit": "ad8f0a472148c3e0ae9851e26a722ee4e29b1595" },
"nvim-web-devicons": { "branch": "master", "commit": "aafa5c187a15701a7299a392b907ec15d9a7075f" },
"pathlib.nvim": { "branch": "main", "commit": "57e5598af6fe253761c1b48e0b59b7cd6699e2c1" },
"persistent-breakpoints.nvim": { "branch": "main", "commit": "4b199b1dcfd136cac8b0fa9c8dbbdeb81463f7a9" },
"plenary.nvim": { "branch": "master", "commit": "3707cdb1e43f5cea73afb6037e6494e7ce847a66" },
"rustaceanvim": { "branch": "master", "commit": "0a1876b970ab946be3f4d341e9d743a5d62d646a" },
"tiny-inline-diagnostic.nvim": { "branch": "main", "commit": "5922bb3dd691a2a37bd51e20d4a3dc7895221e51" },
"vim-repeat": { "branch": "master", "commit": "65846025c15494983dafe5e3b46c8f88ab2e9635" }
}

View file

@ -0,0 +1,8 @@
return {
type = "server",
port = "${port}",
executable = {
command = vim.fn.exepath("codelldb"), -- Update with your codelldb binary path
args = { "--port", "${port}" },
},
}

View file

45
nvim/lua/dap/setup.lua Normal file
View file

@ -0,0 +1,45 @@
local utils = require("utils")
local dap = require("dap")
--[[
.vscode/launch.json:
----------------------------
{
"version": "0.2.0",
"configurations": [
{
"type": "name_of_adapter",
"request": "launch/attach",
"name": "Friendly name",
"program": "${workspaceFolder}/path/to/executable",
"cwd": "${workspaceFolder}",
"args": [],
"stopOnEntry": false,
"environment": []
}
]
}
----------------------------
]]
local dir_path = "dap/adapters"
utils.foreach(utils.get_file_names_in_dir(dir_path, "*.lua", true), function(adapter)
dap.adapters[adapter] = require(dir_path .. "/" .. adapter)
end)
-- Do not define default fallbacks until I have a better way of handling a default selected configuration.
-- I never want to be prompted for a configuration, we should have ae serialized active config which is always run unless changed.
-- -- Define configurations
-- dap.configurations.cpp = {
-- {
-- name = "Launch File",
-- type = "codelldb",
-- request = "launch",
-- program = function()
-- return vim.fn.input("Path to executable: ", vim.fn.getcwd() .. "/", "file")
-- end,
-- cwd = "${workspaceFolder}",
-- stopOnEntry = false,
-- args = {},
-- },
-- }

View file

@ -0,0 +1,44 @@
local utils = require("utils")
local M = {}
M.format_on_save = true
function M.format(force)
local do_force = force or false
if M.format_on_save or do_force then
vim.lsp.buf.format()
end
end
function M.format_enable()
M.format_on_save = true
end
function M.format_disable()
M.format_on_save = false
end
function M.setup()
local user_commands = {
{ "FormatEnable", "lua require('format_handler').format_enable()" },
{ "FormatDisable", "lua require('format_handler').format_disable()" },
}
for _, cmd in ipairs(user_commands) do
vim.api.nvim_command("command! " .. cmd[1] .. " " .. cmd[2])
end
utils.add_keymaps({
n = {
["<leader>ff"] = {
cmd = function() M.format(true) end
},
["<leader>fe"] = {
cmd = M.format_enable,
},
["<leader>fd"] = {
cmd = M.format_disable,
},
},
})
end
return M

View file

@ -0,0 +1,35 @@
local M = {}
M.hints_active = true
M.buffers = {}
function M.add_buffer(bufnr)
table.insert(M.buffers, bufnr)
vim.lsp.inlay_hint.enable(M.hints_active, { bufnr = bufnr })
vim.api.nvim_create_autocmd({ "BufDelete", "BufUnload" }, {
buffer = bufnr,
callback = function()
for i, buffer in ipairs(M.buffers) do
if buffer == bufnr then
table.remove(M.buffers, i)
break
end
end
end,
})
end
function M.disable()
for _, bufnr in ipairs(M.buffers) do
vim.lsp.inlay_hint.enable(false, { bufnr = bufnr })
end
end
function M.restore()
for _, bufnr in ipairs(M.buffers) do
vim.lsp.inlay_hint.enable(M.hints_active, { bufnr = bufnr })
end
end
return M

151
nvim/lua/keymaps.lua Normal file
View file

@ -0,0 +1,151 @@
local g = vim.g
g.mapleader = " "
g.maplocalleader = " "
local move_up = {
cmd = "v:count || mode(1)[0:1] == \"no\" ? \"k\" : \"gk\"",
opts = {
expr = true
}
}
local move_down = {
cmd = "v:count || mode(1)[0:1] == \"no\" ? \"j\" : \"gj\"",
opts = {
expr = true
}
}
local utils = require("utils")
utils.add_keymaps({
n = {
-- Using lspsaga for hover doc
["K"] = {
cmd = "<Nop>",
},
-- Using lspsaga finder with gr which does references
["grr"] = {
cmd = "<Nop>",
},
["gra"] = {
cmd = "<Nop>",
},
["grn"] = {
cmd = "<Nop>",
},
["gri"] = {
cmd = "<Nop>",
},
-- Navigation
["<C-Left>"] = {
cmd = "<C-w>h",
},
["<C-Down>"] = {
cmd = "<C-w>j",
},
["<C-Up>"] = {
cmd = "<C-w>k",
},
["<C-Right>"] = {
cmd = "<C-w>l",
},
["<C-h>"] = {
cmd = "<C-w>h",
},
["<C-j>"] = {
cmd = "<C-w>j",
},
["<C-k>"] = {
cmd = "<C-w>k",
},
["<C-l>"] = {
cmd = "<C-w>l",
},
-- Window
["<C-q>"] = {
cmd = "<C-w>q",
},
-- Disable current highlights
["<Esc>"] = {
cmd = "<cmd> noh <CR>",
},
-- Copies the entire file
["<C-c>"] = {
cmd = ":%y+<CR>",
opts = {
silent = true
}
},
-- Allow moving the cursor through wrapped lines with <Up> and <Down>
-- http://www.reddit.com/r/vim/comments/2k4cbr/problem_with_gj_and_gk/
-- empty mode is same as using <cmd> :map
-- also don't use g[j|k] when in operator pending mode, so it doesn't alter d, y or c behaviour
["<Up>"] = move_up,
["<Down>"] = move_down,
["j"] = move_down,
["k"] = move_up,
-- Maps to remove
["<C-z>"] = {
cmd = "<Nop>",
},
-- Marks are less frequently used than leaping, also, less relevant with arrow and fzf navigation.
-- Prioritize regular m for leaping, and <leader>m for setting marks.
["<leader>m"] = {
cmd = "m",
},
["[d"] = {
cmd = function()
vim.diagnostic.jump({ count = -1, float = false })
end
},
["]d"] = {
cmd = function()
vim.diagnostic.jump({ count = 1, float = false })
end
},
},
i = {},
v = {
["<Up>"] = move_up,
["<Down>"] = move_down,
["j"] = move_down,
["k"] = move_up,
["<tab>"] = {
cmd = ">gv",
},
["<S-tab>"] = {
cmd = "<gv",
},
-- Marks are less frequently used than leaping, also, less relevant with arrow and fzf navigation.
-- Prioritize regular m for leaping, and <leader>m for setting marks.
["<leader>m"] = {
cmd = "m",
},
},
x = {
["<Up>"] = move_up,
["<Down>"] = move_down,
["j"] = move_down,
["k"] = move_up,
["p"] = {
cmd = "p:let @+=@0<CR>:let @\"=@0<CR>",
opts = {
silent = true
},
},
},
t = {
["<C-q>"] = {
cmd = "<C-\\><C-N>",
},
},
})

19
nvim/lua/lazy_init.lua Normal file
View file

@ -0,0 +1,19 @@
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", -- latest stable release
lazypath,
})
end
vim.opt.rtp:prepend(lazypath)
-- Initialize plugins, add a plugin by creating a new file in the plugins dir
require("lazy").setup("plugs", {
git = {
timeout = 300
}
})

View file

@ -0,0 +1,62 @@
local utils = require("utils")
-- https://clangd.llvm.org/extensions.html#switch-between-sourceheader
local function switch_source_header(bufnr)
bufnr = utils.validate_bufnr(bufnr)
local clangd_client = vim.lsp.get_clients({ bufnr = bufnr, name = "clangd" })[1]
local params = { uri = vim.uri_from_bufnr(bufnr) }
if clangd_client then
clangd_client.request("textDocument/switchSourceHeader", params, function(err, result)
if err then
error(tostring(err))
end
if not result then
print "Corresponding file cannot be determined"
return
end
vim.api.nvim_command("drop " .. vim.uri_to_fname(result))
end, bufnr)
else
print "method textDocument/switchSourceHeader is not supported by any servers active on the current buffer"
end
end
return {
cmd = {
"clangd",
"--background-index", -- Enables background indexing
"--clang-tidy", -- Enables clang-tidy diagnostics
"--completion-style=bundled", -- Simpler completions for faster performance
"--rename-file-limit=0", -- No limit on renaming files
"--header-insertion=iwyu", -- Suggest missing includes based on IWYU
"--inlay-hints", -- Enable inlay hints for parameter and type information
"--limit-results=70", -- Limit autocompletion and symbol results
"--suggest-missing-includes", -- Still show missing includes suggestions
"--pch-storage=disk", -- Stores precompiled headers on disk (fixes the issue where system ran out of memory when indexing large projects, not a huge performance hit on fast m2 ssds)
"--log=error", -- Log only errors
},
filetypes = { "c", "cpp", "objc", "objcpp", "cuda", "proto" },
root_markers = {
".clangd",
".clang-tidy",
".clang-format",
"compile_commands.json",
"compile_flags.txt",
"configure.ac",
},
on_attach = function(_, bufnr)
local lsp_maps = {
{
"<leader>ko",
function() switch_source_header(0) end,
},
}
local keymaps = { n = {} }
for i, _ in ipairs(lsp_maps) do
local binding, cmd = unpack(lsp_maps[i])
keymaps.n[binding] = { cmd = cmd, opts = { buffer = bufnr } }
end
utils.add_keymaps(keymaps)
end,
}

View file

@ -0,0 +1,14 @@
return {
cmd = { "cmake-language-server" },
filetypes = { "cmake" },
root_markers = {
"CMakeLists.txt",
"CMakePresets.json",
"CTestConfig.cmake",
"build",
"cmake",
},
init_options = {
buildDirectory = "build",
},
}

View file

@ -0,0 +1,56 @@
local mod_cache = nil
return {
cmd = { "gopls" },
filetypes = { "go", "gomod", "gowork", "gotmpl" },
settings = {
gopls = {
["ui.inlayhints.hints"] = {
compositeLiteralFields = true,
constantValues = true,
parameterNames = true,
},
analyses = {
unusedparams = true,
},
staticcheck = true,
lintTool = "golangci-lint",
},
},
root_dir = function(callback)
local path = vim.fn.expand("%:p")
if not path or path == "" then
callback(nil)
return
end
-- Asynchronously fetch GOMODCACHE if not already set
if not mod_cache then
vim.system({ "go", "env", "GOMODCACHE" }, { text = true }, function(result)
if result and result.code == 0 and result.stdout then
mod_cache = vim.trim(result.stdout)
else
vim.notify("[gopls] Unable to fetch GOMODCACHE", vim.log.levels.WARN)
mod_cache = nil
end
end)
end
-- Check if the file is in the module cache
if mod_cache and path:sub(1, #mod_cache) == mod_cache then
local clients = vim.lsp.get_clients({ name = "gopls" })
if #clients > 0 then
callback(clients[#clients].config.root_dir)
return
end
end
-- Fallback: Find project root markers
local go_mod_root = vim.fs.find({ "go.work", "go.mod", ".git" }, { upward = true, path = path })[1]
if go_mod_root then
callback(vim.fs.dirname(go_mod_root))
else
callback(nil)
end
end,
}

View file

@ -0,0 +1,39 @@
return {
cmd = { "lua-language-server" },
filetypes = { "lua" },
root_markers = {
".luarc.json",
".luarc.jsonc",
".luacheckrc",
".stylua.toml",
"stylua.toml",
"selene.toml",
"selene.yml",
".git"
},
on_init = function(client)
local path = vim.tbl_get(client, "workspace_folders", 1, "name")
if not path then
return
end
-- override the lua-language-server settings for Neovim config
client.settings = vim.tbl_deep_extend("force", client.settings, {
Lua = {
runtime = {
version = "LuaJIT"
},
-- Make the server aware of Neovim runtime files
workspace = {
checkThirdParty = false,
library = {
vim.env.VIMRUNTIME
-- Depending on the usage, you might want to add additional paths here.
-- "${3rd}/luv/library"
-- "${3rd}/busted/library",
}
}
}
})
end
}

View file

@ -0,0 +1,21 @@
return {
cmd = { "pyright-langserver", "--stdio" },
filetypes = { "python", "py" },
root_markers = {
"pyproject.toml",
"setup.py",
"setup.cfg",
"requirements.txt",
"Pipfile",
"pyrightconfig.json",
},
settings = {
python = {
analysis = {
autoSearchPaths = true,
useLibraryCodeForTypes = true,
diagnosticMode = "openFilesOnly",
},
},
},
}

106
nvim/lua/lsp/setup.lua Normal file
View file

@ -0,0 +1,106 @@
local utils = require("utils")
local inlay_hints_handler = require("inlay_hints_handler")
local format_handler = require("format_handler")
local function chain_on_attach(...)
local funcs = { ... }
return function(client, bufnr)
for _, func in ipairs(funcs) do
func(client, bufnr)
end
end
end
local function global_on_attach(client, bufnr)
inlay_hints_handler.add_buffer(bufnr)
if client.server_capabilities.documentFormattingProvider then
vim.api.nvim_buf_create_user_command(bufnr, "Format", vim.lsp.buf.format, { nargs = 0 })
vim.api.nvim_create_autocmd("BufWritePre", {
buffer = bufnr,
callback = function()
format_handler.format()
end,
})
end
utils.add_keymaps({
n = {
["gd"] = {
cmd = function()
vim.lsp.buf.definition()
end,
opts = {
noremap = true,
silent = true,
buffer = bufnr
}
},
["gD"] = {
cmd = function()
vim.lsp.buf.declaration()
end,
opts = {
noremap = true,
silent = true,
buffer = bufnr
}
},
}
})
end
local global_capabilities = require("blink.cmp").get_lsp_capabilities()
global_capabilities.offsetEncoding = { "utf-16" }
vim.diagnostic.config({
underline = true, -- Underline diagnostic errors
virtual_text = false, -- Disable inline text messages
signs = true, -- Show icons in the sign column
update_in_insert = true, -- Update diagnostics during insert mode
})
vim.lsp.config("*", {
capabilities = global_capabilities,
handlers = {
["textDocument/publishDiagnostics"] = vim.lsp.diagnostic.on_publish_diagnostics,
},
root_markers = { ".git" },
})
-- Find all files in lua/lsp/servers and require them
-- We use them to ensure that the servers are installed and configured
local errors = {}
local dir_path = "lsp/servers"
utils.foreach(utils.get_file_names_in_dir(dir_path, "*.lua", true), function(server_name)
local server_path = dir_path .. "/" .. server_name
local result, conf = utils.xpcallmsg(
function() return require(server_path) end,
"Failed to require " .. server_path,
errors
)
if not result or type(conf) ~= "table" or vim.tbl_isempty(conf) or conf.cmd == nil then
error("Invalid configuration for " .. server_name)
return
end
conf.on_attach = (function()
if conf.on_attach then
return chain_on_attach(global_on_attach, conf.on_attach)
end
return global_on_attach
end)()
-- These still throw errors when wrapped by xpcall.
-- Wanted it to just handle incorrect input and let the runtime continue
-- as it would if the require was successful when wrapped. That would be great
-- for WIP LSP configuration, instead we have the ugly if statements above.
vim.lsp.config(server_name, conf)
vim.lsp.enable(server_name)
end)
if #errors > 0 then
error(table.concat(errors, "\n"))
end

View file

@ -0,0 +1,9 @@
local M = {}
function M.get_breadcrumbs()
local breadcrumbs = require("lspsaga.symbol.winbar").get_bar()
-- Return breadcrumbs if the string exists and is not empty, otherwise, get the filename and return it
return breadcrumbs and breadcrumbs ~= "" and breadcrumbs or vim.fn.expand("%:t")
end
return M

31
nvim/lua/plugs/arrow.lua Normal file
View file

@ -0,0 +1,31 @@
return {
"otavioschwanck/arrow.nvim",
event = "VeryLazy",
lazy = true,
opts = {
show_icons = true,
leader_key = ",",
global_bookmarks = false,
separate_by_branch = true,
custom_actions = {
open = function(filename, _)
vim.cmd(string.format(":drop %s", filename))
end,
},
mappings = {
edit = "e",
delete_mode = "d",
clear_all_items = "C",
toggle = "s",
open_vertical = "v",
open_horizontal = "h",
quit = "q",
remove = "x",
next_item = "n",
prev_item = "p",
},
window = {
border = "rounded",
}
}
}

View file

@ -0,0 +1,20 @@
return {
"rmagatti/auto-session",
opts = {
log_level = "error",
auto_session_suppress_dirs = {
"/",
"~/",
"~/Projects",
"~/Downloads",
"~/Development",
"~/Dev",
"~/Dev/Git",
"~/.config",
"~/dev/git/.dotfiles",
},
},
init = function()
vim.o.sessionoptions = "localoptions"
end
}

123
nvim/lua/plugs/ayu.lua Normal file
View file

@ -0,0 +1,123 @@
local function force_color_from_reference_on_others(others, reference)
local reference_hl = vim.api.nvim_get_hl(0, { name = reference })
for _, member in ipairs(others) do
local property = vim.api.nvim_get_hl(0, { name = member })
property.fg = reference_hl.fg
vim.api.nvim_set_hl(0, member, property)
end
end
local function reset_hl_groups_for_ft(groups_to_reset)
for _, group in ipairs(groups_to_reset) do
local ft = group[1]
local groups = group[2]
vim.api.nvim_create_autocmd("FileType", {
pattern = ft,
callback = function()
for _, group_name in ipairs(groups) do
vim.api.nvim_set_hl(0, group_name, {})
end
end,
})
end
end
return {
"Shatur/neovim-ayu",
config = function()
local is_mirage = true
local ayu = require("ayu")
local colors = require("ayu.colors")
colors.generate(is_mirage)
local overrides = {
global_variable = {
underline = true,
italic = true,
},
member_variable = {
bold = true,
},
namespace = {
italic = true,
fg = colors.markup,
},
pre_process = {
fg = colors.keyword,
},
default_type = {
fg = colors.regexp
},
type = {
fg = colors.entity,
},
}
ayu.setup({
mirage = is_mirage, -- Set to `true` to use `mirage` variant instead of `dark` for dark background.
terminal = false, -- Set to `false` to let terminal manage its own colors.
overrides = {
-- TRANSPARENCY
Normal = { bg = "none" },
NormalFloat = { bg = "none" },
ColorColumn = { bg = "none" },
SignColumn = { bg = "none" },
Folded = { bg = "none" },
FoldColumn = { bg = "none" },
CursorColumn = { bg = "none" },
VertSplit = { bg = "none" },
CursorLineNr = { bg = "none" },
-- TRANSPARENCY
["@property"] = overrides.member_variable,
["PreProc"] = overrides.pre_process,
--CPP
["@lsp.typemod.variable.fileScope.cpp"] = overrides.global_variable,
["@lsp.type.namespace.cpp"] = overrides.namespace,
["@type.builtin.cpp"] = overrides.default_type,
-- CPP
--
-- Rust
["@lsp.type.struct.rust"] = overrides.type,
["@lsp.type.namespace.rust"] = overrides.namespace,
["@lsp.type.builtinType.rust"] = overrides.default_type,
-- Rust
--
-- C
["@lsp.typemod.variable.globalScope.c"] = overrides.global_variable,
["@type.builtin.c"] = overrides.default_type,
-- C
--
-- Go
-- ["@module.go"] = overrides.namespace, -- The go LSP is not reliable enough for this sadly, sometimes it adds module tokens and sometimes it doesnt.
["@variable.member.go"] = overrides.member_variable,
["@type.builtin.go"] = overrides.default_type,
-- Go
--
-- Zig
["@module.zig"] = overrides.namespace,
["@type.builtin.zig"] = overrides.default_type,
["@function.builtin.zig"] = overrides.default_type,
-- ["@variable.member.zig"] = overrides.member_variable,-- Cant have bold member variable in zig, they don't differentiate function calls/accessors from variables, they are all just "members" .... BS LSP
-- ["@variable.parameter"] = {},-- Zig LSP is lacking, a parameter is marked as a regular variable outside of it's definition, can't separate between them.
-- Zig
},
})
ayu.colorscheme()
-- Fix nuances of the colorscheme in different languages.
-- These changes needs to run after the colorscheme is set.
force_color_from_reference_on_others({
"@property",
"@variable.member.go",
"@variable.member",
"@variable.member.zig",
}, "@variable")
reset_hl_groups_for_ft({
{ "go", { "@property", } },
})
end
}

18
nvim/lua/plugs/blink.lua Normal file
View file

@ -0,0 +1,18 @@
return {
"saghen/blink.cmp",
lazy = false,
version = "v0.*",
---@module "blink.cmp"
---@type blink.cmp.Config
opts = {
keymap = { preset = "super-tab" },
-- highlight = {
-- use_nvim_cmp_as_default = true,
-- },
-- nerd_font_variant = "mono",
},
-- allows extending the enabled_providers array elsewhere in your config
-- without having to redefining it
opts_extend = { "sources.completion.enabled_providers" }
}

View file

@ -0,0 +1,56 @@
return {
"olimorris/codecompanion.nvim",
dependencies = {
"nvim-lua/plenary.nvim",
"nvim-treesitter/nvim-treesitter",
-- "hrsh7th/nvim-cmp",
{ 'echasnovski/mini.diff', version = false },
{ "stevearc/dressing.nvim", opts = {} },
},
config = function()
require("codecompanion").setup({
strategies = {
chat = {
adapter = "copilot",
},
inline = {
adapter = "copilot",
},
agent = {
adapter = "copilot",
},
},
adapters = {
copilot = function() return require("codecompanion.adapters").extend("copilot", {}) end,
},
display = {
diff = {
provider = "mini_diff",
},
},
opts = {
log_level = "DEBUG",
},
})
local keymaps = {
n = {
["<Leader>ci"] = { cmd = "<cmd>CodeCompanion<cr>" },
["<Leader>cc"] = { cmd = "<cmd>CodeCompanionChat toggle<cr>" },
["<Leader>cm"] = { cmd = "<cmd>CodeCompanion /commit<cr>" },
},
v = {
["<Leader>ci"] = { cmd = "<cmd>CodeCompanion<cr>" },
["ga"] = { cmd = "<cmd>CodeCompanionAdd<cr>" },
["<Leader>ce"] = { cmd = "<cmd>CodeCompanion /explain<cr>" },
["<Leader>cf"] = { cmd = "<cmd>CodeCompanion /fix<cr>" },
["<Leader>ct"] = { cmd = "<cmd>CodeCompanion /tests<cr>" },
}
}
local utils = require("utils")
utils.add_opts_to_all_mappings(keymaps, { silent = true })
utils.add_keymaps(keymaps)
vim.cmd([[cab cc CodeCompanion]])
end
}

View file

@ -0,0 +1,26 @@
return {
"mistricky/codesnap.nvim",
build = "make",
event = "VeryLazy",
lazy = true,
config = function()
require("codesnap").setup({
mac_window_bar = true,
title = "codesnap.nvim",
code_font_family = "JetBrainsMono Nerd Font",
breadcrumbs_separator = "/",
has_breadcrumbs = true,
bg_theme = "grape",
watermark = "",
})
require("utils").add_keymaps({
v = {
["<leader>cs"] = {
cmd = ":CodeSnap<CR>",
opts = { silent = true },
},
}
})
end,
}

View file

@ -0,0 +1,17 @@
return {
"norcalli/nvim-colorizer.lua",
event = "VeryLazy",
lazy = true,
opts = {
DEFAULT_OPTIONS = {
RGB = true,
RRGGBB = true,
names = false,
RRGGBBAA = true,
css = true,
css_fn = true,
mode = "background",
},
"*",
}
}

View file

@ -0,0 +1,18 @@
return {
"github/copilot.vim",
config = function()
vim.g.copilot_no_tab_map = true
require("utils").add_keymaps({
i = {
["<Right>"] = {
cmd = 'copilot#Accept("\\<Right>")',
opts = {
expr = true,
replace_keycodes = false,
silent = true,
}
}
}
})
end
}

View file

@ -0,0 +1,5 @@
return {
"nvim-tree/nvim-web-devicons",
event = "VeryLazy",
lazy = true,
}

71
nvim/lua/plugs/fzf.lua Normal file
View file

@ -0,0 +1,71 @@
return {
"ibhagwan/fzf-lua",
dependencies = { "nvim-tree/nvim-web-devicons" },
opts = {
"telescope",
winopts = {
preview = {
default = "bat"
}
},
lsp = {
workspace_symbols = {
symbol_kinds = { "Variable", "Function", "Method", "Class", "Struct", "Interface" },
},
},
previewers = {
builtin = {
-- turn off syntax highlighting for files with more than 100KB
-- this avoid hanging when previewing large files (due to treesitter parsing on minified files)
syntax_limit_b = 1024 * 100, -- 100KB
}
}
},
config = function()
local fzf = require("fzf-lua")
local pickers = {
{
mapping = "o",
action = function()
fzf.files({
git_icons = false,
})
end
},
{
mapping = "a",
action = function()
fzf.live_grep_native({
git_icons = false,
rg_opts = "--hidden --column --line-number --no-heading --color=always --smart-case",
fzf_opts = {
['--exact'] = false, -- Disable exact matching
},
})
end
},
{
mapping = "g",
action = function()
fzf.git_bcommits({})
end
},
{
mapping = "s",
action = function()
fzf.lsp_live_workspace_symbols({})
end
}
}
local keymaps = {}
keymaps.n = {}
for _, picker in ipairs(pickers) do
keymaps.n["<leader>t" .. picker.mapping] = {
cmd = picker.action
}
end
require("utils").add_keymaps(keymaps)
end
}

101
nvim/lua/plugs/incline.lua Normal file
View file

@ -0,0 +1,101 @@
return {
"b0o/incline.nvim",
dependencies = {
"lewis6991/gitsigns.nvim"
},
event = "VeryLazy",
lazy = true,
config = function()
local gitsigns = require("gitsigns")
gitsigns.setup({})
local devicons = require("nvim-web-devicons")
require("incline").setup({
window = {
padding = 0,
},
hide = {
cursorline = true,
},
render = function(props)
local filename = vim.fn.fnamemodify(vim.api.nvim_buf_get_name(props.buf), ":t")
if filename == "" then
filename = "[No Name]"
end
local ft_icon, ft_color = devicons.get_icon_color(filename)
local function get_git_diff()
local icons = { removed = "", changed = "", added = "" }
local signs = vim.b[props.buf].gitsigns_status_dict
local labels = {}
if signs == nil then
return labels
end
for name, icon in pairs(icons) do
if tonumber(signs[name]) and signs[name] > 0 then
table.insert(labels, { icon .. " " .. signs[name] .. " ", group = "Diff" .. name })
end
end
if #labels > 0 then
table.insert(labels, { "" })
end
return labels
end
local function get_diagnostic_label()
local icons = { error = "", warn = "", info = "", hint = "" }
local label = {}
for severity, icon in pairs(icons) do
local n = #vim.diagnostic.get(props.buf,
{ severity = vim.diagnostic.severity[string.upper(severity)] })
if n > 0 then
table.insert(label, { icon .. " " .. n .. " ", group = "DiagnosticSign" .. severity })
end
end
if #label > 0 then
table.insert(label, { "" })
end
return label
end
local function get_arrow_label()
local statusline = require("arrow.statusline")
if statusline.is_on_arrow_file(props.buf) == nil then
return ""
end
return " " .. statusline.text_for_statusline_with_icons(props.buf)
end
return {
guibg = "#1e2030",
guifg = "#cad3f5",
{ " " },
{ get_diagnostic_label() },
{ get_git_diff() },
{ (ft_icon or "") .. " ", guifg = ft_color, guibg = "none" },
{ filename .. "", gui = vim.bo[props.buf].modified and "bold,italic" or "bold" },
{ get_arrow_label() .. "" .. vim.api.nvim_win_get_number(props.win), group = "DevIconWindows" },
{ " " }
}
end,
require("utils").add_keymaps({
n = {
["<leader>gh"] = {
cmd = gitsigns.preview_hunk
},
["<leader>gb"] = {
cmd = gitsigns.toggle_current_line_blame
},
["[g"] = {
cmd = function() gitsigns.nav_hunk("prev") end
},
["]g"] = {
cmd = function() gitsigns.nav_hunk("next") end
}
}
})
})
end,
}

View file

@ -0,0 +1,11 @@
return {
"lukas-reineke/indent-blankline.nvim",
main = "ibl",
event = "BufRead",
opts = {
debounce = 100,
scope = {
enabled = false
},
}
}

94
nvim/lua/plugs/leap.lua Normal file
View file

@ -0,0 +1,94 @@
local saved_hlsearch = false
local saved_highlights = {}
local colors = require("ayu.colors")
colors.generate(true)
local function save_and_set_invisible_inlay_hints_hl()
saved_highlights = vim.api.nvim_get_hl(0, { name = "LspInlayHint" })
vim.api.nvim_set_hl(0, "LspInlayHint", { fg = colors.bg, bg = "none" })
end
local function restore_inlay_hints_hl()
vim.api.nvim_set_hl(0, "LspInlayHint", saved_highlights)
end
return {
"ggandor/leap.nvim",
dependencies = {
{ "tpope/vim-repeat", lazy = true },
},
event = "VeryLazy",
lazy = true,
config = function()
local leap = require("leap")
-- Disable auto jumping to the first match
-- Autojumping is not intuitive when running bi-directional leaps
leap.opts.safe_labels = {}
-- Adding more labels since we're not using autojumping. These are sorted by priority
-- focusing on the home row and the strongest fingers for Colemak-DH
leap.opts.labels = "tsragneiomdch,pfluxzv./kwqby;j1234567890{}()[]<>J!@#$%^&*TSRAGNEIOMDCHPFLUXZV?KWQBY:"
local autocmds = {
{
event_name = "LeapEnter",
cb = function()
saved_hlsearch = vim.o.hlsearch
vim.o.hlsearch = false
save_and_set_invisible_inlay_hints_hl()
end
},
{
event_name = "LeapLeave",
cb = function()
vim.o.hlsearch = saved_hlsearch
restore_inlay_hints_hl()
end
},
}
local utils = require("utils")
local leap_augroup_name = "LeapEvents"
vim.api.nvim_create_augroup(leap_augroup_name, { clear = true })
for _, cmd in ipairs(autocmds) do
utils.create_user_event_cb(cmd.event_name, cmd.cb, leap_augroup_name)
end
local leap_user = require("leap.user")
local function leap_across_windows()
leap.leap({
target_windows = leap_user.get_focusable_windows()
})
end
local function leap_in_current_buffer()
leap.leap({
target_windows = { vim.api.nvim_get_current_win() }
})
end
utils.add_keymaps({
n = {
["m"] = {
cmd = function()
leap_across_windows()
end,
},
},
v = {
["m"] = {
cmd = function()
leap_in_current_buffer()
end,
}
},
o = {
["m"] = {
cmd = function()
leap_in_current_buffer()
end,
}
}
})
end,
}

View file

@ -0,0 +1,65 @@
return {
-- "nvimdev/lspsaga.nvim",
"LarssonMartin1998/lspsaga.nvim", -- Use my own fork until PR's are merged
event = "LspAttach",
lazy = true,
-- dir = "~/dev/git/lspsaga.nvim",
dependencies = {
"nvim-tree/nvim-web-devicons",
},
after = "nvim-lspconfig",
config = function()
require("lspsaga").setup({
request_timeout = 750,
symbol_in_winbar = {
enable = false,
},
implement = {
enable = false,
},
outline = {
enable = false,
win_width = 52,
},
ui = {
border = "rounded",
title = false,
},
code_action = {
extend_gitsigns = true
},
hover = {
jump_on_first_press = true
},
})
local keymaps = {
n = {
["K"] = {
cmd = ":Lspsaga hover_doc<CR>"
},
["<leader>rn"] = {
cmd = ":Lspsaga rename<CR>"
},
["gr"] = {
cmd = ":Lspsaga finder<CR>"
},
["<leader>lt"] = {
cmd = ":Lspsaga peek_type_definition<CR>"
},
["<leader>ld"] = {
cmd = ":Lspsaga peek_definition<CR>"
},
["<leader>ca"] = {
cmd = ":Lspsaga code_action<CR>"
},
["<leader>lc"] = {
cmd = ":Lspsaga incoming_calls<CR>"
},
}
}
local utils = require("utils")
utils.add_opts_to_all_mappings(keymaps, { silent = true })
utils.add_keymaps(keymaps)
end,
}

View file

@ -0,0 +1,51 @@
local wm = require("window_management")
local function resize_mode()
if wm.is_in_resizing_mode() then
return "▲ Resizing ▼"
else
return ""
end
end
return {
"nvim-lualine/lualine.nvim",
dependencies = {
"nvim-tree/nvim-web-devicons"
},
event = "VeryLazy",
lazy = true,
config = function()
require("lualine").setup {
options = {
theme = "ayu",
section_separators = {
left = "",
right = "",
},
component_separators = {
left = "",
right = ""
},
icons_enabled = true,
},
sections = {
lualine_a = { "mode" },
lualine_b = { "branch", resize_mode },
lualine_c = { "buffers" },
lualine_x = { "encoding", "fileformat", "filetype" },
lualine_y = { "progress" },
lualine_z = { "location" }
},
inactive_sections = {
lualine_a = {},
lualine_b = {},
lualine_c = {},
lualine_x = {},
lualine_y = {},
lualine_z = {}
},
tabline = {},
}
end
}

36
nvim/lua/plugs/mason.lua Normal file
View file

@ -0,0 +1,36 @@
return {
"williamboman/mason.nvim",
dependencies = { "WhoIsSethDaniel/mason-tool-installer.nvim" },
config = function()
require("mason").setup({})
require("mason-tool-installer").setup({
ensure_installed = {
-- LLVM debugger
"codelldb",
-- C and C++
"clangd",
"clang-format",
-- Rust
"rust-analyzer",
-- Go
"gopls",
"golangci-lint",
"delve",
-- Lua
"lua-language-server",
-- CMake
"cmake-language-server",
"cmakelang",
-- Python
"debugpy",
"pyright",
},
})
end
}

11
nvim/lua/plugs/neogit.lua Normal file
View file

@ -0,0 +1,11 @@
return {
"NeogitOrg/neogit",
dependencies = {
"sindrets/diffview.nvim",
},
event = "VeryLazy",
lazy = true,
config = function()
require("neogit").setup()
end
}

18
nvim/lua/plugs/neorg.lua Normal file
View file

@ -0,0 +1,18 @@
return {
"nvim-neorg/neorg",
opts = {
load = {
["core.defaults"] = {},
["core.dirman"] = {
config = {
workspaces = {
my_workspace = "~/.neorg",
},
},
},
["core.concealer"] = {},
},
},
event = "VeryLazy",
lazy = true,
}

37
nvim/lua/plugs/noice.lua Normal file
View file

@ -0,0 +1,37 @@
return {
"folke/noice.nvim",
event = "VeryLazy",
lazy = true,
dependencies = {
{ "MunifTanjim/nui.nvim", lazy = true },
{
"rcarriga/nvim-notify",
opts = {
background_colour = "#24273a",
fps = 1,
render = "compact",
stages = "static"
}
}
},
opts = {
lsp = {
-- override markdown rendering so that **cmp** and other plugins use **Treesitter**
override = {
["vim.lsp.util.convert_input_to_markdown_lines"] = true,
["vim.lsp.util.stylize_markdown"] = true,
-- ["cmp.entry.get_documentation"] = true, -- requires hrsh7th/nvim-cmp
},
},
presets = {
bottom_search = true, -- use a classic bottom cmdline for search
command_palette = false, -- position the cmdline and popupmenu together
long_message_to_split = true, -- long messages will be sent to a split
inc_rename = false, -- enables an input dialog for inc-rename.nvim
lsp_doc_border = false, -- add a border to hover docs and signature help
},
notify = {
level = "warn"
}
}
}

152
nvim/lua/plugs/nvim-dap.lua Normal file
View file

@ -0,0 +1,152 @@
local utils = require("utils")
local inlay_hints_handler = require("inlay_hints_handler")
local are_stepping_keymaps_active = false
return {
"mfussenegger/nvim-dap",
dependencies = {
"rcarriga/nvim-dap-ui",
-- Special adapters
"leoluz/nvim-dap-go",
"mfussenegger/nvim-dap-python",
{ "nvim-neotest/nvim-nio", lazy = true },
"LiadOz/nvim-dap-repl-highlights",
"theHamsta/nvim-dap-virtual-text",
"Weissle/persistent-breakpoints.nvim",
},
config = function()
local dap = require("dap")
local dapui = require("dapui")
-- Special adapters
require("dap-go").setup()
require("dap-python").setup("python3")
-- Special adapters
require("dap.ext.vscode").load_launchjs()
require("persistent-breakpoints").setup {
load_breakpoints_event = { "BufReadPost" }
}
require("nvim-dap-repl-highlights").setup()
require("nvim-dap-virtual-text").setup()
local virtual_text = require("nvim-dap-virtual-text/virtual_text")
local breakpoint_api = require("persistent-breakpoints.api")
dapui.setup({
controls = {
enabled = false,
},
layouts = {
{
elements = {
{
id = "watches",
size = 0.5
},
{
id = "stacks",
size = 0.5
}
},
position = "bottom",
size = 15
}
},
})
local stepping_keymaps = {
n = {
["m"] = {
cmd = function()
dap.step_out()
end
},
["n"] = {
cmd = function()
dap.step_over()
end
},
["i"] = {
cmd = function()
dap.step_into()
end
},
}
}
local function enter_debug_mode()
dapui.open()
if not are_stepping_keymaps_active then
utils.add_temporary_keymaps(stepping_keymaps)
are_stepping_keymaps_active = true
end
inlay_hints_handler.disable()
end
local function exit_debug_mode()
dapui.close()
if are_stepping_keymaps_active then
utils.remove_keymaps(stepping_keymaps)
are_stepping_keymaps_active = false
end
inlay_hints_handler.restore()
virtual_text.clear_virtual_text()
end
local dap_signs = {
{ "DapBreakpoint", { text = "🛑", texthl = "", linehl = "", numhl = "" } },
{ "DapBreakpointRejected", { text = "🔵", texthl = "", linehl = "", numhl = "" } },
{ "DapBreakpointCondition", { text = "🟥", texthl = "", linehl = "", numhl = "" } },
}
for _, sign in ipairs(dap_signs) do
vim.fn.sign_define(unpack(sign))
end
dap.listeners.after.event_initialized["dapui_config"] = function()
enter_debug_mode()
end
dap.listeners.before.event_terminated["dapui_config"] = function()
exit_debug_mode()
end
dap.listeners.before.event_exited["dapui_config"] = function()
exit_debug_mode()
end
utils.add_keymaps({
n = {
["<leader>dr"] = {
cmd = function()
dap.continue()
end
},
["<leader>bt"] = {
cmd = function()
breakpoint_api.toggle_breakpoint()
end
},
["<leader>bc"] = {
cmd = function()
breakpoint_api.set_conditional_breakpoint()
end
},
["<leader>br"] = { -- breakpoint remove
cmd = function()
breakpoint_api.clear_all_breakpoints()
end
},
["<leader>ds"] = {
cmd = function()
dap.disconnect({ terminateDebuggee = true })
dap.close()
exit_debug_mode()
end
},
}
})
end,
}

View file

@ -0,0 +1,4 @@
return {
"nvim-lua/plenary.nvim",
lazy = true,
}

View file

@ -0,0 +1,61 @@
local utils = require("utils")
local inlay_hints_handler = require("inlay_hints_handler")
local format_handler = require("format_handler")
return {
"mrcjkb/rustaceanvim",
version = "^5",
ft = { "rust" },
config = function()
vim.g.rustaceanvim = {
inlay_hints = {
highlight = "NonText",
},
tools = {
hover_actions = {
auto_focus = true,
},
},
server = {
on_attach = function(client, bufnr)
inlay_hints_handler.add_buffer(bufnr)
if client.server_capabilities.documentFormattingProvider then
vim.api.nvim_buf_create_user_command(bufnr, "Format", vim.lsp.buf.format, { nargs = 0 })
vim.api.nvim_create_autocmd("BufWritePre", {
buffer = bufnr,
callback = function()
format_handler.format()
end,
})
end
utils.add_keymaps({
n = {
["gd"] = {
cmd = function()
vim.lsp.buf.definition()
end,
opts = {
noremap = true,
silent = true,
buffer = bufnr,
}
},
["gD"] = {
cmd = function()
vim.lsp.buf.declaration()
end,
opts = {
noremap = true,
silent = true,
buffer = bufnr,
}
},
}
})
end,
}
}
end,
}

View file

@ -0,0 +1,15 @@
return {
"kylechui/nvim-surround",
version = "*",
event = "VeryLazy",
lazy = true,
opts = {
-- Make sure that we never get whitespaces when adding surroundings
surrounds = {
["("] = { add = { "(", ")" }, },
["{"] = { add = { "{", "}" }, },
["<"] = { add = { "<", ">" }, },
["["] = { add = { "[", "]" }, },
}
}
}

View file

@ -0,0 +1,19 @@
return {
"rachartier/tiny-inline-diagnostic.nvim",
event = "VeryLazy",
priority = 1000,
config = function()
require("tiny-inline-diagnostic").setup()
vim.diagnostic.config({
virtual_text = false,
})
vim.cmd [[
highlight DiagnosticUnderlineError gui=undercurl guisp=#ff0000 " Red for error
highlight DiagnosticUnderlineWarn gui=undercurl guisp=#ffaa00 " Yellow/Orange for warning
highlight DiagnosticUnderlineHint gui=undercurl guisp=#00ffff " Cyan for hint
highlight DiagnosticUnderlineInfo gui=undercurl guisp=#0000ff " Blue for info
]]
end
}

View file

@ -0,0 +1,85 @@
return {
"nvim-treesitter/nvim-treesitter",
event = { "BufReadPre", "BufNewFile" },
build = ":TSUpdate",
dependencies = {
{
"nvim-treesitter/nvim-treesitter-context",
opts = {
max_lines = 2, -- How many lines the window should span. Values <= 0 mean no limit.
multiline_threshold = 3, -- Maximum number of lines to show for a single context
trim_scope = "inner", -- Which context lines to discard if `max_lines` is exceeded. Choices: 'inner', 'outer'
}
},
"nvim-treesitter/nvim-treesitter-textobjects",
},
config = function()
require("nvim-treesitter.configs").setup({
ensure_installed = {
"vim",
"vimdoc",
"bash",
"lua",
"c",
"cpp",
"c_sharp",
"rust",
"cmake",
"make",
"yaml",
"ninja",
"gitignore",
"markdown",
"markdown_inline",
"hyprlang",
"json",
"html",
"hlsl",
"glsl",
"gdshader",
"gdscript",
"dockerfile",
"dart",
"go",
"zig",
"css",
"regex",
"dap_repl",
"muttrc",
"python",
},
sync_install = false,
-- This can be updated to a list of languages instead of defaulting to true
highlight = {
enable = true,
additional_vim_regex_highlighting = false,
},
indent = { enable = true },
incremental_selection = {
enable = true,
keymaps = {
init_selection = "<C-cr>",
node_incremental = "<C-cr>",
scope_incremental = false,
node_decremental = "<C-bs>",
},
},
textobjects = {
select = {
enable = true,
lookahead = true,
keymaps = {
["ic"] = { query = "@class.inner" },
["ac"] = { query = "@class.outer" },
["ii"] = { query = "@conditional.inner" },
["ai"] = { query = "@conditional.outer" },
["if"] = { query = "@function.inner" },
["af"] = { query = "@function.outer" },
["il"] = { query = "@loop.inner" },
["al"] = { query = "@loop.outer" },
},
},
},
})
end
}

49
nvim/lua/terminal.lua Normal file
View file

@ -0,0 +1,49 @@
local utils = require("utils")
local wm = require("window_management")
local terminal_window = nil
local terminal_bufnr = nil
local function open_terminal_window()
if terminal_bufnr and vim.api.nvim_buf_is_valid(terminal_bufnr) and utils.is_buf_buftype(terminal_bufnr, "terminal") then
vim.cmd("botright split")
terminal_window = vim.api.nvim_get_current_win()
vim.api.nvim_win_set_buf(terminal_window, terminal_bufnr)
else
vim.cmd("botright split term://zsh")
terminal_window = vim.api.nvim_get_current_win()
terminal_bufnr = vim.api.nvim_get_current_buf()
end
end
local function toggle_terminal()
if terminal_window and vim.api.nvim_win_is_valid(terminal_window) then
vim.api.nvim_win_close(terminal_window, true)
terminal_window = nil
return
end
open_terminal_window()
local term_height = vim.api.nvim_get_option("lines")
local height_percentage = 0.225
local min_height = 15
local max_height = 25
local height = utils.calculate_split_size(term_height, height_percentage, min_height, max_height)
vim.api.nvim_win_set_height(terminal_window, height)
vim.api.nvim_win_set_option(terminal_window, "winfixheight", true)
utils.lock_buf_to_window(terminal_window, terminal_bufnr, "terminal")
vim.api.nvim_command("startinsert")
end
utils.add_keymaps({
n = {
["<leader>h"] = {
cmd = function()
toggle_terminal()
wm.autosize_windows()
end,
}
}
})

205
nvim/lua/utils.lua Normal file
View file

@ -0,0 +1,205 @@
local M = {}
local overridden_default_keymaps = {}
local function is_single_keymap_table(map_table)
assert(map_table)
return map_table.n or map_table.t or map_table.i or map_table.v or map_table.x or map_table.o
end
function M.get_file_names_in_dir(dir, expr, strip_extension)
local path = vim.fn.stdpath("config") .. "/lua/" .. dir
local files_str = vim.fn.globpath(path, expr, true)
local has_line_breaks = vim.fn.match(files_str, [[\n]]) > -1
local files = has_line_breaks and vim.fn.split(files_str, "\n") or { files_str }
local should_strip_extension = strip_extension or false
if should_strip_extension then
return vim.tbl_map(function(file)
return vim.fn.fnamemodify(file, ":t:r")
end, files)
else
return files
end
end
function M.validate_bufnr(bufnr)
vim.validate('bufnr', bufnr, 'number')
return bufnr == 0 and vim.api.nvim_get_current_buf() or bufnr
end
function M.xpcallmsg(fn, err_msg, err_container)
return xpcall(fn, function(err)
if err_container then
table.insert(err_container, err_msg .. ": " .. err)
else
error(err_msg .. ": " .. err)
end
end)
end
function M.foreach(t, f)
for _, v in pairs(t) do
f(v)
end
end
function M.create_user_event_cb(event_name, function_callback, augroup)
assert(event_name and event_name ~= "", "Event name must be provided")
assert(function_callback and type(function_callback) == "function", "Callback must be a valid function")
local cmd = {
callback = function_callback,
pattern = event_name,
}
if augroup then
cmd.group = augroup
end
vim.api.nvim_create_autocmd("User", cmd)
end
function M.broadcast_event(event_name)
vim.api.nvim_command("doautocmd <nomodeline> User " .. event_name)
end
function M.add_opts_to_all_mappings(mappings, opts)
assert(opts and mappings)
for _, modes in pairs(mappings) do
for _, mapping in pairs(modes) do
local existing_opts = mapping.opts or {}
mapping.opts = vim.tbl_extend("force", existing_opts, opts)
end
end
end
local function pass_keymap_tbl_to_fn(maps, fn)
if is_single_keymap_table(maps) then
fn(maps)
else
for _, map_table in pairs(maps) do
fn(map_table)
end
end
end
local function get_keymaps(mode, buffer)
if buffer then
return vim.api.nvim_buf_get_keymap(buffer, mode)
end
return vim.api.nvim_get_keymap(mode)
end
function M.add_temporary_keymaps(maps)
assert(maps)
pass_keymap_tbl_to_fn(maps, function(map_table)
for mode, entries in pairs(map_table) do
-- We make an assumptino here which is that all the entries are buffers, or not buffers.
-- Meaning, we only check the first entry and trust that the rest are the same.
local result = get_keymaps(mode, (function()
for _, entry in pairs(entries) do
-- nil buffer is treated as a global keymap
return entry.buffer
end
end)())
for code, _ in pairs(entries) do
for _, map in ipairs(result) do
if map.lhs == code then
if not overridden_default_keymaps[mode] then
overridden_default_keymaps[mode] = {}
end
overridden_default_keymaps[mode][code] = {
cmd = map.callback or map.rhs,
opts = {
noremap = map.noremap == 1,
expr = map.expr == 1,
silent = map.silent == 1,
nowait = map.nowait == 1,
script = map.script == 1,
buffer = type(map.buffer) == "number" and map.buffer or nil,
},
}
end
end
end
end
end)
M.add_keymaps(maps)
end
function M.add_keymaps(maps)
assert(maps)
pass_keymap_tbl_to_fn(maps, function(map_table)
for mode, entries in pairs(map_table) do
for code, info in pairs(entries) do
vim.keymap.set(mode, code, info.cmd, info.opts)
end
end
end)
end
function M.remove_keymaps(maps)
assert(maps)
pass_keymap_tbl_to_fn(maps, function(map_table)
for mode, entries in pairs(map_table) do
local overriden_mode = overridden_default_keymaps[mode]
for code, _ in pairs(entries) do
vim.keymap.del(mode, code)
if overriden_mode and overriden_mode[code] then
vim.keymap.set(mode, code, overriden_mode[code].cmd, overriden_mode[code].opts)
end
end
end
end)
end
function M.is_buf_filetype(bufnr, filetype)
return vim.api.nvim_buf_get_option(bufnr, "filetype") == filetype
end
function M.is_buf_buftype(bufnr, filetype)
return vim.api.nvim_buf_get_option(bufnr, "buftype") == filetype
end
function M.lock_buf_to_window(win_id, bufnr, filetype)
local augroup_id = vim.api.nvim_create_augroup("LockWindow" .. win_id, { clear = true })
vim.api.nvim_create_autocmd("BufEnter", {
group = augroup_id,
callback = function()
local current_win = vim.api.nvim_get_current_win()
if current_win ~= win_id then
return
end
local current_buf = vim.api.nvim_win_get_buf(win_id)
if current_buf == bufnr then
return
end
if M.is_buf_filetype(current_buf, filetype) then
bufnr = current_buf
return
end
vim.api.nvim_win_set_buf(win_id, bufnr)
end,
})
end
function M.calculate_split_size(term_size, percentage, min_size, max_size)
local calculated_size = math.floor(term_size * percentage)
return math.min(math.max(calculated_size, min_size), max_size)
end
return M

73
nvim/lua/vim_opt.lua Normal file
View file

@ -0,0 +1,73 @@
local opt = vim.opt
-- Disable tabs, will use telescope and harpoon instead
opt.showtabline = 0
-- Make Vim use the system clipboard
opt.clipboard = "unnamedplus"
-- Highlight the currently selected row
opt.cursorline = true
opt.cursorlineopt = "both"
-- Indenting
opt.expandtab = true
opt.smartindent = true
opt.breakindent = true
opt.shiftwidth = 4
opt.tabstop = 4
opt.softtabstop = 4
-- Disable home screen
opt.shortmess:append("sI")
-- Signcolumn
opt.signcolumn = "yes:2" -- Adds a spacing to the left which can contain gutter icons
opt.fillchars = { eob = " " } -- Remove the fill character for empty lines which defaults to: "~"
-- Search
opt.ignorecase = true
opt.smartcase = true
opt.incsearch = true
-- Command
opt.inccommand = "nosplit"
-- Disable mouse support
opt.mouse = ""
-- Numbers
opt.number = true
opt.relativenumber = true
opt.numberwidth = 4
-- Decrease update time
opt.updatetime = 250
opt.timeoutlen = 300
-- Disable swapfile, 99/100 times it just gets in the way
opt.swapfile = false
-- Buffers
opt.splitright = true
opt.splitbelow = true
-- Removes the extra command line bar at the bottom, using lualine instead
opt.cmdheight = 0
-- Statusline
opt.laststatus = 3
-- Terminal integration
opt.termguicolors = true
opt.termsync = true
-- Sets a minimum number of lines to keep above and below the cursor
opt.scrolloff = 4
-- Whitespaces
-- opt.listchars = { tab = "→\"", trail = "·", nbsp = "␣" }
-- opt.list = true
opt.list = false
return opt

View file

@ -0,0 +1,269 @@
local utils = require("utils")
local M = {}
local is_in_resizing_mode = false
local on_resize_mode_enter_event = "ResizeModeEnter"
local on_resize_mode_exit_event = "ResizeModeExit"
local function is_floating_window(window)
assert(window, "Invalid window")
return vim.api.nvim_win_get_config(window).relative ~= ""
end
local function window_has_valid_buffer(window)
assert(window, "Invalid window")
local buf = vim.api.nvim_win_get_buf(window)
if not buf then
return false
end
-- An empty bufname is alright, for instance if we have a new empty buffer
local buf_name = vim.api.nvim_buf_get_name(buf)
if not buf_name then
return false
end
local buf_type = vim.api.nvim_buf_get_option(buf, "buftype")
if buf_type ~= "" then
return false
end
return true
end
local function get_total_num_windows_open()
return #vim.api.nvim_tabpage_list_wins(0)
end
local function get_adjacent_window(dir_char)
assert(dir_char == "h" or dir_char == "j" or dir_char == "k" or dir_char == "l", "Invalid direction character")
local current_window = vim.api.nvim_get_current_win()
if not current_window then
return
end
vim.cmd("wincmd " .. dir_char)
local new_window = vim.api.nvim_get_current_win()
vim.api.nvim_set_current_win(current_window)
assert(vim.api.nvim_get_current_win() == current_window, "Cursor moved to a different window")
return new_window
end
local function is_current_window_at_edge(dir_char)
return vim.api.nvim_get_current_win() == get_adjacent_window(dir_char)
end
local function swap_buffer_between_windows(window_a, window_b)
assert(window_a and window_b, "Invalid window")
local buffer_a = vim.api.nvim_win_get_buf(window_a)
local buffer_b = vim.api.nvim_win_get_buf(window_b)
vim.api.nvim_win_set_buf(window_a, buffer_b)
vim.api.nvim_win_set_buf(window_b, buffer_a)
assert(vim.api.nvim_win_get_buf(window_a) == buffer_b and vim.api.nvim_win_get_buf(window_b) == buffer_a,
"Failed to swap buffers")
end
local function swap_window(dir_char)
assert(dir_char == "h" or dir_char == "j" or dir_char == "k" or dir_char == "l", "Invalid direction character")
local function can_swap_window(window)
if not window then
return true
end
if is_floating_window(window) then
return true
end
if not window_has_valid_buffer(window) then
return true
end
return false
end
local required_num_windows = 2
if get_total_num_windows_open() < required_num_windows then
return
end
local current_window = vim.api.nvim_get_current_win()
if can_swap_window(current_window) then
return
end
if is_current_window_at_edge(dir_char) then
return
end
local adjacent_window = get_adjacent_window(dir_char)
if can_swap_window(adjacent_window) then
return
end
swap_buffer_between_windows(current_window, adjacent_window)
vim.api.nvim_set_current_win(adjacent_window)
assert(vim.api.nvim_get_current_win() == adjacent_window, "Failed to swap windows")
end
local function resize_window(window, dir_char)
assert(is_in_resizing_mode, "Not in resizing mode")
assert(window, "Invalid window")
assert(dir_char == "h" or dir_char == "j" or dir_char == "k" or dir_char == "l", "Invalid direction character")
local function can_resize_window(win)
if not win then
return true
end
if is_floating_window(win) then
return true
end
return false
end
if can_resize_window(window) then
return
end
local resize_units_vertical = 5
local resize_units_horizontal = 3
if dir_char == "h" then
vim.cmd("vertical resize -" .. resize_units_vertical * vim.v.count1)
elseif dir_char == "j" then
vim.cmd("resize -" .. resize_units_horizontal * vim.v.count1)
elseif dir_char == "k" then
vim.cmd("resize +" .. resize_units_horizontal * vim.v.count1)
elseif dir_char == "l" then
vim.cmd("vertical resize +" .. resize_units_vertical * vim.v.count1)
end
end
local function exit_resizing_mode()
assert(is_in_resizing_mode, "Not in resizing mode")
is_in_resizing_mode = false
utils.broadcast_event(on_resize_mode_exit_event)
assert(not is_in_resizing_mode, "Failed to exit resizing mode")
end
local function enter_resizing_mode()
assert(not is_in_resizing_mode, "Already in resizing mode")
local current_window = vim.api.nvim_get_current_win()
if not current_window then
return
end
if is_floating_window(current_window) then
return
end
if not window_has_valid_buffer(current_window) then
return
end
is_in_resizing_mode = true
utils.broadcast_event(on_resize_mode_enter_event)
assert(is_in_resizing_mode, "Failed to enter resizing mode")
end
function M.autosize_windows()
vim.api.nvim_command("wincmd =")
end
function M.is_in_resizing_mode()
return is_in_resizing_mode
end
function M.setup()
local resizing_mode_keymaps = {
n = {
["<Left>"] = {
cmd = function() resize_window(vim.api.nvim_get_current_win(), "h") end
},
["<Down>"] = {
cmd = function() resize_window(vim.api.nvim_get_current_win(), "j") end
},
["<Up>"] = {
cmd = function() resize_window(vim.api.nvim_get_current_win(), "k") end
},
["<Right>"] = {
cmd = function() resize_window(vim.api.nvim_get_current_win(), "l") end
},
["<Esc>"] = {
cmd = function() exit_resizing_mode() end
},
["<Enter>"] = {
cmd = function() exit_resizing_mode() end
},
["="] = {
cmd = function() M.autosize_windows() end
},
}
}
local enter_resizing_mode_keymaps = {
n = {
["<C- >"] = {
cmd = function() enter_resizing_mode() end
}
},
}
local window_shifting_keymaps = {
n = {
["<C-S-Left>"] = {
cmd = function()
swap_window("h")
end
},
["<C-S-Down>"] = {
cmd = function()
swap_window("j")
end
},
["<C-S-Up>"] = {
cmd = function()
swap_window("k")
end
},
["<C-S-Right>"] = {
cmd = function()
swap_window("l")
end
},
},
}
utils.add_keymaps({
window_shifting_keymaps,
enter_resizing_mode_keymaps
})
local function on_resize_mode_enter()
utils.remove_keymaps(enter_resizing_mode_keymaps)
utils.add_keymaps(resizing_mode_keymaps)
end
local function on_resize_mode_exit()
utils.remove_keymaps(resizing_mode_keymaps)
utils.add_keymaps(enter_resizing_mode_keymaps)
end
local window_management_augroup = "WindowManagementEvents"
vim.api.nvim_create_augroup(window_management_augroup, { clear = true })
utils.create_user_event_cb(on_resize_mode_enter_event, on_resize_mode_enter, window_management_augroup)
utils.create_user_event_cb(on_resize_mode_exit_event, on_resize_mode_exit, window_management_augroup)
end
return M