187 lines
6.5 KiB
Lua
187 lines
6.5 KiB
Lua
-- ~/.config/nvim/init.lua
|
|
|
|
-- =============================================================================
|
|
-- 0. LANGUAGE SETTINGS (Set UI to English)
|
|
-- =============================================================================
|
|
vim.opt.langmenu = "en_US.UTF-8"
|
|
pcall(vim.cmd, "language en_US.UTF-8")
|
|
|
|
-- =============================================================================
|
|
-- 1. BOOTSTRAP PAQ (Plugin Manager Installation)
|
|
-- =============================================================================
|
|
local data_path = vim.fn.stdpath("data") .. "/site/pack/paqs/start/"
|
|
local paq_path = data_path .. "paq-nvim"
|
|
|
|
if vim.fn.empty(vim.fn.glob(paq_path)) > 0 then
|
|
print("Installing Paq...")
|
|
vim.fn.system({ "git", "clone", "--depth=1", "https://github.com/savq/paq-nvim.git", paq_path })
|
|
vim.cmd("packadd paq-nvim")
|
|
end
|
|
|
|
-- =============================================================================
|
|
-- 2. LOAD PLUGINS & AUTO-INSTALL
|
|
-- =============================================================================
|
|
local plugins = require("plugins")
|
|
local paq = require("paq")
|
|
paq(plugins)
|
|
|
|
local missing_plugins = false
|
|
for _, plugin in ipairs(plugins) do
|
|
local plugin_name = type(plugin) == "table" and plugin[1] or plugin
|
|
local name = plugin_name:match(".*/(.*)")
|
|
if name and vim.fn.empty(vim.fn.glob(data_path .. name)) > 0 then
|
|
missing_plugins = true
|
|
break
|
|
end
|
|
end
|
|
|
|
if missing_plugins then
|
|
print("New plugins found. Installing... Please restart Neovim afterwards.")
|
|
paq.install()
|
|
end
|
|
|
|
-- =============================================================================
|
|
-- 3. EDITOR OPTIONS (A11y / Screenreader optimized)
|
|
-- =============================================================================
|
|
local opt = vim.opt
|
|
opt.number = false
|
|
opt.relativenumber = false
|
|
opt.showcmd = false
|
|
opt.laststatus = 0
|
|
opt.ruler = false
|
|
opt.showmode = false
|
|
opt.mouse = ""
|
|
opt.shortmess:append("atI")
|
|
opt.hidden = true
|
|
opt.termguicolors = true -- Important for modern LSPs/UI
|
|
|
|
-- =============================================================================
|
|
-- 4. DIAGNOSTICS (Error display)
|
|
-- =============================================================================
|
|
vim.diagnostic.config({
|
|
virtual_text = false, -- No text noise in the line
|
|
underline = true, -- Errors are underlined
|
|
signs = false, -- No icons on the edge (less noise)
|
|
update_in_insert = false,
|
|
})
|
|
|
|
-- =============================================================================
|
|
-- 5. KEYMAPS (Leader: Space)
|
|
-- =============================================================================
|
|
vim.g.mapleader = " "
|
|
|
|
-- Open error list (Quickfix)
|
|
vim.keymap.set("n", "<leader>e", vim.diagnostic.setqflist, { desc = "Show error list" })
|
|
|
|
-- Open dashboard
|
|
vim.keymap.set("n", "<leader>b", function()
|
|
local ok, dashboard = pcall(require, "config.dashboard")
|
|
if ok then dashboard.open() else print("Dashboard not found!") end
|
|
end, { desc = "Back to dashboard" })
|
|
|
|
-- Core Update
|
|
local ok_up, updater = pcall(require, "core.update")
|
|
if ok_up then
|
|
vim.keymap.set("n", "<leader>U", updater.update, { desc = "Update MonoVim Core" })
|
|
end
|
|
|
|
-- =============================================================================
|
|
-- 6. MASON & LSP SETUP (DELAYED FOR STABILITY)
|
|
-- =============================================================================
|
|
vim.schedule(function()
|
|
local ok_mason, mason = pcall(require, "mason")
|
|
local ok_mason_lsp, mason_lspconfig = pcall(require, "mason-lspconfig")
|
|
local ok_lspconfig, lspconfig = pcall(require, "lspconfig")
|
|
|
|
if ok_mason and ok_mason_lsp and ok_lspconfig then
|
|
mason.setup({
|
|
ui = { border = "rounded" }
|
|
})
|
|
|
|
mason_lspconfig.setup({
|
|
ensure_installed = { "basedpyright", "rust_analyzer", "lua_ls" },
|
|
})
|
|
|
|
-- Security check: Does the function really exist?
|
|
if mason_lspconfig.setup_handlers then
|
|
mason_lspconfig.setup_handlers({
|
|
-- Default handler for each installed server
|
|
function(server_name)
|
|
local opts = {}
|
|
|
|
-- If nvim-cmp is used for autocompletion
|
|
local ok_cmp, cmp_lsp = pcall(require, "cmp_nvim_lsp")
|
|
if ok_cmp then
|
|
opts.capabilities = cmp_lsp.default_capabilities()
|
|
end
|
|
|
|
lspconfig[server_name].setup(opts)
|
|
end,
|
|
|
|
-- Special configuration for Lua (prevents 'vim' warnings)
|
|
["lua_ls"] = function()
|
|
lspconfig.lua_ls.setup({
|
|
settings = {
|
|
Lua = {
|
|
diagnostics = { globals = { "vim" } }
|
|
}
|
|
}
|
|
})
|
|
end,
|
|
})
|
|
end
|
|
end
|
|
end)
|
|
local ok_oil, oil = pcall(require, "oil")
|
|
if ok_oil then
|
|
oil.setup({
|
|
default_file_explorer = true,
|
|
columns = { "icon" }, -- You can also delete "icon" for pure text
|
|
view_options = {
|
|
show_hidden = true,
|
|
},
|
|
})
|
|
-- Keymap: Space + f (File)
|
|
vim.keymap.set("n", "<leader>f", "<CMD>Oil<CR>", { desc = "Open File Manager" })
|
|
end
|
|
-- =============================================================================
|
|
-- 7. BUFFER MANAGEMENT & DASHBOARD LOGIC
|
|
-- =============================================================================
|
|
local ok_mini, bufremove = pcall(require, "mini.bufremove")
|
|
if ok_mini then bufremove.setup({}) end
|
|
|
|
local function force_dashboard()
|
|
vim.schedule(function()
|
|
local listed = vim.fn.getbufinfo({buflisted = 1})
|
|
if #listed == 0 or (#listed == 1 and listed[1].name == "" and vim.bo[listed[1].bufnr].filetype == "") then
|
|
local ok_dash, dashboard = pcall(require, "config.dashboard")
|
|
if ok_dash then dashboard.open() end
|
|
end
|
|
end)
|
|
end
|
|
|
|
-- Close buffer (integrated save prompt)
|
|
vim.keymap.set("n", "<leader>d", function()
|
|
if vim.bo.modified then
|
|
local choice = vim.fn.confirm("Save changes?", "&Yes\n&No\n&Cancel", 1)
|
|
if choice == 1 then
|
|
vim.cmd("write")
|
|
elseif choice == 3 then
|
|
return
|
|
end
|
|
end
|
|
|
|
if ok_mini then
|
|
bufremove.delete(0, true)
|
|
else
|
|
vim.cmd("bd!")
|
|
end
|
|
end, { desc = "Close buffer" })
|
|
|
|
-- Autocommands for Dashboard (on startup and when deleting buffers)
|
|
vim.api.nvim_create_autocmd({ "VimEnter", "BufDelete" }, {
|
|
callback = function()
|
|
force_dashboard()
|
|
end
|
|
})
|