mirror of
https://github.com/Ascyii/nvim.git
synced 2026-01-01 04:04:24 -05:00
Init from other configuration repository. This is just a backup and will be refactored soon
This commit is contained in:
86
lua/config/autocmds.lua
Normal file
86
lua/config/autocmds.lua
Normal file
@@ -0,0 +1,86 @@
|
||||
|
||||
-- Autocommands
|
||||
|
||||
vim.cmd(':colorscheme gruvbox')
|
||||
|
||||
if vim.g.diffm then
|
||||
-- vim.api.nvim_create_autocmd("VimEnter", {
|
||||
-- callback = function()
|
||||
-- -- Create a new empty buffer
|
||||
-- vim.cmd("enew")
|
||||
--
|
||||
-- -- Your multiline message
|
||||
-- local lines = {
|
||||
-- "Welcome to Neovim!",
|
||||
-- "",
|
||||
-- "You are in Diff Mode!",
|
||||
-- "Press <leader>do to open the Difftab.",
|
||||
-- "",
|
||||
-- "Good luck!"
|
||||
-- }
|
||||
--
|
||||
-- -- Get dimensions
|
||||
-- local width = vim.api.nvim_get_option("columns")
|
||||
-- local height = vim.api.nvim_get_option("lines")
|
||||
--
|
||||
-- -- Center vertically
|
||||
-- local start_line = math.floor((height - #lines) / 3)
|
||||
--
|
||||
-- -- Insert empty lines at the top
|
||||
-- for _ = 1, start_line do
|
||||
-- vim.api.nvim_buf_set_lines(0, -1, -1, false, {""})
|
||||
-- end
|
||||
--
|
||||
-- -- Center horizontally and insert text
|
||||
-- for _, line in ipairs(lines) do
|
||||
-- local padding = math.floor((width - #line) / 2)
|
||||
-- local padded_line = string.rep(" ", math.max(padding, 0)) .. line
|
||||
-- vim.api.nvim_buf_set_lines(0, -1, -1, false, {padded_line})
|
||||
-- end
|
||||
--
|
||||
-- -- Make buffer not modifiable
|
||||
-- vim.bo.modifiable = false
|
||||
-- vim.bo.buflisted = false
|
||||
-- end
|
||||
-- })
|
||||
|
||||
end
|
||||
|
||||
|
||||
vim.api.nvim_create_user_command("Ex", function()
|
||||
if vim.opt.diff:get() then
|
||||
-- require("diffview").open()
|
||||
print("running with diff view mode -> No ex")
|
||||
else
|
||||
-- fallback if not in diff mode (optional)
|
||||
-- vim.cmd("Explore") -- or do nothing
|
||||
-- Just disable EX
|
||||
print("You have tree view (no ex anymore)")
|
||||
end
|
||||
end, {})
|
||||
|
||||
|
||||
-- Save the last file on exit
|
||||
vim.api.nvim_create_autocmd("VimLeave", {
|
||||
callback = function()
|
||||
-- Save the last file path to a file
|
||||
local last_file = vim.fn.expand('%:p') -- Get the absolute path of the current file
|
||||
if last_file ~= "" then
|
||||
local file = io.open(vim.fn.stdpath('data') .. "/lastfile.txt", "w")
|
||||
if file then
|
||||
file:write(last_file)
|
||||
file:close()
|
||||
end
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
-- Setting a transparent background
|
||||
function Transparent(color)
|
||||
color = color or "gruvbox"
|
||||
vim.cmd.colorscheme(color)
|
||||
vim.api.nvim_set_hl(0, "Normal", { bg = "none" })
|
||||
vim.api.nvim_set_hl(0, "NormalFloat", { bg = "none" })
|
||||
end
|
||||
Transparent()
|
||||
|
||||
0
lua/config/colorscheme.lua
Normal file
0
lua/config/colorscheme.lua
Normal file
8
lua/config/init.lua
Normal file
8
lua/config/init.lua
Normal file
@@ -0,0 +1,8 @@
|
||||
-- Load lazy first
|
||||
require('config.lazy')
|
||||
|
||||
-- General settings
|
||||
require('config.options')
|
||||
require('config.keymaps')
|
||||
require('config.autocmds')
|
||||
require('config.lsp')
|
||||
292
lua/config/keymaps.lua
Normal file
292
lua/config/keymaps.lua
Normal file
@@ -0,0 +1,292 @@
|
||||
-- ###########################
|
||||
-- the heart of neovim #######
|
||||
-- ###########################
|
||||
|
||||
require("helpers.functions")
|
||||
|
||||
-- gloabal settings
|
||||
vim.keymap.set('n', '<leader>q', function()
|
||||
local success, _ = pcall(function()
|
||||
vim.cmd('wa') -- Write (save) all buffers
|
||||
end)
|
||||
vim.cmd('qa!') -- Quit all buffers forcefully
|
||||
end)
|
||||
|
||||
vim.keymap.set("n", "<leader>w", "<C-w>w")
|
||||
|
||||
vim.keymap.set('v', '<leader>p', function()
|
||||
vim.cmd('normal! "+p')
|
||||
end, { desc = 'Yank to clipboard and keep the selection' })
|
||||
|
||||
-- branching depeding on diff mode
|
||||
if vim.g.diffm then
|
||||
-- diff view commands
|
||||
vim.keymap.set('n', '<leader>do', ":DiffviewClose<CR>:DiffviewOpen<CR>")
|
||||
vim.keymap.set('n', '<leader>df', ":DiffviewClose<CR>:DiffviewFileHistory<CR>")
|
||||
vim.keymap.set('n', '<leader>dt', ":DiffviewToggleFiles<CR>")
|
||||
vim.keymap.set('n', '<leader>dc', ":DiffviewClose<CR>")
|
||||
vim.keymap.set('n', '<leader>dl', ":DiffviewLog<CR>")
|
||||
|
||||
-- vim.keymap.set("n", "<leader>e", "<C-w>w<C-w>w")
|
||||
else
|
||||
-- not in diff mode
|
||||
-- TODO: make this dynamic
|
||||
local season = "S2"
|
||||
|
||||
local links = require("helpers.linker") -- replace with real file path
|
||||
local user = vim.fn.system('whoami'):gsub('\n', '')
|
||||
local api = require("nvim-tree.api")
|
||||
local builtin = require('telescope.builtin')
|
||||
local current_date = os.date("%Y-%m-%d")
|
||||
local week_number = os.date("%W") + 1 -- Week number (starting from Sunday)
|
||||
local day_of_week = os.date("%a") -- Abbreviated weekday name (e.g., Mon, Tue)
|
||||
|
||||
-- this is how to access global vars
|
||||
function set_obs()
|
||||
-- _G is the global table. this creates variable 'obs' attached to
|
||||
-- the global table with the value 'some text value'
|
||||
_G.season = season
|
||||
end
|
||||
|
||||
|
||||
--------------------- NORMAL -------------------------
|
||||
|
||||
|
||||
-- vim.keymap.set("i", "<Tab>", "<C-p>", { silent = true })
|
||||
|
||||
|
||||
vim.keymap.set("n", "L", ":BufferNext<CR>", { silent = true }) -- also update the root with the bang
|
||||
vim.keymap.set("n", "n", "nzz", { silent = true }) -- also update the root with the bang
|
||||
vim.keymap.set("n", "N", "Nzz", { silent = true }) -- also update the root with the bang
|
||||
vim.keymap.set("n", "H", ":BufferPrevious<CR>", { silent = true }) -- also update the root with the bang
|
||||
vim.keymap.set("n", "<C-o>", "<C-o>zz", { silent = true }) -- also update the root with the bang
|
||||
vim.keymap.set("n", "<C-i>", "<C-i>zz", { silent = true }) -- also update the root with the bang
|
||||
vim.keymap.set("n", "<C-u>", "<C-u>zz", { silent = true }) -- also update the root with the bang
|
||||
vim.keymap.set("n", "<C-d>", "<C-d>zz", { silent = true }) -- also update the root with the bang
|
||||
|
||||
vim.keymap.set('n', '<leader>a', 'm9ggVG"+y`9')
|
||||
vim.keymap.set('n', '<leader>va', 'ggVG')
|
||||
|
||||
-- Launch panel if nothing is typed after <leader>z
|
||||
vim.keymap.set("n", "<leader>z", "<cmd>Telekasten panel<CR>")
|
||||
|
||||
-- Most used functions
|
||||
vim.keymap.set("n", "<leader>zf", "<cmd>Telekasten find_notes<CR>")
|
||||
vim.keymap.set("n", "<leader>zg", "<cmd>Telekasten search_notes<CR>")
|
||||
vim.keymap.set('n', '<leader>zq', ':e ~/synced/brainstore/zettelkasten/input.txt<CR>`.zz')
|
||||
vim.keymap.set("n", "<leader>zd", "<cmd>Telekasten goto_today<CR>")
|
||||
vim.keymap.set("n", "<leader>zr", "<cmd>Telekasten rename_note<CR>")
|
||||
vim.keymap.set("n", "<leader>zz", "<cmd>Telekasten follow_link<CR>")
|
||||
vim.keymap.set("n", "<leader>zn", "<cmd>Telekasten new_note<CR>")
|
||||
vim.keymap.set("n", "<leader>zb", "<cmd>Telekasten show_backlinks<CR>")
|
||||
vim.keymap.set("n", "<leader>zw", "<cmd>Telekasten find_weekly_notes<CR>")
|
||||
vim.keymap.set("n", "<leader>zI", "<cmd>Telekasten insert_img_link<CR>")
|
||||
|
||||
vim.keymap.set("n", "<leader>me", ":mes<CR>")
|
||||
vim.keymap.set("n", "<C-/>", ":ToggleTerm<CR>")
|
||||
vim.keymap.set("t", "<C-/>", "<C-\\><C-n>:ToggleTerm<CR>")
|
||||
|
||||
vim.keymap.set("n", "<leader>snt", "<cmd>set nu<CR>")
|
||||
vim.keymap.set("n", "<leader>snf", "<cmd>set nonu<CR>")
|
||||
|
||||
|
||||
-- Call insert link automatically when we start typing a link
|
||||
vim.keymap.set("n", "<leader>il", "<cmd>Telekasten insert_link<CR>")
|
||||
|
||||
require("custom.uni")
|
||||
vim.keymap.set("n", "<leader>nv", function()
|
||||
|
||||
select_course_directory()
|
||||
--pick_unicourse("/home/jonas/projects/university/S2") -- Change path accordingly
|
||||
end, { desc = "Open UniCourse menu" })
|
||||
|
||||
|
||||
vim.keymap.set('n', '<leader>ca', 'ggVGd')
|
||||
vim.keymap.set("n", "<leader>bd", ":BufferDelete<CR>", { silent = true }) -- also update the root with the bang
|
||||
|
||||
-- Typstar stuff
|
||||
vim.keymap.set("n", "<leader>ti", ":TypstarInsertRnote<CR>", { silent = true }) -- also update the root with the bang
|
||||
vim.keymap.set("n", "<leader>to", ":TypstarOpenDrawing<CR>", { silent = true }) -- also update the root with the bang
|
||||
|
||||
|
||||
-- Get a ready to use terminal
|
||||
vim.keymap.set('n', '<leader>tr', ':tabnew<CR>:term<CR>i')
|
||||
vim.keymap.set("n", "<leader>tt", ":Telescope<CR>", { desc = "Follow Link" })
|
||||
vim.keymap.set('n', '<leader>tw', watch_and_open, { noremap = true, silent = true })
|
||||
|
||||
-- This needs to be refined for quick access to a new file or a recently edited one
|
||||
vim.keymap.set('n', '<leader>ov', open_vorlesung)
|
||||
-- new quick note file
|
||||
-- TODO: make this smarter
|
||||
vim.keymap.set("n", "<leader>nn", ":e ~/synced/brainstore/zettelkasten/quick<CR>", { silent = true }) -- also update the root with the bang
|
||||
|
||||
vim.keymap.set("n", "<leader>r", set_root)
|
||||
|
||||
-- Custom journal plugin disable temporary
|
||||
-- local journal = require("custom.journal")
|
||||
-- vim.keymap.set("n", "<leader>jt", journal.open_today, { desc = "Open Today's Journal" })
|
||||
-- vim.keymap.set("n", "<leader>ja", journal.list_all_journals, { desc = "Open Today's Journal" })
|
||||
-- vim.keymap.set("n", "<leader>jm", journal.search_this_month, { desc = "Search This Month's Journals" })
|
||||
|
||||
-- Quickly open some buffers
|
||||
-- Open all the vim configs instant
|
||||
vim.keymap.set('n', '<leader>occ', ':e ~/.config/nvim/init.lua<CR>`.zz')
|
||||
vim.keymap.set('n', '<leader>oct', ':e ~/synced/vault/contacts/contacts.txt<CR>`.zz')
|
||||
vim.keymap.set('n', '<leader>ock', ':e ~/.config/nvim/lua/config/keymaps.lua<CR>`.zz')
|
||||
vim.keymap.set('n', '<leader>ocd', ':e ~/.config/nvim/lua/config/autocmds.lua<CR>`.zz')
|
||||
vim.keymap.set('n', '<leader>oco', ':e ~/.config/nvim/lua/config/options.lua<CR>`.zz')
|
||||
vim.keymap.set('n', '<leader>ocl', ':e ~/.config/nvim/lua/config/lazy.lua<CR>`.zz')
|
||||
vim.keymap.set('n', '<leader>oczl', ':e ~/.config/nvim/lua/config/lsp.lua<CR>`.zz')
|
||||
vim.keymap.set('n', '<leader>ocp', ':e ~/.config/nvim/lua/plugins/main.lua<CR>`.zz')
|
||||
vim.keymap.set('n', '<leader>ocf', ':e ~/.config/nvim/lua/helpers/functions.lua<CR>`.zz')
|
||||
vim.keymap.set('n', '<leader>oca', ':e ~/.config/nvim/lua/helpers/after.lua<CR>`.zz')
|
||||
vim.keymap.set('n', '<leader>oq', ':e ~/synced/brainstore/input.txt<CR>`.zz')
|
||||
vim.keymap.set('n', '<leader>ohh', ':e ~/configuration/nixos/users/' .. user .. '/home.nix<CR>`.zz')
|
||||
vim.keymap.set('n', '<leader>op', ':e ~/configuration/nixos/users/' .. user .. '/packages.nix<CR>`.zz')
|
||||
vim.keymap.set('n', '<leader>on', ':e ~/configuration/nixos/configuration.nix<CR>`.zz')
|
||||
vim.keymap.set('n', '<leader>om', ':e ~/configuration/nixos/modules<CR>')
|
||||
vim.keymap.set('n', '<leader>ow', ':e ~/synced/brainstore/waste.txt<CR>')
|
||||
vim.keymap.set('n', '<leader>oho', ':e ~/configuration/nixos/hosts<CR>')
|
||||
vim.keymap.set('n', '<leader>os', ':e ~/configuration/nixos/modules/server<CR>')
|
||||
vim.keymap.set('n', '<leader>ot', ':e ~/synced/brainstore/todos/todo.txt<CR>`.zz')
|
||||
vim.keymap.set('n', '<leader>od', ':e ~/synced/brainstore/todos/done.txt<CR>`.zz')
|
||||
vim.keymap.set('n', '<leader>ou', ':e ~/projects/university/' .. season .. '/input.txt<CR>`.zz')
|
||||
vim.keymap.set('n', '<leader>oz', ':e ~/.zshrc<CR>`.zz')
|
||||
vim.keymap.set('n', '<leader>oaa', ':e ~/.common_shell<CR>`.zz')
|
||||
-- Map the function to a keybinding (e.g., <leader>lf to open the last file)
|
||||
vim.keymap.set("n", "<leader>or", "<cmd>lua open_last_file()<CR>", { noremap = true, silent = true })
|
||||
-- open the calendar
|
||||
--
|
||||
function open_cal()
|
||||
local current_date = os.date("%Y-%m-%d")
|
||||
local week_number = os.date("%V")
|
||||
local day_of_week = os.date("%a")
|
||||
local path = "~/synced/brainstore/calendar/calendar_" .. os.date("%Y") .. ".txt"
|
||||
local keys = ":e " .. path .. "<CR>/" .. current_date .. " w" .. tonumber(week_number) .. " " .. day_of_week .. "<CR>$"
|
||||
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(keys, true, false, true), 'n', true)
|
||||
end
|
||||
|
||||
vim.keymap.set('n', '<leader>ok', open_cal)
|
||||
-------------------------------------------------------------------------------------
|
||||
|
||||
vim.keymap.set("n", "<leader>lf", links.insert_brainstore_link, { desc = "Link Brainstore file" })
|
||||
vim.keymap.set("n", "<leader>lm", links.insert_mail_link, { desc = "Link Mail" })
|
||||
vim.keymap.set('n', '<leader>ll', ':Lazy<CR>')
|
||||
vim.keymap.set("n", "<leader>lp", links.insert_project_link, { desc = "Link Project" })
|
||||
vim.keymap.set("n", "<leader>lc", links.insert_contact_link, { desc = "Link Contact" })
|
||||
vim.keymap.set("n", "<leader>ld", links.insert_date_link, { desc = "Link Contact" })
|
||||
|
||||
|
||||
-- nvim tree
|
||||
vim.keymap.set("n", "<leader>e", function()
|
||||
api.tree.toggle({ find_file = true, update_root = true, focus = true, })
|
||||
|
||||
end, { silent = true }) -- also update the root with the bang
|
||||
|
||||
vim.keymap.set('n', '<leader>ia', 'gg=G<C-o>zz')
|
||||
vim.keymap.set('n', '<leader>ya', 'ggVG"+y<C-o>')
|
||||
|
||||
-- Map <leader>q to save and quit all buffers with error handling
|
||||
-- Dangerous but feels good
|
||||
|
||||
vim.keymap.set('n', '<leader>ss', ':wa<CR>')
|
||||
vim.keymap.set('n', '<leader>sw', function()
|
||||
local word = vim.fn.expand("<cword>")
|
||||
local replacement = vim.fn.input("Replace '" .. word .. "' with: ")
|
||||
if replacement ~= "" then
|
||||
vim.cmd(string.format("%%s/\\<%s\\>/%s/gI", vim.fn.escape(word, '\\/'), vim.fn.escape(replacement, '\\/')))
|
||||
end
|
||||
end, { desc = "Substitute word under cursor (prompt)" })
|
||||
vim.keymap.set('v', '<leader>sv', function()
|
||||
-- Save the current selection
|
||||
local save_reg = vim.fn.getreg('"')
|
||||
local save_regtype = vim.fn.getregtype('"')
|
||||
|
||||
-- Yank the visual selection into the " register
|
||||
vim.cmd('normal! ""y')
|
||||
|
||||
local selection = vim.fn.getreg('"')
|
||||
-- Escape magic characters for the search
|
||||
selection = vim.fn.escape(selection, '\\/.*$^~[]')
|
||||
|
||||
-- Prompt for the replacement text
|
||||
local replacement = vim.fn.input("Replace '" .. selection .. "' with: ")
|
||||
if replacement ~= "" then
|
||||
vim.cmd(string.format("%%s/%s/%s/gI", selection, replacement))
|
||||
end
|
||||
|
||||
-- Restore previous register
|
||||
vim.fn.setreg('"', save_reg, save_regtype)
|
||||
end, { desc = "Substitute selection in file" })
|
||||
-- vim.keymap.set('n', '<leader>sl', search_brain_links)
|
||||
|
||||
vim.keymap.set('n', '<leader>pp', function()
|
||||
vim.api.nvim_command('normal! "+p')
|
||||
end, { desc = 'Paste from system clipboard' })
|
||||
|
||||
-- vim.keymap.set('n', '<leader>fg', builtin.live_grep, { desc = 'Telescope live grep' })
|
||||
vim.keymap.set('n', '<leader>fr', function()
|
||||
require('telescope.builtin').oldfiles({
|
||||
disable_devicons = true,
|
||||
})
|
||||
end, { noremap = true, silent = true })
|
||||
vim.keymap.set('n', '<leader>fb', builtin.buffers, { desc = 'Telescope buffers' })
|
||||
vim.keymap.set('n', '<leader>fh', builtin.help_tags, { desc = 'Telescope help tags' })
|
||||
vim.keymap.set("n", "<leader>fl", links.follow_link, { desc = "Follow Link" })
|
||||
|
||||
|
||||
vim.keymap.set('n', '<leader>g', function()
|
||||
require('telescope.builtin').live_grep({
|
||||
disable_devicons = true,
|
||||
cwd = vim.fn.getcwd(), -- set the starting directory
|
||||
additional_args = function()
|
||||
return { '--hidden', '--glob', '!.git/*' } -- include hidden files but exclude .git
|
||||
end,
|
||||
})
|
||||
end, { noremap = true, silent = true })
|
||||
|
||||
vim.keymap.set('n', '<leader><leader>', find_eff, { desc = 'Telescope find files (with dotfiles and folders but excluding .git, .cache, .local, and large files)' })
|
||||
|
||||
------------------------ VISUAL ------------------
|
||||
|
||||
vim.keymap.set('v', 'p', function()
|
||||
local unnamed_content = vim.fn.getreg('""')
|
||||
vim.api.nvim_command('normal! p')
|
||||
vim.fn.setreg('""', unnamed_content)
|
||||
end, { desc = 'Paste from unnamed register (don\'t overwrite it) in visual mode' })
|
||||
vim.keymap.set('v', '<leader>y', function()
|
||||
vim.cmd('normal! "+y')
|
||||
vim.cmd('normal! gv')
|
||||
end, { desc = 'Yank to clipboard and keep the selection' })
|
||||
|
||||
|
||||
---------------------------- INSERT ---------------------------
|
||||
|
||||
vim.keymap.set('i', '<C-k>', function()
|
||||
local col = vim.fn.col('.')
|
||||
local line = vim.fn.line('.')
|
||||
local line_len = vim.fn.col('$') - 1
|
||||
if col <= line_len then
|
||||
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes('<Right>', true, false, true), 'n', true)
|
||||
else
|
||||
if line < vim.fn.line('$') then
|
||||
vim.cmd('normal! j^')
|
||||
end
|
||||
end
|
||||
end)
|
||||
-- Move left with wrapping
|
||||
vim.keymap.set('i', '<C-j>', function()
|
||||
local col = vim.fn.col('.')
|
||||
local line = vim.fn.line('.')
|
||||
if col > vim.fn.indent(line) + 1 then
|
||||
-- not at very beginning (after indent), move left
|
||||
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes('<Left>', true, false, true), 'n', true)
|
||||
else
|
||||
if line > 1 then
|
||||
vim.cmd('normal! k$')
|
||||
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes('<Right>', true, false, true), 'n', true)
|
||||
end
|
||||
end
|
||||
end, { noremap = true, silent = true })
|
||||
end
|
||||
|
||||
48
lua/config/lazy.lua
Normal file
48
lua/config/lazy.lua
Normal file
@@ -0,0 +1,48 @@
|
||||
-- Bootstrap lazy.nvim
|
||||
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
|
||||
if not (vim.uv or vim.loop).fs_stat(lazypath) then
|
||||
local lazyrepo = "https://github.com/folke/lazy.nvim.git"
|
||||
local out = vim.fn.system({ "git", "clone", "--filter=blob:none", "--branch=stable", lazyrepo, lazypath })
|
||||
if vim.v.shell_error ~= 0 then
|
||||
vim.api.nvim_echo({
|
||||
{ "Failed to clone lazy.nvim:\n", "ErrorMsg" },
|
||||
{ out, "WarningMsg" },
|
||||
{ "\nPress any key to exit..." },
|
||||
}, true, {})
|
||||
vim.fn.getchar()
|
||||
os.exit(1)
|
||||
end
|
||||
end
|
||||
vim.opt.rtp:prepend(lazypath)
|
||||
|
||||
-- Make sure to setup `mapleader` and `maplocalleader` before
|
||||
-- loading lazy.nvim so that mappings are correct.
|
||||
-- This is also a good place to setup other settings (vim.opt)
|
||||
vim.g.mapleader = " "
|
||||
vim.g.maplocalleader = "\\"
|
||||
|
||||
-- Setup lazy.nvim
|
||||
require("lazy").setup({
|
||||
spec = {
|
||||
-- import your plugins
|
||||
-- { import = "plugins" },
|
||||
require("plugins")
|
||||
},
|
||||
-- Configure any other settings here. See the documentation for more details.
|
||||
-- colorscheme that will be used when installing plugins.
|
||||
install = { colorscheme = { "gruvbox" } },
|
||||
-- automatically check for plugin updates
|
||||
checker = { enabled = false },
|
||||
dev = {
|
||||
path = "~/projects",
|
||||
fallback = true,
|
||||
},
|
||||
change_detection = {
|
||||
enabled = false, -- disable automatic reloading
|
||||
notify = false, -- optional: also disable notification when it would reload
|
||||
},
|
||||
})
|
||||
|
||||
-- after lazy did its job
|
||||
require("helpers.after")
|
||||
|
||||
109
lua/config/lsp.lua
Normal file
109
lua/config/lsp.lua
Normal file
@@ -0,0 +1,109 @@
|
||||
-- lsp.lua
|
||||
local lspconfig = require("lspconfig")
|
||||
local cmp = require("cmp")
|
||||
|
||||
|
||||
require("lspconfig").clangd.setup({
|
||||
})
|
||||
|
||||
|
||||
-- nvim-cmp setup
|
||||
cmp.setup({
|
||||
snippet = {
|
||||
expand = function(args) require("luasnip").lsp_expand(args.body) end,
|
||||
},
|
||||
mapping = cmp.mapping.preset.insert({
|
||||
["<C-Space>"] = cmp.mapping.complete(),
|
||||
["<CR>"] = cmp.mapping.confirm({ select = true }),
|
||||
["<Tab>"] = cmp.mapping.select_next_item(),
|
||||
["<S-Tab>"] = cmp.mapping.select_prev_item(),
|
||||
}),
|
||||
sources = cmp.config.sources({
|
||||
{ name = "nvim_lsp" },
|
||||
{ name = "luasnip" },
|
||||
}, {
|
||||
{ name = "buffer" },
|
||||
{ name = "path" },
|
||||
}),
|
||||
})
|
||||
|
||||
-- Capabilities for nvim-cmp
|
||||
local capabilities = require("cmp_nvim_lsp").default_capabilities()
|
||||
|
||||
|
||||
-- Example servers
|
||||
local servers = { "gopls", "pyright", "lua_ls", "rust_analyzer", "clangd" }
|
||||
|
||||
|
||||
require("mason-lspconfig").setup({
|
||||
ensure_installed = servers
|
||||
})
|
||||
for _, lsp in ipairs(servers) do
|
||||
local config = {
|
||||
capabilities = capabilities,
|
||||
on_attach = function(_, bufnr)
|
||||
local opts = { buffer = bufnr, noremap = true, silent = true }
|
||||
|
||||
-- LSP core
|
||||
vim.keymap.set("n", "gd", vim.lsp.buf.definition, opts) -- Jump to definition
|
||||
vim.keymap.set("n", "gD", vim.lsp.buf.declaration, opts) -- Jump to declaration
|
||||
vim.keymap.set("n", "gr", vim.lsp.buf.references, opts) -- Find references
|
||||
vim.keymap.set("n", "gi", vim.lsp.buf.implementation, opts) -- Go to implementation
|
||||
vim.keymap.set("n", "gt", vim.lsp.buf.type_definition, opts) -- Go to type definition
|
||||
vim.keymap.set("n", "K", vim.lsp.buf.hover, opts) -- Hover docs
|
||||
vim.keymap.set("n", "<C-k>", vim.lsp.buf.signature_help, opts) -- Signature help
|
||||
|
||||
-- Refactor
|
||||
vim.keymap.set("n", "<leader>rn", vim.lsp.buf.rename, opts) -- Rename symbol
|
||||
vim.keymap.set("n", "<leader>ca", vim.lsp.buf.code_action, opts) -- Code actions
|
||||
|
||||
-- Diagnostics
|
||||
vim.keymap.set("n", "[d", vim.diagnostic.goto_prev, opts) -- Previous diagnostic
|
||||
vim.keymap.set("n", "]d", vim.diagnostic.goto_next, opts) -- Next diagnostic
|
||||
vim.keymap.set("n", "<leader>e", vim.diagnostic.open_float, opts) -- Show diagnostic
|
||||
vim.keymap.set("n", "<leader>lq", vim.diagnostic.setloclist, opts) -- List diagnostics
|
||||
|
||||
-- Workspace
|
||||
vim.keymap.set("n", "<leader>wa", vim.lsp.buf.add_workspace_folder, opts)
|
||||
vim.keymap.set("n", "<leader>wr", vim.lsp.buf.remove_workspace_folder, opts)
|
||||
vim.keymap.set("n", "<leader>wl", function()
|
||||
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
|
||||
end, opts)
|
||||
|
||||
-- Formatting
|
||||
vim.keymap.set("n", "<leader>fff", function()
|
||||
vim.lsp.buf.format({ async = true })
|
||||
end, opts)
|
||||
end
|
||||
}
|
||||
if lsp == "lua_ls" then
|
||||
config.settings = {
|
||||
Lua = {
|
||||
diagnostics = {
|
||||
globals = { "vim" },
|
||||
},
|
||||
},
|
||||
}
|
||||
end
|
||||
|
||||
if lsp == "clangd" then
|
||||
config.cmd = {
|
||||
"clangd",
|
||||
"--query-driver=/run/current-system/sw/bin/clang",
|
||||
"--compile-commands-dir=build",
|
||||
}
|
||||
end
|
||||
|
||||
lspconfig[lsp].setup(config)
|
||||
end
|
||||
-- Diagnostic config (inline virtual text + signs + underlines)
|
||||
vim.diagnostic.config({
|
||||
virtual_text = {
|
||||
prefix = "●", -- could be '●', '▎', 'x'
|
||||
spacing = 2,
|
||||
},
|
||||
signs = true,
|
||||
underline = true,
|
||||
update_in_insert = false,
|
||||
severity_sort = true,
|
||||
})
|
||||
23
lua/config/options.lua
Normal file
23
lua/config/options.lua
Normal file
@@ -0,0 +1,23 @@
|
||||
|
||||
-- vim.o.textwidth = 80
|
||||
-- vim.o.wrap = true;
|
||||
vim.o.shiftwidth = 4;
|
||||
vim.o.tabstop = 4;
|
||||
vim.o.number = true;
|
||||
vim.o.ignorecase = true;
|
||||
vim.o.mouse= "";
|
||||
|
||||
-- this stands for undofile and should be always used because why not?
|
||||
vim.o.udf = true;
|
||||
|
||||
-- optionally enable 24-bit colour
|
||||
vim.opt.termguicolors = true
|
||||
|
||||
if vim.g.diffm then
|
||||
vim.g.loaded_netrw = 0
|
||||
vim.g.loaded_netrwPlugin = 0
|
||||
else
|
||||
vim.g.loaded_netrw = 1
|
||||
vim.g.loaded_netrwPlugin = 1
|
||||
end
|
||||
vim.opt.signcolumn = "yes"
|
||||
Reference in New Issue
Block a user