From ed6b02924f28c153e9bade557082818da5b041ab Mon Sep 17 00:00:00 2001 From: Ethan Lane Date: Thu, 15 May 2025 18:20:49 +0100 Subject: [PATCH] WIP: Start moving neovim config to lua --- .config/nvim/after/plugin/colors.lua | 0 .config/nvim/init.lua | 4 + .config/nvim/{init.vim => init.vim.bak} | 0 .config/nvim/lua/configs.lua | 36 +++++ .config/nvim/lua/functions.lua | 0 .config/nvim/lua/functions/.gitkeep | 0 .config/nvim/lua/keybindings.lua | 50 +++++++ .config/nvim/lua/plugins.lua | 41 ++++++ .config/nvim/lua/plugins/.gitkeep | 0 .config/nvim/lua/utils.lua | 0 .config/nvim/plugin/packer_compiled.lua | 174 ++++++++++++++++++++++++ 11 files changed, 305 insertions(+) create mode 100644 .config/nvim/after/plugin/colors.lua create mode 100644 .config/nvim/init.lua rename .config/nvim/{init.vim => init.vim.bak} (100%) create mode 100644 .config/nvim/lua/configs.lua create mode 100644 .config/nvim/lua/functions.lua create mode 100644 .config/nvim/lua/functions/.gitkeep create mode 100644 .config/nvim/lua/keybindings.lua create mode 100644 .config/nvim/lua/plugins.lua create mode 100644 .config/nvim/lua/plugins/.gitkeep create mode 100644 .config/nvim/lua/utils.lua create mode 100644 .config/nvim/plugin/packer_compiled.lua diff --git a/.config/nvim/after/plugin/colors.lua b/.config/nvim/after/plugin/colors.lua new file mode 100644 index 0000000..e69de29 diff --git a/.config/nvim/init.lua b/.config/nvim/init.lua new file mode 100644 index 0000000..85cf7be --- /dev/null +++ b/.config/nvim/init.lua @@ -0,0 +1,4 @@ +require("configs") +require("plugins") +require("keybindings") +require("functions") diff --git a/.config/nvim/init.vim b/.config/nvim/init.vim.bak similarity index 100% rename from .config/nvim/init.vim rename to .config/nvim/init.vim.bak diff --git a/.config/nvim/lua/configs.lua b/.config/nvim/lua/configs.lua new file mode 100644 index 0000000..e37ac79 --- /dev/null +++ b/.config/nvim/lua/configs.lua @@ -0,0 +1,36 @@ +-- Imports +local U = require("utils") + +-- Neovim Alias +local exec = vim.api.nvim_exec -- execute Vimscript +local api = vim.api -- neovim commands +local autocmd = vim.api.nvim_create_autocmd -- execute autocommands +local set = vim.opt -- global options +local cmd = vim.cmd -- execute Vim commands + +-- Configs +vim.g.mapleader = " " + +set.compatible = false +set.showmatch = true +set.ignorecase = true +set.mouse = "v" +set.hlsearch = true +set.incsearch = true +set.tabstop = 4 +set.softtabstop = 4 +set.expandtab = true +set.shiftwidth = 4 +set.autoindent = true +set.number = true +set.relativenumber = true +set.wildmode = "longest,list" +set.cc = "80" +set.mouse = "a" +set.clipboard = "unnamedplus" +set.cursorline = true +set.ttyfast = true +set.fixeol = false +set.splitright = true +set.splitbelow = true +set.termguicolors = true diff --git a/.config/nvim/lua/functions.lua b/.config/nvim/lua/functions.lua new file mode 100644 index 0000000..e69de29 diff --git a/.config/nvim/lua/functions/.gitkeep b/.config/nvim/lua/functions/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/.config/nvim/lua/keybindings.lua b/.config/nvim/lua/keybindings.lua new file mode 100644 index 0000000..cd5b5da --- /dev/null +++ b/.config/nvim/lua/keybindings.lua @@ -0,0 +1,50 @@ +-- Helper function +function map(mode, lhs, rhs, opts) + local options = { noremap = true } + if opts then + options = vim.tbl_extend("force", options, opts) + end + vim.keymap.set(mode, lhs, rhs, options) +end + +local opts = { silent = true, noremap = true, expr = true } + +-- Move Lines Up/Down +map("i", "", ":m .+1==gi", opts) +map("i", "", ":m .-2==gi", opts) +map("v", "", ":m '>+1gv=gv", opts) +map("v", "", ":m '<-2gv=gv", opts) + +map("n", "", "H", opts) +map("n", "", "J", opts) +map("n", "", "K", opts) +map("n", "", "L", opts) + +map("n", "", "h", opts) +map("n", "", "j", opts) +map("n", "", "k", opts) +map("n", "", "l", opts) + +map("n", "gf", ":vert winc f", opts) + +map("i", "", [[coc#pum#visible() ? coc#_select_confirm() : "\u\"]], opts) +map("i", "", [[coc#pum#visible() ? coc#pum#next(1) : "\"]], opts) +map("i", "", [[coc#pum#visible() ? coc#pum#prev(1) : "\"]], opts) + +map("n", "n", ":NERDTreeFocus", opts) +map("n", "", ":NERDTree", opts) +map("n", "", ":NERDTreeToggle", opts) +map("n", "", ":NERDTreeFind", opts) + +map("n", "ha", function() require("harpoon.mark").add_file() end, opts) +map("n", "hh", function() require("harpoon.ui").toggle_quick_menu() end, opts) +map("n", "1", [[lua require("harpoon.ui").nav_file(1)]], opts) +map("n", "2", [[lua require("harpoon.ui").nav_file(2)]], opts) +map("n", "3", [[lua require("harpoon.ui").nav_file(3)]], opts) +map("n", "4", [[lua require("harpoon.ui").nav_file(4)]], opts) +map("n", "", [[lua require("harpoon.ui").nav_prev()]], opts) +map("n", "", [[lua require("harpoon.ui").nav_next()]], opts) + +map("n", "ff", ":FZF", opts) + +map("n", "mm", ":nohl", opts) \ No newline at end of file diff --git a/.config/nvim/lua/plugins.lua b/.config/nvim/lua/plugins.lua new file mode 100644 index 0000000..f07b1cc --- /dev/null +++ b/.config/nvim/lua/plugins.lua @@ -0,0 +1,41 @@ +local install_path = vim.fn.stdpath("data") .. "/site/pack/packer/start/packer.nvim" +if vim.fn.empty(vim.fn.glob(install_path)) > 0 then + packer_bootstrap = + vim.fn.system({"git", "clone", "--depth", "1", "https://github.com/wbthomason/packer.nvim", install_path}) +end +-- Register Packer with vim +vim.api.nvim_cmd({ + cmd = "packadd", + args = {"packer.nvim"}, +}, {}) + +return require("packer").startup { + function(use) + -- Packer can manage itself + use "wbthomason/packer.nvim" + + -- Plugins go here + use 'dracula/vim' + use 'ryanoasis/vim-devicons' + -- use 'SirVer/ultisnips' + use 'honza/vim-snippets' + use 'scrooloose/nerdtree' + use 'preservim/nerdcommenter' + use 'mhinz/vim-startify' + use {'neoclide/coc.nvim', branch = 'release'} + use 'nvim-lua/plenary.nvim' + use 'ThePrimeagen/harpoon' + use 'junegunn/fzf' + use 'junegunn/fzf.vim' + use 'neovim/nvim-lspconfig' + use 'jose-elias-alvarez/null-ls.nvim' + use 'MunifTanjim/prettier.nvim' + use 'OmniSharp/omnisharp-vim' + + -- Install and compile Plugins + if packer_bootstrap then + require("packer").sync() + end + end +} + diff --git a/.config/nvim/lua/plugins/.gitkeep b/.config/nvim/lua/plugins/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/.config/nvim/lua/utils.lua b/.config/nvim/lua/utils.lua new file mode 100644 index 0000000..e69de29 diff --git a/.config/nvim/plugin/packer_compiled.lua b/.config/nvim/plugin/packer_compiled.lua new file mode 100644 index 0000000..6ad9d76 --- /dev/null +++ b/.config/nvim/plugin/packer_compiled.lua @@ -0,0 +1,174 @@ +-- Automatically generated packer.nvim plugin loader code + +if vim.api.nvim_call_function('has', {'nvim-0.5'}) ~= 1 then + vim.api.nvim_command('echohl WarningMsg | echom "Invalid Neovim version for packer.nvim! | echohl None"') + return +end + +vim.api.nvim_command('packadd packer.nvim') + +local no_errors, error_msg = pcall(function() + +_G._packer = _G._packer or {} +_G._packer.inside_compile = true + +local time +local profile_info +local should_profile = false +if should_profile then + local hrtime = vim.loop.hrtime + profile_info = {} + time = function(chunk, start) + if start then + profile_info[chunk] = hrtime() + else + profile_info[chunk] = (hrtime() - profile_info[chunk]) / 1e6 + end + end +else + time = function(chunk, start) end +end + +local function save_profiles(threshold) + local sorted_times = {} + for chunk_name, time_taken in pairs(profile_info) do + sorted_times[#sorted_times + 1] = {chunk_name, time_taken} + end + table.sort(sorted_times, function(a, b) return a[2] > b[2] end) + local results = {} + for i, elem in ipairs(sorted_times) do + if not threshold or threshold and elem[2] > threshold then + results[i] = elem[1] .. ' took ' .. elem[2] .. 'ms' + end + end + if threshold then + table.insert(results, '(Only showing plugins that took longer than ' .. threshold .. ' ms ' .. 'to load)') + end + + _G._packer.profile_output = results +end + +time([[Luarocks path setup]], true) +local package_path_str = "/home/vylpes/.cache/nvim/packer_hererocks/2.1.1741730670/share/lua/5.1/?.lua;/home/vylpes/.cache/nvim/packer_hererocks/2.1.1741730670/share/lua/5.1/?/init.lua;/home/vylpes/.cache/nvim/packer_hererocks/2.1.1741730670/lib/luarocks/rocks-5.1/?.lua;/home/vylpes/.cache/nvim/packer_hererocks/2.1.1741730670/lib/luarocks/rocks-5.1/?/init.lua" +local install_cpath_pattern = "/home/vylpes/.cache/nvim/packer_hererocks/2.1.1741730670/lib/lua/5.1/?.so" +if not string.find(package.path, package_path_str, 1, true) then + package.path = package.path .. ';' .. package_path_str +end + +if not string.find(package.cpath, install_cpath_pattern, 1, true) then + package.cpath = package.cpath .. ';' .. install_cpath_pattern +end + +time([[Luarocks path setup]], false) +time([[try_loadstring definition]], true) +local function try_loadstring(s, component, name) + local success, result = pcall(loadstring(s), name, _G.packer_plugins[name]) + if not success then + vim.schedule(function() + vim.api.nvim_notify('packer.nvim: Error running ' .. component .. ' for ' .. name .. ': ' .. result, vim.log.levels.ERROR, {}) + end) + end + return result +end + +time([[try_loadstring definition]], false) +time([[Defining packer_plugins]], true) +_G.packer_plugins = { + ["coc.nvim"] = { + loaded = true, + path = "/home/vylpes/.local/share/nvim/site/pack/packer/start/coc.nvim", + url = "https://github.com/neoclide/coc.nvim" + }, + fzf = { + loaded = true, + path = "/home/vylpes/.local/share/nvim/site/pack/packer/start/fzf", + url = "https://github.com/junegunn/fzf" + }, + ["fzf.vim"] = { + loaded = true, + path = "/home/vylpes/.local/share/nvim/site/pack/packer/start/fzf.vim", + url = "https://github.com/junegunn/fzf.vim" + }, + harpoon = { + loaded = true, + path = "/home/vylpes/.local/share/nvim/site/pack/packer/start/harpoon", + url = "https://github.com/ThePrimeagen/harpoon" + }, + nerdcommenter = { + loaded = true, + path = "/home/vylpes/.local/share/nvim/site/pack/packer/start/nerdcommenter", + url = "https://github.com/preservim/nerdcommenter" + }, + nerdtree = { + loaded = true, + path = "/home/vylpes/.local/share/nvim/site/pack/packer/start/nerdtree", + url = "https://github.com/scrooloose/nerdtree" + }, + ["null-ls.nvim"] = { + loaded = true, + path = "/home/vylpes/.local/share/nvim/site/pack/packer/start/null-ls.nvim", + url = "https://github.com/jose-elias-alvarez/null-ls.nvim" + }, + ["nvim-lspconfig"] = { + loaded = true, + path = "/home/vylpes/.local/share/nvim/site/pack/packer/start/nvim-lspconfig", + url = "https://github.com/neovim/nvim-lspconfig" + }, + ["omnisharp-vim"] = { + loaded = true, + path = "/home/vylpes/.local/share/nvim/site/pack/packer/start/omnisharp-vim", + url = "https://github.com/OmniSharp/omnisharp-vim" + }, + ["packer.nvim"] = { + loaded = true, + path = "/home/vylpes/.local/share/nvim/site/pack/packer/start/packer.nvim", + url = "https://github.com/wbthomason/packer.nvim" + }, + ["plenary.nvim"] = { + loaded = true, + path = "/home/vylpes/.local/share/nvim/site/pack/packer/start/plenary.nvim", + url = "https://github.com/nvim-lua/plenary.nvim" + }, + ["prettier.nvim"] = { + loaded = true, + path = "/home/vylpes/.local/share/nvim/site/pack/packer/start/prettier.nvim", + url = "https://github.com/MunifTanjim/prettier.nvim" + }, + vim = { + loaded = true, + path = "/home/vylpes/.local/share/nvim/site/pack/packer/start/vim", + url = "https://github.com/dracula/vim" + }, + ["vim-devicons"] = { + loaded = true, + path = "/home/vylpes/.local/share/nvim/site/pack/packer/start/vim-devicons", + url = "https://github.com/ryanoasis/vim-devicons" + }, + ["vim-snippets"] = { + loaded = true, + path = "/home/vylpes/.local/share/nvim/site/pack/packer/start/vim-snippets", + url = "https://github.com/honza/vim-snippets" + }, + ["vim-startify"] = { + loaded = true, + path = "/home/vylpes/.local/share/nvim/site/pack/packer/start/vim-startify", + url = "https://github.com/mhinz/vim-startify" + } +} + +time([[Defining packer_plugins]], false) + +_G._packer.inside_compile = false +if _G._packer.needs_bufread == true then + vim.cmd("doautocmd BufRead") +end +_G._packer.needs_bufread = false + +if should_profile then save_profiles() end + +end) + +if not no_errors then + error_msg = error_msg:gsub('"', '\\"') + vim.api.nvim_command('echohl ErrorMsg | echom "Error in packer_compiled: '..error_msg..'" | echom "Please check your config for correctness" | echohl None') +end