From 102f9a5608cbb7b5553cd0d1862b6bd8e40c8075 Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 11 May 2025 00:43:32 +0200 Subject: refractored neovim config --- nvim/lua/codev.lua | 11 -- nvim/lua/configs.lua | 285 +++++++++++++++++++++++++++++++++++ nvim/lua/core/autocmds.lua | 98 +++++++++++++ nvim/lua/core/keymaps.lua | 113 ++++++++++++++ nvim/lua/core/options.lua | 37 +++++ nvim/lua/keybindings.lua | 162 -------------------- nvim/lua/options.lua | 43 ------ nvim/lua/plugins.lua | 359 ++++++++++++++++++++------------------------- 8 files changed, 689 insertions(+), 419 deletions(-) delete mode 100644 nvim/lua/codev.lua create mode 100644 nvim/lua/configs.lua create mode 100644 nvim/lua/core/autocmds.lua create mode 100644 nvim/lua/core/keymaps.lua create mode 100644 nvim/lua/core/options.lua delete mode 100644 nvim/lua/keybindings.lua delete mode 100644 nvim/lua/options.lua (limited to 'nvim/lua') diff --git a/nvim/lua/codev.lua b/nvim/lua/codev.lua deleted file mode 100644 index ed6c330..0000000 --- a/nvim/lua/codev.lua +++ /dev/null @@ -1,11 +0,0 @@ -vim.api.nvim_exec2([[ - augroup SeqFileType - autocmd! - autocmd BufRead,BufNewFile *.seq set filetype=seq - autocmd BufRead,BufNewFile *.seq set syntax=codev - autocmd BufRead,BufNewFile *.lis set filetype=lis - autocmd BufRead,BufNewFile *.lis set syntax=codelis - augroup END -]], {}) - -vim.api.nvim_exec2([[autocmd FileType seq set commentstring=!%s]], {}) diff --git a/nvim/lua/configs.lua b/nvim/lua/configs.lua new file mode 100644 index 0000000..92d26f7 --- /dev/null +++ b/nvim/lua/configs.lua @@ -0,0 +1,285 @@ +-- Plugin configurations +-- All plugin-specific settings are configured here + +-------------------------------- +-- TELESCOPE +-------------------------------- +local function setup_telescope() + local actions = require("telescope.actions") + + -- Function to open selected file in external program + local function open_in_external_program(prompt_bufnr) + local entry = require('telescope.actions.state').get_selected_entry() + local file_path = entry.path or entry.filename + if file_path then + os.execute(string.format('start "" "%s"', file_path)) + else + print("No file selected") + end + actions.close(prompt_bufnr) + end + + require('telescope').setup({ + defaults = { + layout_config = { + vertical = { width = 0.5 } + }, + mappings = { + n = { + ["q"] = actions.close, + ["o"] = open_in_external_program, + }, + i = { + [""] = actions.close, + [""] = actions.cycle_history_next, + [""] = actions.cycle_history_prev, + [""] = actions.move_selection_next, + [""] = actions.move_selection_previous, + [""] = open_in_external_program, + } + }, + }, + pickers = { + live_grep = { + file_ignore_patterns = { 'node_modules', '.git', '.venv' }, + additional_args = function(_) + return { "--hidden" } + end + }, + find_files = { + file_ignore_patterns = { 'node_modules', '.git', '.venv' }, + hidden = true + } + } + }) +end + +-------------------------------- +-- HARPOON +-------------------------------- +local function setup_harpoon() + local harpoon = require("harpoon") + + -- Initialize harpoon + harpoon:setup({ + settings = { + save_on_toggle = true, + sync_on_ui_close = true, + } + }) +end + +-------------------------------- +-- OIL +-------------------------------- +local function setup_oil() + require("oil").setup({ + -- Default file explorer settings + default_file_explorer = true, + + -- Columns to display + columns = { "icon" }, + + -- Buffer options + buf_options = { + buflisted = false, + bufhidden = "hide", + }, + + -- Window options + win_options = { + wrap = false, + signcolumn = "no", + cursorcolumn = false, + foldcolumn = "0", + spell = false, + list = false, + conceallevel = 3, + concealcursor = "nvic", + }, + + -- File operations + delete_to_trash = true, + skip_confirm_for_simple_edits = false, + prompt_save_on_select_new_entry = true, + cleanup_delay_ms = 2000, + + -- UI behavior + constrain_cursor = "editable", + watch_for_changes = false, + + -- Custom keymaps + keymaps = { + ["g?"] = "actions.show_help", + [""] = "actions.select", + [""] = { "actions.select", opts = { vertical = true } }, + [""] = { "actions.select", opts = { horizontal = true } }, + [""] = "actions.preview", + [""] = "actions.close", + [""] = "actions.refresh", + ["-"] = "actions.parent", + ["_"] = "actions.open_cwd", + ["`"] = "actions.cd", + ["~"] = { "actions.cd", opts = { scope = "tab" } }, + ["gs"] = "actions.change_sort", + [""] = "actions.open_external", + ["g."] = "actions.toggle_hidden", + ["g\\"] = "actions.toggle_trash", + ['yp'] = { + desc = 'Copy filepath to system clipboard', + callback = function () + require('oil.actions').copy_entry_path.callback() + vim.fn.setreg("+", vim.fn.getreg(vim.v.register)) + end, + }, + }, + + -- Disable default keymaps + use_default_keymaps = false, + + -- View options + view_options = { + show_hidden = false, + natural_order = true, + case_insensitive = false, + sort = { + { "type", "asc" }, + { "name", "asc" }, + }, + }, + + -- Preview window settings + preview = { + max_width = 0.9, + min_width = { 40, 0.4 }, + max_height = 0.9, + min_height = { 5, 0.1 }, + border = "rounded", + win_options = { winblend = 0 }, + }, + + -- Floating window settings + float = { + padding = 2, + max_width = 0, + max_height = 0, + border = "rounded", + win_options = { winblend = 0 }, + }, + }) +end + +-------------------------------- +-- TOGGLETERM +-------------------------------- +local function setup_toggleterm() + require("toggleterm").setup({ + -- Shell to use in the terminal + shell = "pwsh.exe -NoLogo", + + -- Display options + direction = "float", + float_opts = { + border = "rounded", + }, + + -- Window appearance + winbar = { + enabled = false + }, + + -- Behavior + start_in_insert = true, + close_on_exit = true, + + -- Integration with tmux + persist_size = true, + persist_mode = true, + }) +end + +-------------------------------- +-- TREESITTER +-------------------------------- +local function setup_treesitter() + require('nvim-treesitter.configs').setup({ + ensure_installed = { "c", "lua", "vim", "vimdoc", "cpp", "python" }, + sync_install = false, + auto_install = false, + highlight = { enable = true }, + indent = { enable = true }, + }) +end + +-------------------------------- +-- COMMENTS +-------------------------------- +local function setup_comments() + require('Comment').setup({ + padding = true, + sticky = true, + ignore = nil, + toggler = { + line = '/', + block = 'gbc', + }, + opleader = { + line = '/', + block = 'gb', + } + }) +end + +-------------------------------- +-- LSP Configuration +-------------------------------- +local function setup_lsp() + -- Configure Mason LSP installer/manager + require('mason').setup({ + ensure_installed = { + 'lua_ls', -- Lua + 'clangd', -- C/C++ + 'pyright', -- Python + 'marksman', -- Markdown + }, + handlers = { + -- Lua LSP settings + lua_ls = function() + require('lspconfig').lua_ls.setup({}) + end, + + -- C/C++ LSP settings (clangd) + clangd = function() + require('lspconfig').clangd.setup({}) + end, + + -- Markdown LSP settings + marksman = function() + require('lspconfig').marksman.setup({}) + end, + } + }) + require("mason-lspconfig").setup {} + + -- Configure diagnostics appearance + vim.diagnostic.config({ + virtual_lines=true, + signs = true, + underline = true, + update_in_insert = false, + severity_sort = true, + }) +end + +-------------------------------- +-- INITIALIZE ALL CONFIGS +-------------------------------- + +-- Set up all plugin configurations +setup_telescope() +setup_harpoon() +setup_oil() +setup_toggleterm() +setup_treesitter() +setup_comments() +setup_lsp() diff --git a/nvim/lua/core/autocmds.lua b/nvim/lua/core/autocmds.lua new file mode 100644 index 0000000..898aeb7 --- /dev/null +++ b/nvim/lua/core/autocmds.lua @@ -0,0 +1,98 @@ +-- Core autocommands +-- Centralized place for all autocommands + +-------------------------------- +-- FILE DETECTION & RELOADING +-------------------------------- + +-- Auto-reload files when changed externally +local file_change_detect = vim.api.nvim_create_augroup("FileChangeDetect", { clear = true }) +vim.api.nvim_create_autocmd({"FocusGained", "BufEnter", "BufWinEnter", "WinEnter", "CursorHold", "CursorHoldI"}, { + group = file_change_detect, + callback = function() + vim.cmd("checktime") + end, +}) + +vim.api.nvim_create_autocmd("FileChangedShellPost", { + group = file_change_detect, + callback = function() + vim.notify("File changed on disk. Buffer reloaded.", vim.log.levels.WARN) + vim.cmd("checktime") + end, +}) + +-------------------------------- +-- TERMINAL BEHAVIOR +-------------------------------- + +-- Terminal settings and keymaps +local terminal_settings = vim.api.nvim_create_augroup("TerminalSettings", { clear = true }) +vim.api.nvim_create_autocmd({"TermOpen", "BufEnter"}, { + group = terminal_settings, + callback = function() + if vim.opt.buftype:get() == "terminal" then + vim.cmd("startinsert") + + -- Terminal keymaps + local opts = { noremap = true, silent = true, buffer = true } + vim.keymap.set("t", "", [[ToggleTerm]], opts) + vim.keymap.set("t", "", [[ToggleTerm]], opts) + vim.keymap.set("t", "jk", [[]], opts) + vim.keymap.set("t", "", [[h]], opts) + vim.keymap.set("t", "", [[j]], opts) + vim.keymap.set("t", "", [[k]], opts) + vim.keymap.set("t", "", [[l]], opts) + end + end, +}) + +-------------------------------- +-- CUSTOM FILETYPES +-------------------------------- + +-- Custom filetype detection +local filetype_group = vim.api.nvim_create_augroup("CustomFileTypes", { clear = true }) + +-- Set up .seq files to use codev syntax +vim.api.nvim_create_autocmd({"BufRead", "BufNewFile"}, { + group = filetype_group, + pattern = "*.seq", + callback = function() + vim.bo.filetype = "seq" + vim.bo.syntax = "codev" + vim.bo.commentstring = "!%s" + end, +}) + +-- Set up .lis files to use codelis syntax +vim.api.nvim_create_autocmd({"BufRead", "BufNewFile"}, { + group = filetype_group, + pattern = "*.lis", + callback = function() + vim.bo.filetype = "lis" + vim.bo.syntax = "codelis" + end, +}) + +-------------------------------- +-- CUSTOM COMMANDS +-------------------------------- + +-- Python docstring helper +vim.api.nvim_create_user_command("PythonDocstring", function() + local docstring = [[""" + +# Information: + +# Arguments: + +# Returns: + +"""]] + -- Insert the docstring at the cursor position + local line = vim.api.nvim_win_get_cursor(0)[1] + vim.api.nvim_buf_set_lines(0, line-1, line-1, false, vim.split(docstring, "\n")) + -- Position cursor at the right spot + vim.api.nvim_win_set_cursor(0, {line+1, 0}) +end, {}) diff --git a/nvim/lua/core/keymaps.lua b/nvim/lua/core/keymaps.lua new file mode 100644 index 0000000..0ab02ff --- /dev/null +++ b/nvim/lua/core/keymaps.lua @@ -0,0 +1,113 @@ +-- Core keymaps +-- General key mappings not tied to specific plugins + +-- Leader key +vim.g.mapleader = " " + +---------------- +-- NORMAL MODE +---------------- + +-- File operations +vim.keymap.set("n", "w", "w", { desc = "Save file" }) +vim.keymap.set("n", "q", "q", { desc = "Quit" }) +vim.keymap.set("n", "Q", "q!", { desc = "Force quit" }) +vim.keymap.set("n", "", "bd", { desc = "Close buffer" }) + +-- Quick buffer navigation +vim.keymap.set("n", "", "h", { desc = "Move to left window" }) +vim.keymap.set("n", "", "j", { desc = "Move to bottom window" }) +vim.keymap.set("n", "", "k", { desc = "Move to top window" }) +vim.keymap.set("n", "", "l", { desc = "Move to right window" }) + +-- Quick formatting +vim.keymap.set("n", "S", "ggVG=", { desc = "Format entire file" }) + +-- Quick line operations +vim.keymap.set("n", "o", "o", { desc = "New line below" }) +vim.keymap.set("n", "O", "O", { desc = "New line above" }) +vim.keymap.set("n", "J", "mzJ`z", { desc = "Join lines and maintain cursor" }) + +-- Better vertical navigation +vim.keymap.set("n", "", "zz", { desc = "Half page down and center" }) +vim.keymap.set("n", "", "zz", { desc = "Half page up and center" }) +vim.keymap.set("n", "n", "nzzzv", { desc = "Next search result and center" }) +vim.keymap.set("n", "N", "Nzzzv", { desc = "Prev search result and center" }) + +-- Clipboard operations +vim.keymap.set({"n", "v"}, "y", [["+y]], { desc = "Copy to system clipboard" }) +vim.keymap.set("n", "Y", [["+Y]], { desc = "Copy line to system clipboard" }) +vim.keymap.set({"n", "v"}, "d", [["_d]], { desc = "Delete to void register" }) +vim.keymap.set("x", "p", [["_dP]], { desc = "Paste over selection" }) + +-- Quickfix navigation +vim.keymap.set("n", "k", "lnextzz", { desc = "Next quickfix item" }) +vim.keymap.set("n", "j", "lprevzz", { desc = "Previous quickfix item" }) + +-- Undo remap +vim.keymap.set("n", "U", "", { desc = "Redo" }) + +-- Search and replace current word +vim.keymap.set("n", "s", [[:%s/\<\>//gI]], + { desc = "Replace current word" }) + +-- Terminal keymaps +vim.keymap.set("n", "t", "ToggleTerm", { desc = "Toggle terminal" }) +vim.keymap.set({"n", "i"},"", "ToggleTermSendCurrentLinej", { desc = "Send line to terminal" }) +vim.keymap.set("n","", "ggVG:'<,'>ToggleTermSendVisualLines", { desc = "Send file to terminal" }) +vim.keymap.set("i","", "ggVG:'<,'>ToggleTermSendVisualLinesi", { desc = "Send file to terminal" }) +vim.keymap.set("v","", ":ToggleTermSendVisualLines", { desc = "Send selection to terminal" }) + +-- File browser +vim.keymap.set("n", "-", "Oil", { desc = "Open parent directory with Oil" }) + +-- LSP quick diagnostics +vim.keymap.set('n', 'e', vim.diagnostic.open_float, { noremap=true, silent=true, desc = "Show diagnostics" }) + +-- Python docstring helper +vim.keymap.set("n", "dc", ":PythonDocstring", { + silent = true, + desc = "Insert Python docstring template" +}) + +---------------- +-- INSERT MODE +---------------- + +vim.keymap.set("i", "jk", "", { desc = "Exit insert mode" }) +vim.keymap.set("i", "e", "e", { desc = "Insert e after leader" }) +vim.keymap.set("i", "", "bd", { desc = "Close buffer" }) + +---------------- +-- VISUAL MODE +---------------- + +-- Move selected lines +vim.keymap.set("v", "J", ":m '>+1gv=gv", { desc = "Move selection down" }) +vim.keymap.set("v", "K", ":m '<-2gv=gv", { desc = "Move selection up" }) + +-- Telescope keymaps (grouped for related functionality) +vim.keymap.set("n", "ff", "Telescope find_files theme=dropdown", { desc = "Find files" }) +vim.keymap.set("n", "fm", "Telescope find_files cwd=D:/Optics/CODEV/Macros theme=dropdown", { desc = "Find macro files" }) +vim.keymap.set("n", "fc", "Telescope find_files cwd=C:/CODEV202403/macro theme=dropdown", { desc = "Find CODEV macro files" }) +vim.keymap.set("n", "fl", "Telescope find_files cwd=C:/CODEV202403/lens theme=dropdown", { desc = "Find lens files" }) +vim.keymap.set("n", "gg", "Telescope live_grep theme=dropdown", { desc = "Live grep" }) +vim.keymap.set("n", "gm", "Telescope live_grep cwd=D:/Optics/CODEV/Macros theme=dropdown", { desc = "Grep in macro files" }) +vim.keymap.set("n", "gc", "Telescope live_grep cwd=C:/CODEV202403/macro theme=dropdown", { desc = "Grep in CODEV macro files" }) +vim.keymap.set("n", "gl", "Telescope live_grep cwd=C:/CODEV202403/lens theme=dropdown", { desc = "Grep in lens files" }) +vim.keymap.set("n", "b", "Telescope buffers theme=dropdown", { desc = "List buffers" }) + +-- Harpoon keymaps +vim.keymap.set("n", "a", function() require("harpoon"):list():add() end, { desc = "Add file to harpoon" }) +vim.keymap.set("n", "", function() require("harpoon").ui:toggle_quick_menu(require("harpoon"):list()) end, { desc = "Toggle harpoon menu" }) +vim.keymap.set("n", "h", function() require("harpoon"):list():select(1) end, { desc = "Harpoon file 1" }) +vim.keymap.set("n", "j", function() require("harpoon"):list():select(2) end, { desc = "Harpoon file 2" }) +vim.keymap.set("n", "k", function() require("harpoon"):list():select(3) end, { desc = "Harpoon file 3" }) +vim.keymap.set("n", "l", function() require("harpoon"):list():select(4) end, { desc = "Harpoon file 4" }) +vim.keymap.set("n", "N", function() require("harpoon"):list():prev() end, { desc = "Previous harpoon file" }) +vim.keymap.set("n", "P", function() require("harpoon"):list():next() end, { desc = "Next harpoon file" }) + +-- Other tool keymaps +vim.keymap.set("n", "G", vim.cmd.Git, { desc = "Open Git status" }) +vim.keymap.set("n", "u", vim.cmd.UndotreeToggle, { desc = "Toggle undo tree" }) +vim.keymap.set("n", "[c", function() require("treesitter-context").go_to_context() end, { desc = "Go to context", silent = true }) diff --git a/nvim/lua/core/options.lua b/nvim/lua/core/options.lua new file mode 100644 index 0000000..b05ad08 --- /dev/null +++ b/nvim/lua/core/options.lua @@ -0,0 +1,37 @@ +-- Core Neovim settings +-- General options and settings + +-- UI settings +vim.opt.termguicolors = true -- True color support +vim.opt.number = true -- Show line numbers +vim.opt.relativenumber = true -- Show relative line numbers +vim.opt.scrolloff = 999 -- Keep cursor centered +vim.opt.splitbelow = true -- Horizontal splits below +vim.opt.splitright = true -- Vertical splits to the right +vim.opt.wrap = true -- Line wrapping +vim.opt.virtualedit = "block" -- Allow cursor beyond text in block mode + +-- Search settings +vim.opt.hlsearch = false -- Don't highlight search results +vim.opt.incsearch = true -- Incremental search +vim.opt.ignorecase = true -- Case insensitive search + +-- Tab settings +vim.opt.tabstop = 4 -- Tab width +vim.opt.softtabstop = 4 -- Soft tab width +vim.opt.shiftwidth = 4 -- Indentation width +vim.opt.expandtab = true -- Use spaces instead of tabs + +-- File management +vim.opt.swapfile = false -- No swap files +vim.opt.backup = false -- No backup files +vim.opt.undodir = os.getenv("USERPROFILE").."/.vim/undodir" -- Undo directory +vim.opt.undofile = true -- Persistent undo history + +-- Performance and usability +vim.opt.updatetime = 50 -- Faster update time +vim.opt.inccommand = "split" -- Live substitution preview + +-- Status line +vim.cmd([[set laststatus=2]]) -- Always show statusline +vim.cmd([[set shortmess=I]]) -- Don't show intro message diff --git a/nvim/lua/keybindings.lua b/nvim/lua/keybindings.lua deleted file mode 100644 index 9a9d0f0..0000000 --- a/nvim/lua/keybindings.lua +++ /dev/null @@ -1,162 +0,0 @@ -vim.g.mapleader = " " ---Telescope keys --- local builtin = require('telescope.builtin') --- vim.keymap.set('n', 'ps', function() --- builtin.grep_string({ search = vim.fn.input("Grep > ") }) --- end) - --- vim.keymap.set('n', 'pf', builtin.find_files, {}) --- vim.keymap.set("n", "pv", vim.cmd.Ex) --- vim.keymap.set('n', "ps", builtin.live_grep,{}) --- vim.keymap.set('n', "pb", builtin.buffers,{}) - --- vim.keymap.set('n', 'ff', 'Telescope find_files search_dirs=[".","D:/Optics/CODEV/Macros","C:/CODEV202403/macro","C:/CODEV202403/lens"] theme=dropdown') -vim.keymap.set('n', 'ff', "Telescope find_files theme=dropdown") -vim.keymap.set('n', 'fm', "Telescope find_files cwd=D:/Optics/CODEV/Macros theme=dropdown") -vim.keymap.set('n', 'fc', "Telescope find_files cwd=C:/CODEV202403/macro theme=dropdown") -vim.keymap.set('n', 'fl', "Telescope find_files cwd=C:/CODEV202403/lens theme=dropdown") - -vim.keymap.set("n", "pp", "Telescope file_browser theme=dropdown") -vim.keymap.set("n", "pm", "Telescope file_browser cwd=D:/Optics/CODEV/Macros theme=dropdown") -vim.keymap.set("n", "pc", "Telescope file_browser cwd=C:/CODEV202403/macro theme=dropdown") -vim.keymap.set("n", "pl", "Telescope file_browser cwd=C:/CODEV202403/lens theme=dropdown") - -vim.keymap.set('n', "gg", "Telescope live_grep theme=dropdown") -vim.keymap.set('n', "gm", "Telescope live_grep cwd=D:/Optics/CODEV/Macros theme=dropdown") -vim.keymap.set('n', "gc", "Telescope live_grep cwd=C:/CODEV202403/macro theme=dropdown") -vim.keymap.set('n', "gl", "Telescope live_grep cwd=C:/CODEV202403/lens theme=dropdown") - - -vim.keymap.set('n', "b", "Telescope buffers theme=dropdown") - -vim.keymap.set('n', 'u', vim.cmd.UndotreeToggle) -vim.keymap.set('n', 'G', vim.cmd.Git) --- Language Server Keybindings -local lsp_zero = require('lsp-zero') - -lsp_zero.on_attach(function(client, bufnr) - local opts = {buffer = bufnr, remap = false} - - vim.keymap.set("n", "gd", function() vim.lsp.buf.definition() end, opts) - vim.keymap.set("n", "K", function() vim.lsp.buf.hover() end, opts) - vim.keymap.set("n", "vws", function() vim.lsp.buf.workspace_symbol() end, opts) - vim.keymap.set("n", "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", "vca", function() vim.lsp.buf.code_action() end, opts) - vim.keymap.set("n", "vrr", function() vim.lsp.buf.references() end, opts) - vim.keymap.set("n", "vrn", function() vim.lsp.buf.rename() end, opts) - vim.keymap.set("i", "", function() vim.lsp.buf.signature_help() end, opts) -end) - -require('mason').setup({}) -require('mason-lspconfig').setup({ - ensure_installed = {'tsserver', 'rust_analyzer'}, - handlers = { - lsp_zero.default_setup, - lua_ls = function() - local lua_opts = lsp_zero.nvim_lua_ls() - require('lspconfig').lua_ls.setup(lua_opts) - end, - } -}) - -local cmp = require('cmp') -local cmp_select = {behavior = cmp.SelectBehavior.Select} - -cmp.setup({ - sources = { - {name = 'path'}, - {name = 'nvim_lsp'}, - {name = 'nvim_lua'}, - }, - formatting = lsp_zero.cmp_format(), - mapping = cmp.mapping.preset.insert({ - [''] = cmp.mapping.scroll_docs(-4), - [''] = cmp.mapping.scroll_docs(4), - [''] = cmp.mapping.select_prev_item(cmp_select), - [''] = cmp.mapping.select_next_item(cmp_select), - [''] = cmp.mapping.confirm({ select = true }), - [''] = cmp.mapping.complete(), - }), -}) --- General Keybindings -vim.keymap.set("i", "jk", "") -vim.keymap.set("n","w", "w") -vim.keymap.set("n","q", "q") -vim.keymap.set("n","", "bd") -vim.keymap.set("i","", "bd") -vim.keymap.set("n","Q", "q!") -vim.keymap.set("n","o", "o") -vim.keymap.set("n","O", "O") -vim.keymap.set("i", "e", "e") ---File Formatting -vim.keymap.set("n","S", "ggVG=") --- Moving Lines around -vim.keymap.set("v", "J", ":m '>+1gv=gv") -vim.keymap.set("v", "K", ":m '<-2gv=gv") -vim.keymap.set("n", "J", "mzJ`z") ---Fast Vertical Navigation -vim.keymap.set("n", "", "zz") -vim.keymap.set("n", "", "zz") --- Search terms stay in the middle -vim.keymap.set("n", "n", "nzzzv") -vim.keymap.set("n", "N", "Nzzzv") --- pasting something instead of current text -vim.keymap.set("x", "p", [["_dP]]) --- copying into system clipboard -vim.keymap.set({"n", "v"}, "y", [["+y]]) -vim.keymap.set("n", "Y", [["+Y]]) --- Put into Void Register -vim.keymap.set({"n", "v"}, "d", [["_d]]) --- Quick Fix List Navingation ---vim.keymap.set("n", "", "cnextzz") ---vim.keymap.set("n", "", "cprevzz") -vim.keymap.set("n", "k", "lnextzz") -vim.keymap.set("n", "j", "lprevzz") --- Terminal Navigation --- vim.keymap.set("n", "tt", "ToggleTerm size=60 direction=horizontal shell=powershell") -vim.keymap.set("n", "t", "ToggleTerm") --- vim.keymap.set("n", "", "ToggleTerm") --- vim.keymap.set("i", "", "ToggleTerm") --- vim.keymap.set("n", "tt", "vertical 60 vsplit | terminal pwsh.exe") --- vim.keymap.set("n", "tj", "term pwsh.exe") -vim.keymap.set("t", "jk", [[]]) -vim.keymap.set("t", "", [[h]]) -vim.keymap.set("t", "", [[j]]) -vim.keymap.set("t", "", [[k]]) -vim.keymap.set("t", "", [[l]]) ---Sending lines and file to the internal terminal I had before to make the cursor move to the previous position but this doesnt seem to be a good option -vim.keymap.set({"n", "i"},"", "ToggleTermSendCurrentLinej") -vim.keymap.set("n","", "ggVG:'<,'>ToggleTermSendVisualLines") -vim.keymap.set("i","", "ggVG:'<,'>ToggleTermSendVisualLinesi") -vim.keymap.set("v","", ":ToggleTermSendVisualLines") --- Buffer Navigation -vim.keymap.set("n", "", [[h]]) -vim.keymap.set("n", "", [[j]]) -vim.keymap.set("n", "", [[k]]) -vim.keymap.set("n", "", [[l]]) --- Undo Remapping -vim.keymap.set("n", "U", "") --- Replace the Current Word everywhere -vim.keymap.set("n", "s", [[:%s/\<\>//gI]]) --- Nvim-Tree --- vim.keymap.set("n", "e", "NvimTreeToggle") --- BufferLine Navigation --- vim.keymap.set("n", "", "BufferLineCycleNext") --- vim.keymap.set("n", "", "BufferLineCyclePrev") --- vim.keymap.set("n", "", "BufferLineCloseOthers") --- Treesitter Context -vim.keymap.set("n", "[c", function() - require("treesitter-context").go_to_context() -end, { silent = true }) --- Docstring commands -vim.keymap.set("n","dc",[[i"""oo#Information:oo#Arguments:oo#Returns:oo"""7k]]) - - - ---vim.keymap.set('n', '', bultin.git_files,{}) ---Oil.nvim keybinds -vim.keymap.set("n", "-", "Oil", { desc = "Open parent directory" }) - -vim.keymap.set("n","m","silent make") diff --git a/nvim/lua/options.lua b/nvim/lua/options.lua deleted file mode 100644 index 944ea6d..0000000 --- a/nvim/lua/options.lua +++ /dev/null @@ -1,43 +0,0 @@ ---Sets automatic update of the file internals -vim.api.nvim_exec2([[ - autocmd FocusGained,BufEnter,BufWinEnter,WinEnter,CursorHold,CursorHoldI * checktime - autocmd FileChangedShellPost * echohl WarningMsg | echo "File changed on disk. Buffer reloaded." | echohl None | checktime -]],{}) -vim.api.nvim_exec2([[set shortmess=I]],{}) - --- vim.api.nvim_exec2([[autocmd TermOpen * startinsert]],{}) - -vim.opt.termguicolors = true --- vim.o.statusline = [[%<%f\ %h%m%r%=%-13.(%l,%c%V%)\ %P]] --- vim.o.laststatus = 2 - -vim.opt.splitbelow = true -vim.opt.splitright = true - -vim.opt.relativenumber = true -vim.opt.number = true -vim.opt.tabstop = 4 -vim.opt.softtabstop = 4 -vim.opt.shiftwidth = 4 -vim.opt.expandtab = true - -vim.opt.swapfile = false -vim.opt.backup = false -vim.opt.undodir = os.getenv("USERPROFILE").."/.vim/undodir" -vim.opt.undofile = true - -vim.opt.hlsearch = false -vim.opt.incsearch = true - -vim.opt.scrolloff = 999 -vim.opt.updatetime = 50 - -vim.opt.wrap = true - -vim.opt.virtualedit = "block" -vim.opt.inccommand = "split" -vim.opt.ignorecase = true - -vim.cmd[[set laststatus=2]] --- vim.opt.clipboard = "unnamedplus" ---vim.opt.colorcolumn = "180" diff --git a/nvim/lua/plugins.lua b/nvim/lua/plugins.lua index 79b4c5f..a04187c 100644 --- a/nvim/lua/plugins.lua +++ b/nvim/lua/plugins.lua @@ -1,8 +1,10 @@ --- lazy plugin manager +-- Plugin declarations +-- All plugins used in Neovim are defined here + + +-- Bootstrap lazy.nvim local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" if not vim.loop.fs_stat(lazypath) then - -- bootstrap lazy.nvim - -- stylua: ignore vim.fn.system({ "git", "clone", @@ -12,245 +14,196 @@ if not vim.loop.fs_stat(lazypath) then lazypath, }) end -vim.opt.rtp:prepend(vim.env.LAZY or lazypath) - -require("lazy").setup({ +vim.opt.rtp:prepend(lazypath) + +-- Initialize lazy.nvim with plugins +require("lazy").setup({ + ------------------------------------------------------------ + -- UI + ------------------------------------------------------------ + -- Colorscheme { "folke/tokyonight.nvim", - init = function() + lazy = false, + priority = 1000, + config = function() vim.cmd.colorscheme("tokyonight-night") - end + end, }, + -- File browser { - 'tpope/vim-fugitive', + 'stevearc/oil.nvim', + dependencies = { "nvim-tree/nvim-web-devicons" }, + cmd = "Oil", }, + -- Terminal { - { - 'VonHeikemen/lsp-zero.nvim', - branch = 'v3.x', - lazy = true, - config = false, - init = function() - -- Disable automatic setup, we are doing it manually - vim.g.lsp_zero_extend_cmp = 0 - vim.g.lsp_zero_extend_lspconfig = 0 - end, - }, - - { - 'williamboman/mason.nvim', - lazy = false, - config = true, - }, - - { - 'neovim/nvim-lspconfig', - dependencies = { - {'hrsh7th/cmp-nvim-lsp'}, - } - }, - - -- Autocompletion - { - 'hrsh7th/nvim-cmp', - event = 'InsertEnter', - dependencies = { - {'L3MON4D3/LuaSnip', - 'hrsh7th/cmp-path', - }, - }, - config = function() - -- Here is where you configure the autocompletion settings. - local lsp_zero = require('lsp-zero') - lsp_zero.extend_cmp() - - -- And you can configure cmp even more, if you want to. - local cmp = require('cmp') - local cmp_action = lsp_zero.cmp_action() - - cmp.setup({ - formatting = lsp_zero.cmp_format(), - sources = { - { name = 'nvim_lsp' }, -- Enable LSP-based completion - { name = 'path' }, -- Enables path completion - { name = 'buffer' }, -- Buffer source for plain text completion - }, - mapping = cmp.mapping.preset.insert({ - [''] = cmp.mapping.complete(), - [''] = cmp.mapping.scroll_docs(-4), - [''] = cmp.mapping.scroll_docs(4), - [''] = cmp_action.luasnip_jump_forward(), - [''] = cmp_action.luasnip_jump_backward(), - }), - - -- }, - }) - end - }, - -- LSP - { - 'neovim/nvim-lspconfig', - cmd = {'LspInfo', 'LspInstall', 'LspStart'}, - event = {'BufReadPre', 'BufNewFile'}, - dependencies = { - {'hrsh7th/cmp-nvim-lsp'}, - {'williamboman/mason-lspconfig.nvim'}, - }, - config = function() - -- This is where all the LSP shenanigans will live - local lsp_zero = require('lsp-zero') - lsp_zero.extend_lspconfig() - - lsp_zero.on_attach(function(client, bufnr) - -- see :help lsp-zero-keybindings - -- to learn the available actions - lsp_zero.default_keymaps({buffer = bufnr}) - end) - - - require('mason-lspconfig').setup({ - ensure_installed = {}, - handlers = { - lsp_zero.default_setup, - lua_ls = function() - -- (Optional) Configure lua language server for neovim - local lua_opts = lsp_zero.nvim_lua_ls() - require('lspconfig').lua_ls.setup(lua_opts) - end, - -- ADD THIS SECTION for clangd: - clangd = function() - require('lspconfig').clangd.setup({ - cmd = { "clangd", "--header-insertion=never" }, - -- No root_dir specification that requires compile_commands.json - }) - end, - } - }) - end - } - + 'akinsho/toggleterm.nvim', + version = "*", + cmd = {"ToggleTerm", "ToggleTermSendCurrentLine", "ToggleTermSendVisualLines"}, }, + ------------------------------------------------------------ + -- EDITOR ENHANCEMENTS + ------------------------------------------------------------ + + -- Telescope (fuzzy finder) { 'nvim-telescope/telescope.nvim', - -- or , branch = '0.1.x', - dependencies = { 'nvim-lua/plenary.nvim' } + dependencies = { 'nvim-lua/plenary.nvim' }, + cmd = "Telescope", }, + -- Harpoon (quick file navigation) { - 'nvim-treesitter/nvim-treesitter', - build = ':TSUpdate', - config = function () - local configs = require("nvim-treesitter.configs") - - configs.setup({ - ensure_installed = { "c", "lua", "vim", "vimdoc", "cpp", "python"}, --add "neorg here" - sync_install = false, - highlight = { - enable = true - }, - indent = { - enable = true - }, - }) - end + "ThePrimeagen/harpoon", + branch = "harpoon2", + dependencies = { "nvim-lua/plenary.nvim" }, }, + -- Git integration { - 'mbbill/undotree' + 'tpope/vim-fugitive', + cmd = {"Git", "Gstatus", "Gblame", "Gdiffsplit", "Gread", "Gwrite", "Ggrep", "GMove", "GDelete"}, }, - {'akinsho/toggleterm.nvim', - version = "*", - opts = { - shell = "pwsh.exe -NoLogo", - winbar = { - enabled =false - }, - direction = 'float', - border = 'none', -- No border around the terminal - -- width = function() - -- return vim.o.columns -- Full width of the screen - -- end, - -- height = function() - -- return vim.o.lines -- Full height minus command line - -- end, - -- width = 800, - -- height = 700, - } + -- Undo history visualization + { + 'mbbill/undotree', + cmd = "UndotreeToggle", }, + + ------------------------------------------------------------ + -- CODE EDITING + ------------------------------------------------------------ + + -- Syntax highlighting { - 'windwp/nvim-autopairs', - event = "InsertEnter", - config = true - -- use opts = {} for passing setup options - -- this is equivalent to setup({}) function -}, + 'nvim-treesitter/nvim-treesitter', + build = ':TSUpdate', + event = { "BufReadPost", "BufNewFile" }, + cmd = { "TSUpdateSync", "TSUpdate", "TSInstall" }, + dependencies = { + 'nvim-treesitter/nvim-treesitter-context', + }, + }, + -- Comments { 'numToStr/Comment.nvim', - lazy = false, - opts= { - -- filetype = { - -- seq ={ - -- commentstring ="! %s" - -- } - -- }, - ---Add a space b/w comment and the line - padding = true, - ---Whether the cursor should stay at its position - sticky = true, - ---Lines to be ignored while (un)comment - ignore = nil, - ---LHS of toggle mappings in NORMAL mode - toggler = { - ---Line-comment toggle keymap - line = '/', - ---Block-comment toggle keymap - block = 'gbc', - }, - ---LHS of operator-pending mappings in NORMAL and VISUAL mode - opleader = { - ---Line-comment keymap - line = '/', - ---Block-comment keymap - block = 'gb', - }} + event = { "BufReadPost", "BufNewFile" }, }, - + -- Auto brackets { - 'nvim-treesitter/nvim-treesitter-context' + 'windwp/nvim-autopairs', + event = "InsertEnter", + config = true, }, + + -- LaTeX support { "lervag/vimtex", - lazy = false, -- we don't want to lazy load VimTeX - -- tag = "v2.15", -- uncomment to pin to a specific release + ft = {"tex", "latex"}, init = function() - -- VimTeX configuration goes here, e.g. vim.g.vimtex_view_method = "mupdf" end }, - -- { - -- "nvim-telescope/telescope-file-browser.nvim", - -- dependencies = { "nvim-telescope/telescope.nvim", "nvim-lua/plenary.nvim" }, - -- - -- }, - + ------------------------------------------------------------ + -- LSP & COMPLETION + ------------------------------------------------------------ + + -- LSP Base { - "ThePrimeagen/harpoon", - branch = "harpoon2", - dependencies = { "nvim-lua/plenary.nvim" } + "mason-org/mason.nvim", + "mason-org/mason-lspconfig.nvim", + "neovim/nvim-lspconfig", +}, + { + "folke/lazydev.nvim", + ft = "lua", -- only load on lua files + opts = { + library = { + -- See the configuration section for more details + -- Load luvit types when the `vim.uv` word is found + { path = "${3rd}/luv/library", words = { "vim%.uv" } }, + }, }, + }, + + -- Autocompletion { - 'stevearc/oil.nvim', - opts = {}, - -- Optional dependencies - -- dependencies = { "echasnovski/mini.icons" }, - dependencies = { "nvim-tree/nvim-web-devicons" }, -- use if prefer nvim-web-devicons - } + 'saghen/blink.cmp', + -- optional: provides snippets for the snippet source + dependencies = { 'rafamadriz/friendly-snippets' }, + + version = '1.*', + opts = { + -- 'default' (recommended) for mappings similar to built-in completions (C-y to accept) + -- 'super-tab' for mappings similar to vscode (tab to accept) + -- 'enter' for enter to accept + -- 'none' for no mappings + -- + -- All presets have the following mappings: + -- C-space: Open menu or open docs if already open + -- C-n/C-p or Up/Down: Select next/previous item + -- C-e: Hide menu + -- C-k: Toggle signature help (if signature.enabled = true) + -- + -- See :h blink-cmp-config-keymap for defining your own keymap + keymap = { preset = 'default' }, + + appearance = { + -- 'mono' (default) for 'Nerd Font Mono' or 'normal' for 'Nerd Font' + -- Adjusts spacing to ensure icons are aligned + nerd_font_variant = 'mono' + }, + + -- (Default) Only show the documentation popup when manually triggered + completion = { documentation = { auto_show = true} }, + + -- Default list of enabled providers defined so that you can extend it + -- elsewhere in your config, without redefining it, due to `opts_extend` +sources = { + -- add lazydev to your completion providers + default = { "lazydev", "lsp", "path", "snippets", "buffer" }, + providers = { + lazydev = { + name = "LazyDev", + module = "lazydev.integrations.blink", + -- make lazydev completions top priority (see `:h blink.cmp`) + score_offset = 100, + }, + }, + }, + -- (Default) Rust fuzzy matcher for typo resistance and significantly better performance + -- You may use a lua implementation instead by using `implementation = "lua"` or fallback to the lua implementation, + -- when the Rust fuzzy matcher is not available, by using `implementation = "prefer_rust"` + -- + -- See the fuzzy documentation for more information + fuzzy = { implementation = "prefer_rust_with_warning" } + }, + opts_extend = { "sources.default" } +}, + +}, { + -- Lazy.nvim options + install = { colorscheme = { "tokyonight-night" } }, + checker = { enabled = true, frequency = 86400 }, -- Check for updates once per day + change_detection = { notify = false }, + performance = { + rtp = { + disabled_plugins = { + "gzip", + "tarPlugin", + "tohtml", + "tutor", + "zipPlugin", + }, + }, + }, }) -- cgit v1.2.3