updates to integrate with code better

This commit is contained in:
Solomon Laing 2023-12-01 18:53:11 +10:30
parent a637f87be0
commit 136d75b543
7 changed files with 670 additions and 624 deletions

View File

@ -1,2 +1,13 @@
require("lazyvim") -- my config based on folkes LazyVim starter
-- require("chris") -- my config based on Christian Chiarullis work
if not vim.g.vscode then
require("lazyvim") -- my config based on folkes LazyVim starter
-- require("chris") -- my config based on Christian Chiarullis work
return
end
vim.g.mapleader = " "
vim.g.maplocalleader = " "
-- Add some vscode specific keymaps
vim.keymap.set("n", "<leader><space>", "<cmd>Find<cr>")
vim.keymap.set("n", "<leader>/", [[<cmd>call VSCodeNotify('workbench.action.findInFiles')<cr>]])
vim.keymap.set("n", "<leader>ss", [[<cmd>call VSCodeNotify('workbench.action.gotoSymbol')<cr>]])

View File

@ -1,27 +1,27 @@
local M = {}
local function load(name)
local Util = require("lazy.core.util")
-- always load lazyvim, then user file
for _, mod in ipairs({ "lazyvim.config." .. name, "config." .. name }) do
Util.try(function()
require(mod)
end, {
msg = "Failed loading " .. mod,
on_error = function(msg)
local modpath = require("lazy.core.cache").find(mod)
if modpath then
Util.error(msg)
end
end,
})
end
local Util = require("lazy.core.util")
-- always load lazyvim, then user file
for _, mod in ipairs({ "lazyvim.config." .. name, "config." .. name }) do
Util.try(function()
require(mod)
end, {
msg = "Failed loading " .. mod,
on_error = function(msg)
local modpath = require("lazy.core.cache").find(mod)
if modpath then
Util.error(msg)
end
end,
})
end
end
M.setup = function()
load("options")
load("autocmds")
load("keymaps")
load("options")
load("autocmds")
load("keymaps")
end
return M

View File

@ -1,14 +1,14 @@
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
vim.fn.system({
"git",
"clone",
"--filter=blob:none",
"https://github.com/folke/lazy.nvim.git",
"--branch=stable",
lazypath,
})
vim.fn.system({
"git",
"clone",
"--filter=blob:none",
"https://github.com/folke/lazy.nvim.git",
"--branch=stable",
lazypath,
})
end
-- map leader and register keymap for Lazy.
@ -20,24 +20,10 @@ vim.opt.rtp:prepend(vim.env.LAZY or lazypath)
require("lazyvim.config").setup()
if not vim.g.vscode then
require("lazy").setup({
spec = "lazyvim.plugins",
defaults = { lazy = true, version = false },
checker = { enabled = true },
})
end
require("lazy").setup({
spec = "lazyvim.plugins",
defaults = { lazy = true, version = false },
checker = { enabled = true },
})
-- This might not be best, but it allows for easy resetting
ColorMe = function()
local colorscheme = "gruvbox-material"
local okay, _ = pcall(vim.cmd, "colorscheme " .. colorscheme)
if not okay then
vim.notify("Colorscheme " .. colorscheme .. " not found!")
vim.cmd("colorsheme habamax")
end
end
ColorMe()
require("lazyvim.utils").setColorscheme()

View File

@ -1,56 +1,89 @@
return {
{
"hrsh7th/nvim-cmp",
event = "InsertEnter",
dependencies = {
"hrsh7th/cmp-nvim-lsp",
"hrsh7th/cmp-path",
"hrsh7th/cmp-emoji",
"hrsh7th/cmp-buffer",
"saadparwaiz1/cmp_luasnip",
},
config = function()
local cmp = require("cmp")
cmp.setup({
completion = {
completeopt = "menu,menuone,noinsert",
},
snippet = {
expand = function(args)
require("luasnip").lsp_expand(args.body)
end,
},
mapping = cmp.mapping.preset.insert({
["<C-b>"] = cmp.mapping.scroll_docs(-4),
["<C-f>"] = cmp.mapping.scroll_docs(4),
["<C-Space>"] = cmp.mapping.complete(),
["<C-e>"] = cmp.mapping.abort(),
["<CR>"] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
["<C-n>"] = cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Insert }),
["<C-p>"] = cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Insert }),
}),
sources = cmp.config.sources({
{ name = "nvim_lsp" },
{ name = "luasnip" },
{ name = "path" },
{ name = "emoji" },
{ name = "buffer" },
}),
formatting = {
format = function(_, item)
local icons = require("lazyvim.config.icons").kind
if icons[item.kind] then
item.kind = icons[item.kind] .. " " .. item.kind
end
return item
end,
},
experimental = {
ghost_text = {
hl_group = "LspCodeLens",
},
},
})
end,
},
{
"hrsh7th/nvim-cmp",
event = "InsertEnter",
dependencies = {
"hrsh7th/cmp-nvim-lsp",
"hrsh7th/cmp-path",
"hrsh7th/cmp-emoji",
"hrsh7th/cmp-buffer",
"saadparwaiz1/cmp_luasnip",
{
"zbirenbaum/copilot-cmp",
dependencies = "copilot.lua",
opts = {},
config = function(_, opts)
local copilot_cmp = require("copilot_cmp")
copilot_cmp.setup(opts)
-- attach cmp source whenever copilot attaches
-- fixes lazy-loading issues with the copilot cmp source
require("lazyvim.utils").on_attach(function(client)
if client.name == "copilot" then
copilot_cmp._on_insert_enter({})
end
end)
end,
},
},
config = function()
local cmp = require("cmp")
cmp.setup({
completion = {
completeopt = "menu,menuone,noinsert",
},
snippet = {
expand = function(args)
require("luasnip").lsp_expand(args.body)
end,
},
mapping = cmp.mapping.preset.insert({
["<C-b>"] = cmp.mapping.scroll_docs(-4),
["<C-f>"] = cmp.mapping.scroll_docs(4),
["<C-Space>"] = cmp.mapping.complete(),
["<C-e>"] = cmp.mapping.abort(),
["<CR>"] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
["<C-n>"] = cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Insert }),
["<C-p>"] = cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Insert }),
}),
sources = cmp.config.sources({
{ name = "nvim_lsp" },
{ name = "luasnip" },
{ name = "path" },
{ name = "emoji" },
{ name = "buffer" },
{ name = "copilot" },
}),
formatting = {
format = function(_, item)
local icons = require("lazyvim.config.icons").kind
if icons[item.kind] then
item.kind = icons[item.kind] .. " " .. item.kind
end
return item
end,
},
experimental = {
ghost_text = {
hl_group = "LspCodeLens",
},
},
})
end,
},
{
"zbirenbaum/copilot-cmp",
dependencies = "copilot.lua",
opts = {},
config = function(_, opts)
local copilot_cmp = require("copilot_cmp")
copilot_cmp.setup(opts)
-- attach cmp source whenever copilot attaches
-- fixes lazy-loading issues with the copilot cmp source
require("lazyvim.utils").on_attach(function(client)
if client.name == "copilot" then
copilot_cmp._on_insert_enter({})
end
end)
end,
}
}

View File

@ -1,212 +1,212 @@
local icons = require("lazyvim.config.icons")
return {
{
"nvim-lua/plenary.nvim",
},
{
"RRethy/vim-illuminate",
event = "BufReadPost",
config = function()
require("illuminate").configure({ delay = 200 })
end,
{
"nvim-lua/plenary.nvim",
},
{
"RRethy/vim-illuminate",
event = "BufReadPost",
config = function()
require("illuminate").configure({ delay = 200 })
end,
-- stylua: ignore
keys = {
{ "]]", function() require("illuminate").goto_next_reference(false) end, desc = "Next Reference", },
{ "[[", function() require("illuminate").goto_prev_reference(false) end, desc = "Prev Reference" },
},
},
{
"nvim-lua/popup.nvim",
},
{
"folke/neodev.nvim",
},
-- {
-- "rcarriga/nvim-notify",
-- opts = {
-- -- Animation style (see below for details)
-- stages = "static",
--
-- -- Render function for notifications. See notify-render()
-- render = "default",
--
-- -- Default timeout for notifications
-- timeout = 2000,
--
-- -- For stages that change opacity this is treated as the highlight behind the window
-- -- Set this to either a highlight group or an RGB hex value e.g. "#000000"
-- background_colour = "Normal",
--
-- -- Minimum width for notification windows
-- minimum_width = 10,
--
-- -- Icons for the different levels
-- icons = {
-- ERROR = icons.diagnostics.Error,
-- WARN = icons.diagnostics.Warning,
-- INFO = icons.diagnostics.Information,
-- DEBUG = icons.ui.Bug,
-- TRACE = icons.ui.Pencil,
-- },
-- },
-- },
{
"echasnovski/mini.bufremove",
event = "VeryLazy",
},
{
"nvim-lua/popup.nvim",
},
{
"folke/neodev.nvim",
},
-- {
-- "rcarriga/nvim-notify",
-- opts = {
-- -- Animation style (see below for details)
-- stages = "static",
--
-- -- Render function for notifications. See notify-render()
-- render = "default",
--
-- -- Default timeout for notifications
-- timeout = 2000,
--
-- -- For stages that change opacity this is treated as the highlight behind the window
-- -- Set this to either a highlight group or an RGB hex value e.g. "#000000"
-- background_colour = "Normal",
--
-- -- Minimum width for notification windows
-- minimum_width = 10,
--
-- -- Icons for the different levels
-- icons = {
-- ERROR = icons.diagnostics.Error,
-- WARN = icons.diagnostics.Warning,
-- INFO = icons.diagnostics.Information,
-- DEBUG = icons.ui.Bug,
-- TRACE = icons.ui.Pencil,
-- },
-- },
-- },
{
"echasnovski/mini.bufremove",
event = "VeryLazy",
-- stylua: ignore
keys = {
{ "<leader>bd", function() require("mini.bufremove").delete(0, false) end, desc = "Delete Buffer" },
{ "<leader>bD", function() require("mini.bufremove").delete(0, true) end, desc = "Delete Buffer (Force)" },
{ "<leader>bd", function() require("mini.bufremove").delete(0, false) end, desc = "Delete Buffer" },
{ "<leader>bD", function() require("mini.bufremove").delete(0, true) end, desc = "Delete Buffer (Force)" },
},
},
-- {
-- "ghillb/cybu.nvim",
-- event = "VeryLazy",
-- keys = {
-- { "<leader>bl", "<cmd>CybuNext<cr>", desc = "Next Buffer" },
-- { "<leader>bh", "<cmd>CybuPrev<cr>", desc = "Prev Buffer" },
-- },
-- opts = {
-- position = {
-- relative_to = "win", -- win, editor, cursor
-- anchor = "topright", -- topleft, topcenter, topright,
-- -- centerleft, center, centerright,
-- -- bottomleft, bottomcenter, bottomright
-- -- vertical_offset = 10, -- vertical offset from anchor in lines
-- -- horizontal_offset = 0, -- vertical offset from anchor in columns
-- -- max_win_height = 5, -- height of cybu window in lines
-- -- max_win_width = 0.5, -- integer for absolute in columns
-- -- float for relative to win/editor width
-- },
-- display_time = 1750, -- time the cybu window is displayed
-- style = {
-- separator = " ", -- string used as separator
-- prefix = "…", -- string used as prefix for truncated paths
-- padding = 1, -- left & right padding in number of spaces
-- hide_buffer_id = true,
-- devicons = {
-- enabled = true, -- enable or disable web dev icons
-- colored = true, -- enable color for web dev icons
-- },
-- },
-- },
-- },
{
"mbbill/undotree",
cmd = { "UndotreeToggle" },
},
{
"MunifTanjim/nui.nvim",
},
{
"kyazdani42/nvim-web-devicons",
},
{
"lukas-reineke/indent-blankline.nvim",
opts = {},
},
{
"windwp/nvim-autopairs",
event = "VeryLazy",
opts = {
disable_filetype = { "TelescopePrompt", "spectre_panel" },
ignored_next_char = "[%w%.*]", -- don't place autopairs when cursor sits infront of any character.
},
config = function(_, opts)
require("nvim-autopairs").setup(opts)
end,
},
{
"preservim/vim-markdown",
},
{
"nacro90/numb.nvim",
event = "BufEnter",
config = function()
require("numb").setup({
show_numbers = true, -- enable 'number' for the window while peeking
show_cursorline = true, -- enable 'cursorline' for window wdile peeking
})
end,
},
{
"junegunn/vim-slash",
},
{
"folke/zen-mode.nvim",
cmd = { "ZenMode" },
config = function()
require("zen-mode").setup({
window = {
backdrop = 1,
height = 0.9,
width = 80,
options = {
signcolumn = "no",
number = false,
relativenumber = false,
cursorline = true,
cursorcolumn = false, -- disable cursor column
},
},
plugins = {
gitsigns = { enabled = false },
tmux = { enabled = false },
twilight = { enabled = false },
},
on_open = function()
vim.g.cmp_active = false
vim.cmd([[LspStop]])
vim.opt.sidescrolloff = 0
end,
on_close = function()
vim.g.cmp_active = true
vim.cmd([[LspStart]])
vim.opt.sidescrolloff = 8
end,
})
end,
},
{
"echasnovski/mini.surround",
keys = { "gz" },
opts = {
mappings = {
add = "gza", -- Add surrounding in Normal and Visual modes
delete = "gzd", -- Delete surrounding
find = "gzf", -- Find surrounding (to the right)
find_left = "gzF", -- Find surrounding (to the left)
highlight = "gzh", -- Highlight surrounding
replace = "gzr", -- Replace surrounding
update_n_lines = "gzn", -- Update `n_lines`
},
},
config = function(_, opts)
-- use gz mappings instead of s to prevent conflict with leap
require("mini.surround").setup(opts)
end,
},
{
"danymat/neogen",
event = "BufEnter",
config = function()
require("neogen").setup({
enabled = true,
input_after_comment = true,
})
end,
},
{
"SmiteshP/nvim-navic",
init = function()
vim.g.navic_silence = true
require("lazyvim.utils").on_attach(function(client, buffer)
if client.server_capabilities.documentSymbolProvider then
require("nvim-navic").attach(client, buffer)
end
end)
end,
opts = { separator = " ", highlight = true, depth_limit = 5 },
},
},
-- {
-- "ghillb/cybu.nvim",
-- event = "VeryLazy",
-- keys = {
-- { "<leader>bl", "<cmd>CybuNext<cr>", desc = "Next Buffer" },
-- { "<leader>bh", "<cmd>CybuPrev<cr>", desc = "Prev Buffer" },
-- },
-- opts = {
-- position = {
-- relative_to = "win", -- win, editor, cursor
-- anchor = "topright", -- topleft, topcenter, topright,
-- -- centerleft, center, centerright,
-- -- bottomleft, bottomcenter, bottomright
-- -- vertical_offset = 10, -- vertical offset from anchor in lines
-- -- horizontal_offset = 0, -- vertical offset from anchor in columns
-- -- max_win_height = 5, -- height of cybu window in lines
-- -- max_win_width = 0.5, -- integer for absolute in columns
-- -- float for relative to win/editor width
-- },
-- display_time = 1750, -- time the cybu window is displayed
-- style = {
-- separator = " ", -- string used as separator
-- prefix = "…", -- string used as prefix for truncated paths
-- padding = 1, -- left & right padding in number of spaces
-- hide_buffer_id = true,
-- devicons = {
-- enabled = true, -- enable or disable web dev icons
-- colored = true, -- enable color for web dev icons
-- },
-- },
-- },
-- },
{
"mbbill/undotree",
cmd = { "UndotreeToggle" },
},
{
"MunifTanjim/nui.nvim",
},
{
"kyazdani42/nvim-web-devicons",
},
{
"lukas-reineke/indent-blankline.nvim",
opts = {},
},
{
"windwp/nvim-autopairs",
event = "VeryLazy",
opts = {
disable_filetype = { "TelescopePrompt", "spectre_panel" },
ignored_next_char = "[%w%.*]", -- don't place autopairs when cursor sits infront of any character.
},
config = function(_, opts)
require("nvim-autopairs").setup(opts)
end,
},
{
"preservim/vim-markdown",
},
{
"nacro90/numb.nvim",
event = "BufEnter",
config = function()
require("numb").setup({
show_numbers = true, -- enable 'number' for the window while peeking
show_cursorline = true, -- enable 'cursorline' for window wdile peeking
})
end,
},
{
"junegunn/vim-slash",
},
{
"folke/zen-mode.nvim",
cmd = { "ZenMode" },
config = function()
require("zen-mode").setup({
window = {
backdrop = 1,
height = 0.9,
width = 80,
options = {
signcolumn = "no",
number = false,
relativenumber = false,
cursorline = true,
cursorcolumn = false, -- disable cursor column
},
},
plugins = {
gitsigns = { enabled = false },
tmux = { enabled = false },
twilight = { enabled = false },
},
on_open = function()
vim.g.cmp_active = false
vim.cmd([[LspStop]])
vim.opt.sidescrolloff = 0
end,
on_close = function()
vim.g.cmp_active = true
vim.cmd([[LspStart]])
vim.opt.sidescrolloff = 8
end,
})
end,
},
{
"echasnovski/mini.surround",
keys = { "gz" },
opts = {
mappings = {
add = "gza", -- Add surrounding in Normal and Visual modes
delete = "gzd", -- Delete surrounding
find = "gzf", -- Find surrounding (to the right)
find_left = "gzF", -- Find surrounding (to the left)
highlight = "gzh", -- Highlight surrounding
replace = "gzr", -- Replace surrounding
update_n_lines = "gzn", -- Update `n_lines`
},
},
config = function(_, opts)
-- use gz mappings instead of s to prevent conflict with leap
require("mini.surround").setup(opts)
end,
},
{
"danymat/neogen",
event = "BufEnter",
config = function()
require("neogen").setup({
enabled = true,
input_after_comment = true,
})
end,
},
{
"SmiteshP/nvim-navic",
init = function()
vim.g.navic_silence = true
require("lazyvim.utils").on_attach(function(client, buffer)
if client.server_capabilities.documentSymbolProvider then
require("nvim-navic").attach(client, buffer)
end
end)
end,
opts = { separator = " ", highlight = true, depth_limit = 5 },
},
}

View File

@ -1,247 +1,251 @@
return {
{
"folke/which-key.nvim",
event = "VeryLazy",
opts = {
plugins = {
-- marks = true, -- shows a list of your marks on ' and `
-- registers = true, -- shows your registers on " in NORMAL or <C-r> in INSERT mode
spelling = {
enabled = true, -- enabling this will show WhichKey when pressing z= to select spelling suggestions
suggestions = 20, -- how many suggestions should be shown in the list?
},
},
key_labels = {
-- override the label used to display some keys. It doesn't effect WK in any other way.
["<leader>"] = "SPC",
},
icons = {
breadcrumb = "»", -- symbol used in the command line area that shows your active key combo
separator = "", -- symbol used between a key and it's label
group = "+", -- symbol prepended to a group
},
popup_mappings = {
scroll_down = "<C-d>", -- binding to scroll down inside the popup
scroll_up = "<C-u>", -- binding to scroll up inside the popup
},
window = {
border = "rounded", -- none, single, double, shadow
position = "bottom", -- bottom, top
margin = { 1, 0, 1, 0 }, -- extra window margin [top, right, bottom, left]
padding = { 2, 2, 2, 2 }, -- extra window padding [top, right, bottom, left]
winblend = 0,
},
layout = {
height = { min = 4, max = 25 }, -- min and max height of the columns
width = { min = 20, max = 50 }, -- min and max width of the columns
spacing = 3, -- spacing between columns
align = "center", -- align columns left, center or right
},
},
config = function(_, opts)
local whichkey = require("which-key")
local utils = require("lazyvim.utils")
{
"folke/which-key.nvim",
event = "VeryLazy",
opts = {
plugins = {
-- marks = true, -- shows a list of your marks on ' and `
-- registers = true, -- shows your registers on " in NORMAL or <C-r> in INSERT mode
spelling = {
enabled = true, -- enabling this will show WhichKey when pressing z= to select spelling suggestions
suggestions = 20, -- how many suggestions should be shown in the list?
},
},
key_labels = {
-- override the label used to display some keys. It doesn't effect WK in any other way.
["<leader>"] = "SPC",
},
icons = {
breadcrumb = "»", -- symbol used in the command line area that shows your active key combo
separator = "", -- symbol used between a key and it's label
group = "+", -- symbol prepended to a group
},
popup_mappings = {
scroll_down = "<C-d>", -- binding to scroll down inside the popup
scroll_up = "<C-u>", -- binding to scroll up inside the popup
},
window = {
border = "rounded", -- none, single, double, shadow
position = "bottom", -- bottom, top
margin = { 1, 0, 1, 0 }, -- extra window margin [top, right, bottom, left]
padding = { 2, 2, 2, 2 }, -- extra window padding [top, right, bottom, left]
winblend = 0,
},
layout = {
height = { min = 4, max = 25 }, -- min and max height of the columns
width = { min = 20, max = 50 }, -- min and max width of the columns
spacing = 3, -- spacing between columns
align = "center", -- align columns left, center or right
},
},
config = function(_, opts)
local whichkey = require("which-key")
local utils = require("lazyvim.utils")
whichkey.setup(opts)
whichkey.setup(opts)
local leader_opts = {
mode = { "n", "v" }, -- NORMAL/VISUAL mode
buffer = nil, -- Global mappings
prefix = "<leader>",
silent = true, -- use 'silent'
noremap = true, -- use 'noremap'
nowait = true, -- use 'nowait'
}
local leader_opts = {
mode = { "n", "v" }, -- NORMAL/VISUAL mode
buffer = nil, -- Global mappings
prefix = "<leader>",
silent = true, -- use 'silent'
noremap = true, -- use 'noremap'
nowait = true, -- use 'nowait'
}
whichkey.register({
mode = { "n", "v" },
["g"] = { name = "+goto" },
["m"] = { name = "+harpoon" },
["]"] = { name = "+next" },
["["] = { name = "+previous" },
})
whichkey.register({
mode = { "n", "v" },
["g"] = { name = "+goto" },
["m"] = { name = "+harpoon" },
["]"] = { name = "+next" },
["["] = { name = "+previous" },
})
local leader_mappings = {
b = { name = "+buffer" },
r = { name = "+replace" },
s = { name = "+search" },
h = { name = "+help" },
gh = { name = "+hunks" },
t = { name = "+todo" },
N = { name = "+noice" },
local leader_mappings = {
b = { name = "+buffer" },
r = { name = "+replace" },
s = { name = "+search" },
h = { name = "+help" },
gh = { name = "+hunks" },
t = { name = "+todo" },
N = { name = "+noice" },
e = { "<cmd>NvimTreeToggle<cr>", "Explorer" },
Z = { "<cmd>ZenMode<cr>", "Zen" },
u = { "<cmd>UndotreeToggle<cr>", "Undo Tree" },
["'"] = { "<cmd>close<CR>", "Close split" },
Z = { "<cmd>ZenMode<cr>", "Zen" },
u = { "<cmd>UndotreeToggle<cr>", "Undo Tree" },
["'"] = { "<cmd>close<CR>", "Close split" },
n = {
name = "+neorg",
n = { "<cmd>Neorg<cr>", "Open Neorg" },
c = { "<cmd>Neorg toggle-concealer<cr>", "Toggle Concealer" },
t = { "<cmd>Neorg tangle current-file<cr>", "Tangle Current File" },
j = { "<cmd>Neorg journal<cr>", "Open Neorg Journal" },
w = {
function()
require("lazyvim.utils.neorg").workspace_switcher()
end,
"Workspace Switcher",
},
},
c = {
name = "+copilot",
c = { "<cmd>Copilot<cr>", "Start Copilot" },
},
f = {
name = "+file",
n = { "<cmd>enew<cr>", "New File" },
},
n = {
name = "+neorg",
n = { "<cmd>Neorg<cr>", "Open Neorg" },
c = { "<cmd>Neorg toggle-concealer<cr>", "Toggle Concealer" },
t = { "<cmd>Neorg tangle current-file<cr>", "Tangle Current File" },
j = { "<cmd>Neorg journal<cr>", "Open Neorg Journal" },
w = {
function()
require("lazyvim.utils.neorg").workspace_switcher()
end,
"Workspace Switcher",
},
},
q = {
name = "+quit",
q = { "<cmd>wq<CR>", "Save and Quit Current" },
a = { "<cmd>wqa<cr>", "Save and Quit all" },
},
f = {
name = "+file",
n = { "<cmd>enew<cr>", "New File" },
},
l = {
name = "+lsp",
l = { "<cmd>lopen<cr>", "Open Location List" },
q = { "<cmd>copen<cr>", "Open Quickfix List" },
},
q = {
name = "+quit",
q = { "<cmd>wq<CR>", "Save and Quit Current" },
a = { "<cmd>wqa<cr>", "Save and Quit all" },
},
c = {
name = "Compiler",
c = { "<cmd>w! | !compiler %<cr>", "Compile File" },
b = { "<cmd>w! | !pandoc % -t beamer -o presentation.pdf<cr>", "Beamer Presentation" },
p = { "<cmd>!opout %<cr><cr>", "Preview Document" },
},
l = {
name = "+lsp",
l = { "<cmd>lopen<cr>", "Open Location List" },
q = { "<cmd>copen<cr>", "Open Quickfix List" },
},
w = {
name = "+window",
w = { "<C-W>p", "Other window" },
d = { "<C-W>c", "Delete Window" },
h = { "<C-W>s", "Split Below" },
v = { "<C-W>v", "Split Right" },
},
C = {
name = "+compiler",
c = { "<cmd>w! | !compiler %<cr>", "Compile File" },
b = { "<cmd>w! | !pandoc % -t beamer -o presentation.pdf<cr>", "Beamer Presentation" },
p = { "<cmd>!opout %<cr><cr>", "Preview Document" },
},
o = {
name = "+option",
f = {
function()
require("lazyvim.plugins.lsp.format").toggle()
end,
"Toggle format on save",
},
s = {
function()
utils.toggle("spell")
end,
"Toggle spelling",
},
w = {
function()
utils.toggle("wrap")
end,
"Toggle word wrap",
},
n = {
function()
utils.toggle("relativenumber", true)
utils.toggle("number")
end,
"Toggle line numbers",
},
d = {
function()
utils.toggle_diagnostics()
end,
"Toggle Diagnostics",
},
c = {
function()
local conceallevel = vim.o.conceallevel > 0 and vim.o.conceallevel or 3
utils.toggle("conceallevel", false, { 0, conceallevel })
end,
"Toggle conceal",
},
h = {
function()
local sidescrolloff = vim.o.sidescrolloff > 0 and vim.o.sidescrolloff or 8
utils.toggle("sidescrolloff", false, { 0, sidescrolloff })
end,
"Toggle side scroll off",
},
},
w = {
name = "+window",
w = { "<C-W>p", "Other window" },
d = { "<C-W>c", "Delete Window" },
h = { "<C-W>s", "Split Below" },
v = { "<C-W>v", "Split Right" },
},
g = {
name = "+git",
g = {
function()
utils.float_term({ "lazygit" })
end,
"Lazygit (cwd)",
},
G = {
function()
utils.float_term({ "lazygit" }, { cwd = utils.get_root() })
end,
"Lazygit (root dir)",
},
},
o = {
name = "+option",
f = {
function()
require("lazyvim.plugins.lsp.format").toggle()
end,
"Toggle format on save",
},
s = {
function()
utils.toggle("spell")
end,
"Toggle spelling",
},
w = {
function()
utils.toggle("wrap")
end,
"Toggle word wrap",
},
n = {
function()
utils.toggle("relativenumber", true)
utils.toggle("number")
end,
"Toggle line numbers",
},
d = {
function()
utils.toggle_diagnostics()
end,
"Toggle Diagnostics",
},
c = {
function()
local conceallevel = vim.o.conceallevel > 0 and vim.o.conceallevel or 3
utils.toggle("conceallevel", false, { 0, conceallevel })
end,
"Toggle conceal",
},
h = {
function()
local sidescrolloff = vim.o.sidescrolloff > 0 and vim.o.sidescrolloff or 8
utils.toggle("sidescrolloff", false, { 0, sidescrolloff })
end,
"Toggle side scroll off",
},
},
z = {
name = "+zk",
I = { "<cmd>ZkIndex<cr>", "Index Notebook" },
n = {
"+new",
n = { "<cmd>ZkNew { title = vim.fn.input('Title: ') }<cr>", "New Note (zk dir)" },
N = {
"<cmd>ZkNew { dir = vim.fn.expand('%:p:h'), title = vim.fn.input('Title: ') }<cr>",
"New Note (cwd)",
},
t = {
"<cmd>ZkNewFromTitleSelection { title = vim.fn.input('Title: ') }<cr>",
"New, Title from selection (zk dir)",
},
T = {
"<cmd>ZkNewFromTitleSelection { dir = vim.fn.expand('%:p:h') title = vim.fn.input('Title: ') }<cr>",
"New, Title from selection (cwd)",
},
c = {
"<cmd>ZkNewFromContentSelection { title = vim.fn.input('Title: ') }<cr>",
"New, Content from selection (zk dir)",
},
C = {
"<cmd>ZkNewFromContentSelection { dir = vim.fn.expand('%:p:h') title = vim.fn.input('Title: ') }<cr>",
"New, Content from selection (cwd)",
},
},
c = { "<cmd>ZkCd<cr>", "cd 'root'" },
s = { "<cmd>ZkNotes<cr>", "List Notes" },
b = { "<cmd>ZkBacklinks<cr>", "Backlinks" },
l = { "<cmd>ZkLinks<cr>", "Links" },
j = {
"<cmd>ZkNew { dir = 'journal', date = 'today', title = vim.fn.input('Title: ') }<cr>",
"New Journal",
},
i = {
{ "<cmd>ZkInsertLink<cr>", "Insert Link" },
},
},
g = {
name = "+git",
g = {
function()
utils.float_term({ "lazygit" })
end,
"Lazygit (cwd)",
},
G = {
function()
utils.float_term({ "lazygit" }, { cwd = utils.get_root() })
end,
"Lazygit (root dir)",
},
},
-- TODO: Add dap back into the project, bashbunni's dotfiles are a good resource.
-- d = {
-- name = "Debug",
-- b = { "<cmd>lua require'dap'.toggle_breakpoint()<cr>", "Breakpoint" },
-- c = { "<cmd>lua require'dap'.continue()<cr>", "Continue" },
-- i = { "<cmd>lua require'dap'.step_into()<cr>", "Into" },
-- o = { "<cmd>lua require'dap'.step_over()<cr>", "Over" },
-- O = { "<cmd>lua require'dap'.step_out()<cr>", "Out" },
-- r = { "<cmd>lua require'dap'.repl.toggle()<cr>", "Repl" },
-- l = { "<cmd>lua require'dap'.run_last()<cr>", "Last" },
-- u = { "<cmd>lua require'dapui'.toggle()<cr>", "UI" },
-- x = { "<cmd>lua require'dap'.terminate()<cr>", "Exit" },
-- },
}
z = {
name = "+zk",
I = { "<cmd>ZkIndex<cr>", "Index Notebook" },
n = {
"+new",
n = { "<cmd>ZkNew { title = vim.fn.input('Title: ') }<cr>", "New Note (zk dir)" },
N = {
"<cmd>ZkNew { dir = vim.fn.expand('%:p:h'), title = vim.fn.input('Title: ') }<cr>",
"New Note (cwd)",
},
t = {
"<cmd>ZkNewFromTitleSelection { title = vim.fn.input('Title: ') }<cr>",
"New, Title from selection (zk dir)",
},
T = {
"<cmd>ZkNewFromTitleSelection { dir = vim.fn.expand('%:p:h') title = vim.fn.input('Title: ') }<cr>",
"New, Title from selection (cwd)",
},
c = {
"<cmd>ZkNewFromContentSelection { title = vim.fn.input('Title: ') }<cr>",
"New, Content from selection (zk dir)",
},
C = {
"<cmd>ZkNewFromContentSelection { dir = vim.fn.expand('%:p:h') title = vim.fn.input('Title: ') }<cr>",
"New, Content from selection (cwd)",
},
},
c = { "<cmd>ZkCd<cr>", "cd 'root'" },
s = { "<cmd>ZkNotes<cr>", "List Notes" },
b = { "<cmd>ZkBacklinks<cr>", "Backlinks" },
l = { "<cmd>ZkLinks<cr>", "Links" },
j = {
"<cmd>ZkNew { dir = 'journal', date = 'today', title = vim.fn.input('Title: ') }<cr>",
"New Journal",
},
i = {
{ "<cmd>ZkInsertLink<cr>", "Insert Link" },
},
},
whichkey.register(leader_mappings, leader_opts)
end,
},
-- TODO: Add dap back into the project, bashbunni's dotfiles are a good resource.
-- d = {
-- name = "Debug",
-- b = { "<cmd>lua require'dap'.toggle_breakpoint()<cr>", "Breakpoint" },
-- c = { "<cmd>lua require'dap'.continue()<cr>", "Continue" },
-- i = { "<cmd>lua require'dap'.step_into()<cr>", "Into" },
-- o = { "<cmd>lua require'dap'.step_over()<cr>", "Over" },
-- O = { "<cmd>lua require'dap'.step_out()<cr>", "Out" },
-- r = { "<cmd>lua require'dap'.repl.toggle()<cr>", "Repl" },
-- l = { "<cmd>lua require'dap'.run_last()<cr>", "Last" },
-- u = { "<cmd>lua require'dapui'.toggle()<cr>", "UI" },
-- x = { "<cmd>lua require'dap'.terminate()<cr>", "Exit" },
-- },
}
whichkey.register(leader_mappings, leader_opts)
end,
},
}

View File

@ -4,13 +4,13 @@ M.root_patterns = { ".git", "/lua" }
---@param on_attach fun(client, buffer)
function M.on_attach(on_attach)
vim.api.nvim_create_autocmd("LspAttach", {
callback = function(args)
local buffer = args.buf
local client = vim.lsp.get_client_by_id(args.data.client_id)
on_attach(client, buffer)
end,
})
vim.api.nvim_create_autocmd("LspAttach", {
callback = function(args)
local buffer = args.buf
local client = vim.lsp.get_client_by_id(args.data.client_id)
on_attach(client, buffer)
end,
})
end
-- returns the root directory based on:
@ -20,113 +20,125 @@ end
-- * root pattern of cwd
---@return string
function M.get_root()
---@type string?
local path = vim.api.nvim_buf_get_name(0)
path = path ~= "" and vim.loop.fs_realpath(path) or nil
---@type string[]
local roots = {}
if path then
for _, client in pairs(vim.lsp.get_active_clients({ bufnr = 0 })) do
local workspace = client.config.workspace_folders
local paths = workspace
and vim.tbl_map(function(ws)
return vim.uri_to_fname(ws.uri)
end, workspace)
or client.config.root_dir and { client.config.root_dir }
or {}
for _, p in ipairs(paths) do
local r = vim.loop.fs_realpath(p)
if path:find(r, 1, true) then
roots[#roots + 1] = r
end
end
end
end
table.sort(roots, function(a, b)
return #a > #b
end)
---@type string?
local root = roots[1]
if not root then
path = path and vim.fs.dirname(path) or vim.loop.cwd()
---@type string?
root = vim.fs.find(M.root_patterns, { path = path, upward = true })[1]
root = root and vim.fs.dirname(root) or vim.loop.cwd()
end
---@cast root string
return root
---@type string?
local path = vim.api.nvim_buf_get_name(0)
path = path ~= "" and vim.loop.fs_realpath(path) or nil
---@type string[]
local roots = {}
if path then
for _, client in pairs(vim.lsp.get_active_clients({ bufnr = 0 })) do
local workspace = client.config.workspace_folders
local paths = workspace
and vim.tbl_map(function(ws)
return vim.uri_to_fname(ws.uri)
end, workspace)
or client.config.root_dir and { client.config.root_dir }
or {}
for _, p in ipairs(paths) do
local r = vim.loop.fs_realpath(p)
if path:find(r, 1, true) then
roots[#roots + 1] = r
end
end
end
end
table.sort(roots, function(a, b)
return #a > #b
end)
---@type string?
local root = roots[1]
if not root then
path = path and vim.fs.dirname(path) or vim.loop.cwd()
---@type string?
root = vim.fs.find(M.root_patterns, { path = path, upward = true })[1]
root = root and vim.fs.dirname(root) or vim.loop.cwd()
end
---@cast root string
return root
end
---@param silent boolean?
---@param values? {[1]:any, [2]:any}function
function M.toggle(option, silent, values)
if values then
if vim.opt_local[option]:get() == values[1] then
vim.opt_local[option] = values[2]
else
vim.opt_local[option] = values[1]
end
return vim.notify(
"Set " .. option .. " to " .. vim.opt_local[option]:get(),
vim.log.levels.INFO,
{ title = "Option" }
)
end
vim.opt_local[option] = not vim.opt_local[option]:get()
if not silent then
vim.notify(
(vim.opt_local[option]:get() and "Enabled" or "Disabled") .. " " .. option,
vim.log.levels.INFO,
{ title = "Option" }
)
end
if values then
if vim.opt_local[option]:get() == values[1] then
vim.opt_local[option] = values[2]
else
vim.opt_local[option] = values[1]
end
return vim.notify(
"Set " .. option .. " to " .. vim.opt_local[option]:get(),
vim.log.levels.INFO,
{ title = "Option" }
)
end
vim.opt_local[option] = not vim.opt_local[option]:get()
if not silent then
vim.notify(
(vim.opt_local[option]:get() and "Enabled" or "Disabled") .. " " .. option,
vim.log.levels.INFO,
{ title = "Option" }
)
end
end
local enabled = true
function M.toggle_diagnostics()
enabled = not enabled
if enabled then
vim.diagnostic.enable()
vim.notify("Enabled diagnostics", vim.log.levels.INFO, { title = "Diagnostics" })
else
vim.diagnostic.disable()
vim.notify("Disabled diagnostics", vim.log.levels.INFO, { title = "Diagnostics" })
end
enabled = not enabled
if enabled then
vim.diagnostic.enable()
vim.notify("Enabled diagnostics", vim.log.levels.INFO, { title = "Diagnostics" })
else
vim.diagnostic.disable()
vim.notify("Disabled diagnostics", vim.log.levels.INFO, { title = "Diagnostics" })
end
end
function M.smart_quit()
local bufnr = vim.api.nvim_get_current_buf()
local modified = vim.api.nvim_buf_get_option(bufnr, "modified")
if modified then
vim.ui.input({
prompt = "You have unsaved changes. Quit anyway? (y/n) ",
}, function(input)
if input == "y" then
vim.cmd("q!")
end
end)
else
vim.cmd("q!")
end
local bufnr = vim.api.nvim_get_current_buf()
local modified = vim.api.nvim_buf_get_option(bufnr, "modified")
if modified then
vim.ui.input({
prompt = "You have unsaved changes. Quit anyway? (y/n) ",
}, function(input)
if input == "y" then
vim.cmd("q!")
end
end)
else
vim.cmd("q!")
end
end
function M.isempty(s)
return s == nil or s == ""
return s == nil or s == ""
end
function M.get_buf_option(opt)
local status_ok, buf_option = pcall(vim.api.nvim_buf_get_option, 0, opt)
if not status_ok then
return nil
else
return buf_option
end
local status_ok, buf_option = pcall(vim.api.nvim_buf_get_option, 0, opt)
if not status_ok then
return nil
else
return buf_option
end
end
function M.telescope(builtin, opts)
return function()
require("telescope.builtin")[builtin](vim.tbl_deep_extend("force", { cwd = M.get_root() }, opts or {}))
end
return function()
require("telescope.builtin")[builtin](vim.tbl_deep_extend("force", { cwd = M.get_root() }, opts or {}))
end
end
-- This might not be best, but it allows for easy resetting
function M.setColorscheme(scheme)
local colorscheme = scheme or "gruvbox-material"
local okay, _ = pcall(vim.cmd, "colorscheme " .. colorscheme)
if not okay then
vim.notify("Colorscheme " .. colorscheme .. " not found!")
vim.cmd("colorsheme habamax")
end
end
return M