From 1d13bc8a07d188c5a0b413dad8197e8ae56dbd0c Mon Sep 17 00:00:00 2001 From: inorishio Date: Mon, 9 Feb 2026 16:05:53 +0100 Subject: [PATCH] The infamous windows/linux NVIM config --- init.lua | 1 - lua/autocmd.lua | 18 +-- lua/config/neoformat.lua | 238 ++++++++++++++++++++++++++++ lua/options.lua | 3 +- lua/plugins/{LOKS.lua => glowy.lua} | 0 lua/plugins/init.lua | 72 ++------- lua/plugins/telescope.lua | 36 +++++ lua/plugins/themes.lua | 9 ++ scripts/windows_dependencies.ps1 | 39 +++++ 9 files changed, 350 insertions(+), 66 deletions(-) create mode 100644 lua/config/neoformat.lua rename lua/plugins/{LOKS.lua => glowy.lua} (100%) create mode 100644 lua/plugins/telescope.lua create mode 100644 lua/plugins/themes.lua create mode 100644 scripts/windows_dependencies.ps1 diff --git a/init.lua b/init.lua index 77a2288..f9c3834 100644 --- a/init.lua +++ b/init.lua @@ -16,7 +16,6 @@ require("globals") require("mappings") require("autocmd") require("minimodules").load_modules() --- require("coc-settings") if vim.g.neovide then require("config.neovide") diff --git a/lua/autocmd.lua b/lua/autocmd.lua index 97d252b..8da5beb 100644 --- a/lua/autocmd.lua +++ b/lua/autocmd.lua @@ -2,22 +2,22 @@ local autocmd = vim.api.nvim_create_autocmd autocmd("LspAttach", { callback = function(args) - local client = vim.lsp.get_client_by_id( args.data.client_id ) - if client then + local client = vim.lsp.get_client_by_id(args.data.client_id) + if client and vim.lsp.document_color and vim.lsp.document_color.enable then vim.lsp.document_color.enable(false, args.buf, { "background" }) end end, }) autocmd("VimLeave", { - command = "set guicursor=a:ver25-Cursor" + command = "set guicursor=a:ver25-Cursor", }) autocmd("BufWritePre", { - callback = function() - local ok = pcall(function() - vim.cmd "undojoin" - end) - vim.cmd "Neoformat" - end, + callback = function() + local ok = pcall(function() + vim.cmd "undojoin" + end) + vim.cmd "Neoformat" + end, }) diff --git a/lua/config/neoformat.lua b/lua/config/neoformat.lua new file mode 100644 index 0000000..59caffd --- /dev/null +++ b/lua/config/neoformat.lua @@ -0,0 +1,238 @@ +local M = {} + +M.plugin = { + "sbdchd/neoformat", + event = { "BufReadPre", "BufNewFile" }, + config = function() + -- === formatter enablement (order = priority) === + vim.g.neoformat_enabled_lua = { "stylua" } + vim.g.neoformat_enabled_python = { "black" } + vim.g.neoformat_enabled_javascript = { "prettier" } + vim.g.neoformat_enabled_typescript = { "prettier" } + vim.g.neoformat_enabled_qml = { "qmlformat" } + vim.g.neoformat_enabled_go = { "gofmt" } + vim.g.neoformat_enabled_sh = { "shfmt" } + vim.g.neoformat_enabled_bash = { "shfmt" } + vim.g.neoformat_enabled_zsh = { "shfmt" } + vim.g.neoformat_enabled_powershell = { "pwshfmt" } -- experimental + + -- === helper to prefer local prettier in cwd/node_modules/.bin === + local function prefer_local_prettier() + local cwd = vim.fn.getcwd() + local local_path = cwd .. "/node_modules/.bin/prettier" + if vim.loop.fs_stat(local_path) then + return local_path + end + local global = vim.fn.exepath("prettier") + if global ~= "" then + return global + end + return "prettier" + end + + -- === neoformatters definitions === + vim.g.neoformatters_javascript = { + prettier = { + exe = prefer_local_prettier(), + args = { "--stdin-filepath", "%:p" }, + stdin = 1, + }, + } + vim.g.neoformatters_typescript = vim.g.neoformatters_javascript + vim.g.neoformatters_json = vim.g.neoformatters_javascript + vim.g.neoformatters_markdown = vim.g.neoformatters_javascript + + vim.g.neoformatters_lua = { + stylua = { + exe = "stylua", + args = { "-", "--stdin-filepath", "%:p" }, + stdin = 1, + }, + } + + vim.g.neoformatters_python = { + black = { + exe = "black", + args = { "-" }, + stdin = 1, + }, + } + + vim.g.neoformatters_qml = { + qmlformat = { + exe = "qmlformat", + args = { "-" }, + stdin = 1, + }, + } + + vim.g.neoformatters_go = { + gofmt = { + exe = "gofmt", + args = {}, + stdin = 1, + }, + } + + vim.g.neoformatters_sh = { + shfmt = { + exe = "shfmt", + args = { "-i", "2", "-ci" }, + stdin = 1, + }, + } + vim.g.neoformatters_bash = vim.g.neoformatters_sh + vim.g.neoformatters_zsh = vim.g.neoformatters_sh + + vim.g.neoformatters_powershell = { + pwshfmt = { + exe = "pwsh", + args = { + "-NoProfile", + "-Command", + [[ + $in = [Console]::In.ReadToEnd(); + if (Get-Command Invoke-Formatter -ErrorAction SilentlyContinue) { + Invoke-Formatter -ScriptDefinition $in | Out-String + } else { + $in + } + ]], + }, + stdin = 1, + }, + } + + -- === utility: check whether a path/exe exists === + local function is_executable(path) + if not path or path == "" then + return false + end + -- if it contains a slash or backslash, treat as path + if path:match("[/\\]") then + local stat = vim.loop.fs_stat(path) + return stat and stat.type == "file" + end + -- otherwise check PATH + return vim.fn.exepath(path) ~= "" + end + + local function resolve_exe_field(exe_field) + if type(exe_field) == "function" then + local ok, res = pcall(exe_field) + if ok then + return res + else + return nil + end + end + if type(exe_field) == "string" then + return exe_field + end + return nil + end + + -- === determine whether any configured formatter for ft is available === + local function has_formatter_for_ft(ft) + if not ft or ft == "" then + return false + end + + -- 1) check explicit enabled list first + local enabled_var = "neoformat_enabled_" .. ft + local enabled = vim.g[enabled_var] + local candidates = {} + + if enabled then + if type(enabled) == "string" then + candidates = { enabled } + elseif type(enabled) == "table" then + candidates = enabled + end + else + -- 2) fallback to any entries defined in vim.g.neoformatters_ + local table_var = "neoformatters_" .. ft + local tbl = vim.g[table_var] + if type(tbl) == "table" then + for name, _ in pairs(tbl) do + table.insert(candidates, name) + end + end + end + + if #candidates == 0 then + return false + end + + -- table of custom formatter definitions + local formatter_table = vim.g["neoformatters_" .. ft] + + for _, name in ipairs(candidates) do + -- if we have a definition with exe, check that exe + if formatter_table and formatter_table[name] and formatter_table[name].exe then + local exe_field = formatter_table[name].exe + local exe = resolve_exe_field(exe_field) + if exe and is_executable(exe) then + return true + end + else + -- otherwise, try to find a system executable by the formatter name + if is_executable(name) then + return true + end + end + end + + return false + end + + -- === safe format wrapper that no-ops when no formatter found === + local function neoformat_if_available(bufnr) + bufnr = bufnr or 0 + local ft = vim.bo[bufnr].filetype + if not has_formatter_for_ft(ft) then + -- silent fallback: do nothing if no formatter is available + return + end + -- run Neoformat in protected call to avoid blocking save on errors + pcall(vim.cmd, "Neoformat") + end + + -- === keymap and command using the safe wrapper === + vim.keymap.set("n", "f", function() + neoformat_if_available() + end, { noremap = true, silent = true }) + + vim.api.nvim_create_user_command("NeoformatIfAvailable", function() + neoformat_if_available() + end, {}) + + -- === autoreformat on save (uses safe wrapper) === + local format_on_save_filetypes = { + lua = true, + python = true, + javascript = true, + typescript = true, + qml = true, + go = true, + sh = true, + bash = true, + zsh = true, + powershell = false, -- keep off by default (experimental) + } + + vim.api.nvim_create_autocmd("BufWritePre", { + group = vim.api.nvim_create_augroup("NeoformatOnSave", { clear = true }), + callback = function(args) + local ft = vim.bo[args.buf].filetype + if format_on_save_filetypes[ft] then + neoformat_if_available(args.buf) + end + end, + }) + + -- === end config === + end, +} + +return M diff --git a/lua/options.lua b/lua/options.lua index 2e3879f..2d83207 100644 --- a/lua/options.lua +++ b/lua/options.lua @@ -5,6 +5,7 @@ vim.opt.softtabstop = 4 vim.opt.shiftwidth = 4 vim.opt.expandtab = false vim.opt.smartindent = false +--vim.opt.rocks.enabled = false vim.o.list = true vim.opt.listchars = { tab = "··", trail = "·", nbsp = "_" } @@ -13,7 +14,7 @@ vim.opt.wrap = true vim.opt.linebreak = true vim.opt.swapfile = false vim.opt.backup = false -vim.opt.undodir = os.getenv("HOME") .. "/.nvim/undodir" +vim.opt.undodir = vim.fn.stdpath('data') .. '/undodir' vim.opt.undofile = true vim.opt.hlsearch = false vim.opt.incsearch = true diff --git a/lua/plugins/LOKS.lua b/lua/plugins/glowy.lua similarity index 100% rename from lua/plugins/LOKS.lua rename to lua/plugins/glowy.lua diff --git a/lua/plugins/init.lua b/lua/plugins/init.lua index 4fc5afd..6851a6f 100644 --- a/lua/plugins/init.lua +++ b/lua/plugins/init.lua @@ -32,22 +32,6 @@ return { require("config.autosession") end, }, - { - "olimorris/onedarkpro.nvim", - priority = 1000, - config = function() - require("config.themelight") - end, - }, - { - "nvim-telescope/telescope.nvim", - dependencies = { - "nvim-lua/plenary.nvim", - }, - config = function() - require("config.telescope") - end, - }, { "lambdalisue/vim-suda", init = function() @@ -148,14 +132,14 @@ return { { "notken12/base46-colors", }, - -- { - -- "mason-org/mason-lspconfig.nvim", - -- opts = {}, + { + "mason-org/mason-lspconfig.nvim", + -- opts = {}, -- dependencies = { -- { "mason-org/mason.nvim", opts = {} }, -- "neovim/nvim-lspconfig", -- }, - -- }, + }, { "folke/lazydev.nvim", ft = "lua", @@ -197,16 +181,6 @@ return { { "mfussenegger/nvim-jdtls", }, - { - "ThePrimeagen/harpoon", - branch = "harpoon2", - dependencies = { - "nvim-lua/plenary.nvim", - }, - config = function() - require("config.harpoon") - end, - }, { "catgoose/nvim-colorizer.lua", config = function() @@ -255,28 +229,6 @@ return { vim.g.minimal_italic_functions = true end, }, - { - "propet/colorscheme-persist.nvim", - dependencies = { - "nvim-telescope/telescope.nvim", - }, - lazy = false, - config = true, - keys = { - { - "sp", - function() - require("colorscheme-persist").picker() - end, - mode = "n", - }, - }, - opts = { - picker_opts = require("telescope.themes").get_dropdown({ - enable_preview = true, - }), - } - }, { "aserowy/tmux.nvim", config = function() @@ -289,6 +241,16 @@ return { require("config.TID") end, }, + { + "ThePrimeagen/harpoon", + branch = "harpoon2", + dependencies = { + "nvim-lua/plenary.nvim", + }, + config = function() + require("config.harpoon") + end, + }, { "aznhe21/actions-preview.nvim", config = function() @@ -297,9 +259,9 @@ return { }, { "sbdchd/neoformat", - -- config = function() - -- require("config.neoformat") - -- end, + config = function() + require("config.neoformat") + end, }, { "Zacharias-Brohn/zterm-navigator.nvim", diff --git a/lua/plugins/telescope.lua b/lua/plugins/telescope.lua new file mode 100644 index 0000000..38f587f --- /dev/null +++ b/lua/plugins/telescope.lua @@ -0,0 +1,36 @@ +return { + { + "nvim-telescope/telescope.nvim", + dependencies = { + "nvim-lua/plenary.nvim", + }, + config = function() + require("config.telescope") + end, + }, + { + "propet/colorscheme-persist.nvim", + enable = false, + dependencies = { + "nvim-telescope/telescope.nvim", + }, + lazy = false, + config = true, + keys = { + { + "sp", + function() + require("colorscheme-persist").picker() + end, + mode = "n", + }, + }, + opts = function() -- ✅ Changed to function + return { + picker_opts = require("telescope.themes").get_dropdown({ + enable_preview = true, + }), + } + end, + }, +} diff --git a/lua/plugins/themes.lua b/lua/plugins/themes.lua new file mode 100644 index 0000000..fee78a0 --- /dev/null +++ b/lua/plugins/themes.lua @@ -0,0 +1,9 @@ +return { + { + "olimorris/onedarkpro.nvim", + priority = 1000, + config = function() + require("config.themelight") + end, + }, +} diff --git a/scripts/windows_dependencies.ps1 b/scripts/windows_dependencies.ps1 new file mode 100644 index 0000000..831d25c --- /dev/null +++ b/scripts/windows_dependencies.ps1 @@ -0,0 +1,39 @@ +Write-Host "installing required packages for nvim" -foregroundcolor cyan + +$packages = @( + "Neovim.Neovim", + "MartinStorsjo.LLVM-MinGW.MSVCRT", + "zig.zig", + "GnuWin32.Make", + "Rustlang.Rust.MSVC", + "GoLang.Go", + "Kitware.Cmake", + "Ninja-build.Ninja" +) + +foreach ( $package in $packages ) { + Write-Host "Installing $package..." -foregroundcolor yellow + # winget install $package +} + +$list = @( + "Git.Git", + "ajeetdsouza.zoxide", +) + +Write-Host "Module list" -ForegroundColor Magenta +for ($i = 0; $i -lt $list.Count; $i++) { + $index = $i + 1 + Write-Host "$index) $($list[$i])" -ForegroundColor Magenta +} + +Write-Host "Do you want to install the above modules for PowerShell (y/n)? " -ForegroundColor Green -NoNewLine +$answer = Read-Host + +if ($answer -eq 'y' -or $answer -eq 'Y') { + foreach ($module in $list) { + Write-Host "Installing $module..." -ForegroundColor Yellow + # winget install --id $module -e + } + return +}