From 61d7120fa819fbed5fc3d26aa58df8f20c03783a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Lukas=20H=C3=A4gele?= Date: Sun, 4 Jan 2026 17:22:25 +0100 Subject: [PATCH] move to lazy and remove unused stuff --- after/ftplugin/lua.lua | 4 +++ init.lua | 6 +++- lazy-lock.json | 14 ++++++++ lua/config/autocommands.lua | 30 ++++++++++++++++ lua/config/keymap.lua | 17 +++++++++ lua/config/lazy.lua | 32 +++++++++++++++++ lua/config/plugins/completion.lua | 19 ++++++++++ lua/config/plugins/hop.lua | 30 ++++++++++++++++ lua/config/plugins/lsp.lua | 48 +++++++++++++++++++++++++ lua/config/plugins/mini.lua | 11 ++++++ lua/config/plugins/telescope.lua | 40 +++++++++++++++++++++ lua/config/plugins/treesitter.lua | 29 +++++++++++++++ lua/config/settings.lua | 30 ++++++++++++++++ lua/config/telescope/multigrep.lua | 53 +++++++++++++++++++++++++++ plugin/floaterminal.lua | 58 ++++++++++++++++++++++++++++++ 15 files changed, 420 insertions(+), 1 deletion(-) create mode 100644 after/ftplugin/lua.lua create mode 100644 lazy-lock.json create mode 100644 lua/config/autocommands.lua create mode 100644 lua/config/keymap.lua create mode 100644 lua/config/lazy.lua create mode 100644 lua/config/plugins/completion.lua create mode 100644 lua/config/plugins/hop.lua create mode 100644 lua/config/plugins/lsp.lua create mode 100644 lua/config/plugins/mini.lua create mode 100644 lua/config/plugins/telescope.lua create mode 100644 lua/config/plugins/treesitter.lua create mode 100644 lua/config/settings.lua create mode 100644 lua/config/telescope/multigrep.lua create mode 100644 plugin/floaterminal.lua diff --git a/after/ftplugin/lua.lua b/after/ftplugin/lua.lua new file mode 100644 index 0000000..0e82a81 --- /dev/null +++ b/after/ftplugin/lua.lua @@ -0,0 +1,4 @@ +local set = vim.opt_local + +set.shiftwidth = 2 +set.number = true diff --git a/init.lua b/init.lua index d94e335..703f978 100644 --- a/init.lua +++ b/init.lua @@ -1,2 +1,6 @@ -require("lukas") +require("config.lazy") + +require("config.autocommands") +require("config.keymap") +require("config.settings") diff --git a/lazy-lock.json b/lazy-lock.json new file mode 100644 index 0000000..4ad1110 --- /dev/null +++ b/lazy-lock.json @@ -0,0 +1,14 @@ +{ + "blink.cmp": { "branch": "main", "commit": "485c03400608cb6534bbf84da8c1c471fc4808c0" }, + "friendly-snippets": { "branch": "main", "commit": "572f5660cf05f8cd8834e096d7b4c921ba18e175" }, + "hop.nvim": { "branch": "master", "commit": "08ddca799089ab96a6d1763db0b8adc5320bf050" }, + "lazy.nvim": { "branch": "main", "commit": "306a05526ada86a7b30af95c5cc81ffba93fef97" }, + "lazydev.nvim": { "branch": "main", "commit": "5231c62aa83c2f8dc8e7ba957aa77098cda1257d" }, + "mini.nvim": { "branch": "main", "commit": "5d8d141cb113e9d235c9215475b26b0d20612150" }, + "nvim-lspconfig": { "branch": "master", "commit": "ac04ec3c2af08e9821b4eb64ede86072b9b213bf" }, + "nvim-treesitter": { "branch": "master", "commit": "42fc28ba918343ebfd5565147a42a26580579482" }, + "plenary.nvim": { "branch": "master", "commit": "b9fd5226c2f76c951fc8ed5923d85e4de065e509" }, + "telescope-fzf-native.nvim": { "branch": "main", "commit": "6fea601bd2b694c6f2ae08a6c6fab14930c60e2c" }, + "telescope.nvim": { "branch": "master", "commit": "a0bbec21143c7bc5f8bb02e0005fa0b982edc026" }, + "tokyonight.nvim": { "branch": "main", "commit": "5da1b76e64daf4c5d410f06bcb6b9cb640da7dfd" } +} diff --git a/lua/config/autocommands.lua b/lua/config/autocommands.lua new file mode 100644 index 0000000..7dcbe9e --- /dev/null +++ b/lua/config/autocommands.lua @@ -0,0 +1,30 @@ +-- remove trailing whitespace on save +vim.api.nvim_create_autocmd({ "BufWritePre" }, { + pattern = { "*" }, + command = [[%s/\s\+$//e]], +}) + +-- highlight when yanking text +vim.api.nvim_create_autocmd('TextYankPost', { + desc = 'highlight when yanking text', + group = vim.api.nvim_create_augroup('highlight-yank', { clear = true }), + callback = function() + vim.highlight.on_yank() + end, +}) + +-- integrated terminal stuff +vim.api.nvim_create_autocmd('TermOpen', { + group = vim.api.nvim_create_augroup('custom-term-open', { clear = true }), + callback = function() + vim.opt.number = false + vim.opt.relativenumber = false + end, +}) +vim.keymap.set("n", "st", function() + vim.cmd.vnew() + vim.cmd.term() + vim.cmd.wincmd("J") + vim.api.nvim_win_set_height(0, 15) +end) + diff --git a/lua/config/keymap.lua b/lua/config/keymap.lua new file mode 100644 index 0000000..a32b6dd --- /dev/null +++ b/lua/config/keymap.lua @@ -0,0 +1,17 @@ + +-- shortcut escape in insert mode +vim.keymap.set('i', 'jj', '') + +-- move highlighted lines +vim.keymap.set("v", "J", ":m '>+1gv=gv") +vim.keymap.set("v", "K", ":m '<-2gv=gv") + +-- execute lua code +vim.keymap.set("n", "x", "source % ") +vim.keymap.set("n", "x", ":.lua") +vim.keymap.set("v", "x", ":lua") + +-- quickfix commands +vim.keymap.set("n", "", "cnext") +vim.keymap.set("n", "", "cprev") + diff --git a/lua/config/lazy.lua b/lua/config/lazy.lua new file mode 100644 index 0000000..b949579 --- /dev/null +++ b/lua/config/lazy.lua @@ -0,0 +1,32 @@ +-- 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 +-- put lazy in the runtimepath for neovim +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 = { + { "folke/tokyonight.nvim", config = function() vim.cmd.colorscheme "tokyonight" end }, + { import = "config.plugins" }, + } +}) + diff --git a/lua/config/plugins/completion.lua b/lua/config/plugins/completion.lua new file mode 100644 index 0000000..3f2e98b --- /dev/null +++ b/lua/config/plugins/completion.lua @@ -0,0 +1,19 @@ +return { + { + 'saghen/blink.cmp', + dependencies = 'rafamadriz/friendly-snippets', + + version = 'v0.*', + + opts = { + keymap = { preset = 'default' }, + + appearance = { + use_nvim_cmp_as_default = true, + nerd_font_variant = 'mono' + }, + + signature = { enabled = true } + }, + }, +} diff --git a/lua/config/plugins/hop.lua b/lua/config/plugins/hop.lua new file mode 100644 index 0000000..a4b4482 --- /dev/null +++ b/lua/config/plugins/hop.lua @@ -0,0 +1,30 @@ +return { + 'smoka7/hop.nvim', + version = "*", + opts = { + keys = 'etovxqpdygfblzhckisuran' + }, + config = function() + local hop = require('hop') + local directions = require('hop.hint').HintDirection + + hop.setup() + + vim.keymap.set('n', 'j', function() + hop.hint_lines({ direction = directions.AFTER_CURSOR }) + end, {remap=true}) + + vim.keymap.set('n', 'k', function() + hop.hint_lines({ direction = directions.BEFORE_CURSOR }) + end, {remap=true}) + + vim.keymap.set('n', 'f', function() + hop.hint_char1({ direction = directions.AFTER_CURSOR, current_line_only = true }) + end, {remap=true}) + + vim.keymap.set('n', 'F', function() + hop.hint_char1({ direction = directions.BEFORE_CURSOR, current_line_only = true }) + end, {remap=true}) + end +} + diff --git a/lua/config/plugins/lsp.lua b/lua/config/plugins/lsp.lua new file mode 100644 index 0000000..8ce76f5 --- /dev/null +++ b/lua/config/plugins/lsp.lua @@ -0,0 +1,48 @@ +return { + { + "neovim/nvim-lspconfig", + + dependencies = { + "folke/lazydev.nvim", + ft = "lua", -- only load on lua files + opts = { + library = { + -- load luvit types when the `vim.uv` word is found + { path = "${3rd}/luv/library", words = { "vim%.uv" } }, + } + }, + }, + + config = function() + -- Use LspAttach autocommand to only map the following keys + -- after the language server attaches to the current buffer + vim.api.nvim_create_autocmd("LspAttach", { + callback = function(args) + local bufnr = args.buf + local client = assert(vim.lsp.get_client_by_id(args.data.client_id), "must have valid client") + + local builtin = require "telescope.builtin" + + -- Enable completion triggered by + vim.opt_local.omnifunc = "v:lua.vim.lsp.omnifunc" + vim.keymap.set("n", "gd", vim.lsp.buf.definition, { buffer = 0 }) + vim.keymap.set("n", "gr", builtin.lsp_references, { buffer = 0 }) + vim.keymap.set("n", "gf", vim.lsp.buf.declaration, { buffer = 0 }) + -- vim.keymap.set("n", "gT", vim.lsp.buf.type_definition, { buffer = 0 }) + vim.keymap.set("n", "gh", vim.lsp.buf.hover, { buffer = 0 }) + + vim.keymap.set("n", "cr", vim.lsp.buf.rename, { buffer = 0 }) + -- vim.keymap.set("n", "ca", vim.lsp.buf.code_action, { buffer = 0 }) + vim.keymap.set("n", "wd", builtin.lsp_document_symbols, { buffer = 0 }) + vim.keymap.set("n", "ww", function() + builtin.diagnostics { root_dir = true } + end, { buffer = 0 }) + end + }) + + local capabilities = require('blink.cmp').get_lsp_capabilities() + require("lspconfig").lua_ls.setup { capabilities = capabilities } + require("lspconfig").clangd.setup { capabilities = capabilities } + end, + } +} diff --git a/lua/config/plugins/mini.lua b/lua/config/plugins/mini.lua new file mode 100644 index 0000000..6327670 --- /dev/null +++ b/lua/config/plugins/mini.lua @@ -0,0 +1,11 @@ +return { + { + 'echasnovski/mini.nvim', + enabled = true, + config = function() + local statusline = require 'mini.statusline' + statusline.setup { use_icons = true } + end + } +} + diff --git a/lua/config/plugins/telescope.lua b/lua/config/plugins/telescope.lua new file mode 100644 index 0000000..63addde --- /dev/null +++ b/lua/config/plugins/telescope.lua @@ -0,0 +1,40 @@ +return { + 'nvim-telescope/telescope.nvim', + tag = '0.1.8', + dependencies = { + 'nvim-lua/plenary.nvim', + { 'nvim-telescope/telescope-fzf-native.nvim', build = 'make' } + }, + config = function() + require('telescope').setup { + pickers = { + find_files = { + theme = "ivy" + } + }, + extensions = { + fzf = {} + } + } + + require('telescope').load_extension('fzf') + + vim.keymap.set("n", "fh", require('telescope.builtin').help_tags) + vim.keymap.set("n", "fp", require('telescope.builtin').find_files) + vim.keymap.set("n", "fc", function() + require('telescope.builtin').find_files { + cwd = vim.fn.stdpath("config") + } + end) + + vim.keymap.set("n", "fl", function() + require('telescope.builtin').find_files { + cwd = vim.fn.stdpath("data") .. "/lazy" + } + end) + + require('config.telescope.multigrep').setup() + + end +} + diff --git a/lua/config/plugins/treesitter.lua b/lua/config/plugins/treesitter.lua new file mode 100644 index 0000000..8f18b8d --- /dev/null +++ b/lua/config/plugins/treesitter.lua @@ -0,0 +1,29 @@ +return { + { + "nvim-treesitter/nvim-treesitter", + branch = 'master', + lazy = false, + build = ":TSUpdate", + config = function() + require'nvim-treesitter.configs'.setup { + -- A list of parser names, or "all" (the listed parsers MUST always be installed) + ensure_installed = { "c", "lua", "vim", "vimdoc", "query", "markdown", "markdown_inline" }, + auto_install = false, + ignore_install = { "javascript" }, + highlight = { + enable = true, + -- disable slow treesitter highlight for large files + disable = function(lang, buf) + local max_filesize = 100 * 1024 -- 100 KB + local ok, stats = pcall(vim.loop.fs_stat, vim.api.nvim_buf_get_name(buf)) + if ok and stats and stats.size > max_filesize then + return true + end + end, + additional_vim_regex_highlighting = false, + }, + } + end + } +} + diff --git a/lua/config/settings.lua b/lua/config/settings.lua new file mode 100644 index 0000000..fca1268 --- /dev/null +++ b/lua/config/settings.lua @@ -0,0 +1,30 @@ +vim.opt.clipboard = "unnamedplus" + +vim.opt.tabstop = 4 +vim.opt.softtabstop = 4 +vim.opt.shiftwidth = 4 +vim.opt.expandtab = true + +vim.opt.smartindent = true + +vim.opt.wrap = false + +vim.opt.swapfile = false +vim.opt.backup = false + +vim.opt.undofile = true + +vim.opt.hlsearch = false +vim.opt.incsearch = true +vim.opt.ignorecase = true +vim.opt.smartcase = true + +-- vim.opt.termguicolors = false + +vim.opt.scrolloff = 8 +vim.opt.signcolumn = "yes" +vim.opt.isfname:append("@-@") + +vim.opt.updatetime = 50 + +-- vim.opt.colorcolumn = "80" diff --git a/lua/config/telescope/multigrep.lua b/lua/config/telescope/multigrep.lua new file mode 100644 index 0000000..1064fe6 --- /dev/null +++ b/lua/config/telescope/multigrep.lua @@ -0,0 +1,53 @@ +local pickers = require("telescope.pickers") +local finders = require("telescope.finders") +local make_entry = require("telescope.make_entry") +local conf = require("telescope.config").values + +local M = {} + +local live_multigrep = function(opts) + opts = opts or {} + opts.cwd = opts.cwd or vim.uv.cwd() + + local finder = finders.new_async_job { + command_generator = function(prompt) + if not prompt or prompt == "" then + return nil + end + + local pieces = vim.split(prompt, " ") + local args = { "rg" } + + if pieces[1] then + table.insert(args, "-e") + table.insert(args, pieces[1]) + end + + if pieces[2] then + table.insert(args, "-g") + table.insert(args, pieces[2]) + end + + return vim.tbl_flatten { + args, + { "--color=never", "--no-heading", "--with-filename", "--line-number", "--column", "--smart-case" }, + } + end, + entry_maker = make_entry.gen_from_vimgrep(opts), + cwd = opts.cwd, + } + + pickers.new(opts, { + debounce = 100, + pompt_title = "multigrep", + finder = finder, + previewer = conf.grep_previewer(opts), + sorder = require("telescope.sorters").empty() + }):find() +end + +M.setup = function() + vim.keymap.set("n", "fg", live_multigrep) +end + +return M diff --git a/plugin/floaterminal.lua b/plugin/floaterminal.lua new file mode 100644 index 0000000..703324f --- /dev/null +++ b/plugin/floaterminal.lua @@ -0,0 +1,58 @@ +vim.keymap.set("t", "", "") + +local state = { + floating = { + buf = -1, + win = -1, + } +} + +local function create_floating_window(opts) + opts = opts or {} + local width = opts.width or math.floor(vim.o.columns * 0.8) + local height = opts.height or math.floor(vim.o.lines * 0.8) + + -- Calculate the position to center the window + local col = math.floor((vim.o.columns - width) / 2) + local row = math.floor((vim.o.lines - height) / 2) + + -- Create a buffer + local buf = nil + if vim.api.nvim_buf_is_valid(opts.buf) then + buf = opts.buf + else + buf = vim.api.nvim_create_buf(false, true) -- No file, scratch buffer + end + + -- Define window configuration + local win_config = { + relative = "editor", + width = width, + height = height, + col = col, + row = row, + style = "minimal", -- No borders or extra UI elements + border = "rounded", + } + + -- Create the floating window + local win = vim.api.nvim_open_win(buf, true, win_config) + + return { buf = buf, win = win } +end + +local toggle_terminal = function() + if not vim.api.nvim_win_is_valid(state.floating.win) then + state.floating = create_floating_window { buf = state.floating.buf } + if vim.bo[state.floating.buf].buftype ~= "terminal" then + vim.cmd.terminal() + end + else + vim.api.nvim_win_hide(state.floating.win) + end +end + +-- Example usage: +-- Create a floating window with default dimensions +vim.api.nvim_create_user_command("Floaterminal", toggle_terminal, {}) +vim.keymap.set({ "n", "t" }, "tt", toggle_terminal) -- 2.39.5