Revamped config

This commit is contained in:
2024-03-22 18:14:16 +01:00
parent 4ee74dddf2
commit 980e542a2c
9 changed files with 103 additions and 93 deletions

34
lua/taken/utils/maps.lua Normal file
View File

@@ -0,0 +1,34 @@
local M = {}
local set = vim.keymap.set
function M.setmap(maps)
local v = maps.v or {}
local n = maps.n or {}
local vn = maps.vn or {}
for map, command in pairs(v) do
if command.desc then
set("v", map, command[1], { desc = command.desc, silent = true })
else
set("v", map, command[1], { silent = true })
end
end
for map, command in pairs(n) do
if command.desc then
set("n", map, command[1], { desc = command.desc, silent = true })
else
set("n", map, command[1], { silent = true })
end
end
for map, command in pairs(vn) do
if command.desc then
set({ "v", "n" }, map, command[1], { desc = command.desc, silent = true })
else
set({ "v", "n" }, map, command[1], { silent = true })
end
end
end
return M

19
lua/taken/utils/mkdir.lua Normal file
View File

@@ -0,0 +1,19 @@
-- code by https://github.com/jghauser/mkdir.nvim
local fn = vim.fn
local M = {}
function M.run()
local dir = fn.expand('<afile>:p:h')
if dir:find('%l+://') == 1 then
return
end
if fn.isdirectory(dir) == 0 then
fn.mkdir(dir, 'p')
end
end
return M

View File

@@ -0,0 +1,35 @@
local on_attach = function(client, bufnr)
local opts = { noremap = true, silent = true, buffer = bufnr }
vim.keymap.set("n", "gd", "<cmd>Telescope lsp_definitions<CR>", opts)
vim.keymap.set("n", "gD", vim.lsp.buf.declaration, opts)
vim.keymap.set("n", "gi", "<cmd>Telescope lsp_implementations<CR>", opts)
vim.keymap.set("n", "gt", "<cmd>Telescope lsp_type_definitions<CR>", opts)
vim.keymap.set("n", "<leader>rn", vim.lsp.buf.rename, opts)
vim.keymap.set("n", "K", function()
vim.lsp.buf.hover()
end, opts)
vim.keymap.set("n", "<leader>vws", function()
vim.lsp.buf.workspace_symbol()
end, opts)
vim.keymap.set("n", "<leader>vd", function()
vim.diagnostic.open_float()
end, opts)
vim.keymap.set("n", "[d", function()
vim.diagnostic.goto_next()
end, opts)
vim.keymap.set("n", "]d", function()
vim.diagnostic.goto_prev()
end, opts)
vim.keymap.set("n", "<leader>vca", function()
vim.lsp.buf.code_action()
end, opts)
vim.keymap.set("n", "gR", "<cmd>Telescope lsp_references<CR>", opts)
vim.keymap.set("n", "<leader>vrn", function()
vim.lsp.buf.rename()
end, opts)
vim.keymap.set("i", "<C-h>", function()
vim.lsp.buf.signature_help()
end, opts)
end
return on_attach

View File

@@ -0,0 +1,64 @@
local M = {}
function M.themeselector()
vim.api.nvim_exec_autocmds("User", { pattern = "ThemeSwitcher", modeline = false })
local configDir = vim.fn.stdpath("config")
local prefsFile = configDir .. "/lua/taken/prefs.lua"
local oldstring = 'M.colorscheme = .*"'
local colors = vim.fn.globpath(vim.o.rtp, "colors/*", 1, 1)
local dataDir = vim.fn.stdpath("data")
local newpath = string.gsub(dataDir, "%-", "%%-")
local themes = {}
for i, v in ipairs(colors) do
if string.find(v, "lazy") then
local filename = ""
if vim.loop.os_uname().sysname == "Windows_NT" then
filename = string.gsub(v, newpath .. "\\lazy\\.*\\", "")
else
filename = string.gsub(v, newpath .. "/lazy/.*/", "")
end
local themename = string.gsub(filename, ".vim", "")
local themename2 = string.gsub(themename, ".lua", "")
table.insert(themes, themename2)
end
end
local opts = {
prompt = "Select a theme",
}
local function change_theme(old, new)
-- function from nvchad
local file = io.open(prefsFile, "r")
local added_pattern = string.gsub(old, "-", "%%-")
local new_content = file:read("*all"):gsub(added_pattern, new)
file = io.open(prefsFile, "w")
file:write(new_content)
file:close()
end
local exec = function(choice)
if choice == nil then
vim.notify("No theme selected!", 4)
return
end
vim.cmd("colorscheme " .. choice)
local newstring = 'M.colorscheme = "' .. choice .. '"'
change_theme(oldstring, newstring)
local cursorcolumncolor = vim.fn.synIDattr(vim.fn.hlID("CursorColumn"), "bg")
if cursorcolumncolor ~= "" then
vim.cmd("hi CursorLine guibg=" .. cursorcolumncolor)
end
end
vim.ui.select(themes, opts, exec)
end
return M