Initial Neovim configuration

This commit is contained in:
Nitload
2026-10-12 10:02:14 +08:00
commit f07f578dae
19 changed files with 878 additions and 0 deletions
+8
View File
@@ -0,0 +1,8 @@
-- Autocmds are automatically loaded on the VeryLazy event
-- Default autocmds that are always set: https://github.com/LazyVim/LazyVim/blob/main/lua/lazyvim/config/autocmds.lua
--
-- Add any additional autocmds here
-- with `vim.api.nvim_create_autocmd`
--
-- Or remove existing autocmds by their group name (which is prefixed with `lazyvim_` for the defaults)
-- e.g. vim.api.nvim_del_augroup_by_name("lazyvim_wrap_spell")
+66
View File
@@ -0,0 +1,66 @@
-- Keymaps are automatically loaded on the VeryLazy event
-- Default keymaps that are always set: https://github.com/LazyVim/LazyVim/blob/main/lua/lazyvim/config/keymaps.lua
-- Add any additional keymaps here
-- -- F6:选择当前标签页中可见的窗格
local function choose_window()
local api = vim.api
local current = api.nvim_get_current_win()
local items = {}
for _, win in ipairs(api.nvim_tabpage_list_wins(0)) do
local config = api.nvim_win_get_config(win)
if config.focusable ~= false and not config.hide then
local buf = api.nvim_win_get_buf(win)
local ft = vim.bo[buf].filetype
local name = api.nvim_buf_get_name(buf)
local label
if vim.bo[buf].buftype == "terminal" then
label = "终端"
elseif ft == "neo-tree" or ft == "NvimTree" then
label = "文件树"
elseif name ~= "" then
label = vim.fn.fnamemodify(name, ":~:.")
else
label = ft ~= "" and ft or "未命名文件"
end
items[#items + 1] = {
win = win,
label = string.format("%s [%d] %s", win == current and "●" or " ", api.nvim_win_get_number(win), label),
}
end
end
vim.ui.select(items, {
prompt = "切换到窗格",
format_item = function(item)
return item.label
end,
}, function(item)
if not item then
return
end
-- 等选择窗口关闭、恢复焦点后,再进入目标窗格
vim.schedule(function()
if api.nvim_win_is_valid(item.win) then
api.nvim_set_current_win(item.win)
local buf = api.nvim_win_get_buf(item.win)
if vim.bo[buf].buftype == "terminal" then
vim.cmd.startinsert()
end
end
end)
end)
end
vim.api.nvim_create_user_command("ChooseWindow", choose_window, { force = true })
local opts = { desc = "选择窗格", silent = true }
vim.keymap.set("n", "<F6>", "<Cmd>ChooseWindow<CR>", opts)
vim.keymap.set("i", "<F6>", "<Esc><Cmd>ChooseWindow<CR>", opts)
vim.keymap.set("t", "<F6>", "<C-\\><C-n><Cmd>ChooseWindow<CR>", opts)
+53
View File
@@ -0,0 +1,53 @@
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
vim.opt.rtp:prepend(lazypath)
require("lazy").setup({
spec = {
-- add LazyVim and import its plugins
{ "LazyVim/LazyVim", import = "lazyvim.plugins" },
-- import/override with your plugins
{ import = "plugins" },
},
defaults = {
-- By default, only LazyVim plugins will be lazy-loaded. Your custom plugins will load during startup.
-- If you know what you're doing, you can set this to `true` to have all your custom plugins lazy-loaded by default.
lazy = false,
-- It's recommended to leave version=false for now, since a lot the plugin that support versioning,
-- have outdated releases, which may break your Neovim install.
version = false, -- always use the latest git commit
-- version = "*", -- try installing the latest stable version for plugins that support semver
},
install = { colorscheme = { "tokyonight", "habamax" } },
checker = {
enabled = true, -- check for plugin updates periodically
notify = false, -- notify on update
}, -- automatically check for plugin updates
performance = {
rtp = {
-- disable some rtp plugins
disabled_plugins = {
"gzip",
-- "matchit",
-- "matchparen",
-- "netrwPlugin",
"tarPlugin",
"tohtml",
"tutor",
"zipPlugin",
},
},
},
})
+3
View File
@@ -0,0 +1,3 @@
-- Options are automatically loaded before lazy.nvim startup
-- Default options that are always set: https://github.com/LazyVim/LazyVim/blob/main/lua/lazyvim/config/options.lua
-- Add any additional options here
+10
View File
@@ -0,0 +1,10 @@
return {
{
"olimorris/codecompanion.nvim",
dependencies = {
"nvim-lua/plenary.nvim",
"nvim-treesitter/nvim-treesitter",
},
opts = {},
},
}
+12
View File
@@ -0,0 +1,12 @@
return {
{
"neovim/nvim-lspconfig",
opts = {
servers = {
asm_lsp = {
filetypes = { "asm", "nasm", "vmasm" },
},
},
},
},
}
+14
View File
@@ -0,0 +1,14 @@
return {
{
"gbprod/nord.nvim",
lazy = false,
priority = 1000,
opts = {},
},
{
"LazyVim/LazyVim",
opts = {
colorscheme = "nord",
},
},
}
+14
View File
@@ -0,0 +1,14 @@
return {
{
"folke/snacks.nvim",
opts = {
dashboard = {
preset = {
header = [[
NITLOAD NVIM
]],
},
},
},
},
}
+197
View File
@@ -0,0 +1,197 @@
-- since this is just an example spec, don't actually load anything here and return an empty spec
-- stylua: ignore
if true then return {} end
-- every spec file under the "plugins" directory will be loaded automatically by lazy.nvim
--
-- In your plugin files, you can:
-- * add extra plugins
-- * disable/enabled LazyVim plugins
-- * override the configuration of LazyVim plugins
return {
-- add gruvbox
{ "ellisonleao/gruvbox.nvim" },
-- Configure LazyVim to load gruvbox
{
"LazyVim/LazyVim",
opts = {
colorscheme = "gruvbox",
},
},
-- change trouble config
{
"folke/trouble.nvim",
-- opts will be merged with the parent spec
opts = { use_diagnostic_signs = true },
},
-- disable trouble
{ "folke/trouble.nvim", enabled = false },
-- override nvim-cmp and add cmp-emoji
{
"hrsh7th/nvim-cmp",
dependencies = { "hrsh7th/cmp-emoji" },
---@param opts cmp.ConfigSchema
opts = function(_, opts)
table.insert(opts.sources, { name = "emoji" })
end,
},
-- change some telescope options and a keymap to browse plugin files
{
"nvim-telescope/telescope.nvim",
keys = {
-- add a keymap to browse plugin files
-- stylua: ignore
{
"<leader>fp",
function() require("telescope.builtin").find_files({ cwd = require("lazy.core.config").options.root }) end,
desc = "Find Plugin File",
},
},
-- change some options
opts = {
defaults = {
layout_strategy = "horizontal",
layout_config = { prompt_position = "top" },
sorting_strategy = "ascending",
winblend = 0,
},
},
},
-- add pyright to lspconfig
{
"neovim/nvim-lspconfig",
---@class PluginLspOpts
opts = {
---@type lspconfig.options
servers = {
-- pyright will be automatically installed with mason and loaded with lspconfig
pyright = {},
},
},
},
-- add tsserver and setup with typescript.nvim instead of lspconfig
{
"neovim/nvim-lspconfig",
dependencies = {
"jose-elias-alvarez/typescript.nvim",
init = function()
require("lazyvim.util").lsp.on_attach(function(_, buffer)
-- stylua: ignore
vim.keymap.set( "n", "<leader>co", "TypescriptOrganizeImports", { buffer = buffer, desc = "Organize Imports" })
vim.keymap.set("n", "<leader>cR", "TypescriptRenameFile", { desc = "Rename File", buffer = buffer })
end)
end,
},
---@class PluginLspOpts
opts = {
---@type lspconfig.options
servers = {
-- tsserver will be automatically installed with mason and loaded with lspconfig
tsserver = {},
},
-- you can do any additional lsp server setup here
-- return true if you don't want this server to be setup with lspconfig
---@type table<string, fun(server:string, opts:_.lspconfig.options):boolean?>
setup = {
-- example to setup with typescript.nvim
tsserver = function(_, opts)
require("typescript").setup({ server = opts })
return true
end,
-- Specify * to use this function as a fallback for any server
-- ["*"] = function(server, opts) end,
},
},
},
-- for typescript, LazyVim also includes extra specs to properly setup lspconfig,
-- treesitter, mason and typescript.nvim. So instead of the above, you can use:
{ import = "lazyvim.plugins.extras.lang.typescript" },
-- add more treesitter parsers
{
"nvim-treesitter/nvim-treesitter",
opts = {
ensure_installed = {
"bash",
"html",
"javascript",
"json",
"lua",
"markdown",
"markdown_inline",
"python",
"query",
"regex",
"tsx",
"typescript",
"vim",
"yaml",
},
},
},
-- since `vim.tbl_deep_extend`, can only merge tables and not lists, the code above
-- would overwrite `ensure_installed` with the new value.
-- If you'd rather extend the default config, use the code below instead:
{
"nvim-treesitter/nvim-treesitter",
opts = function(_, opts)
-- add tsx and treesitter
vim.list_extend(opts.ensure_installed, {
"tsx",
"typescript",
})
end,
},
-- the opts function can also be used to change the default opts:
{
"nvim-lualine/lualine.nvim",
event = "VeryLazy",
opts = function(_, opts)
table.insert(opts.sections.lualine_x, {
function()
return "😄"
end,
})
end,
},
-- or you can return new options to override all the defaults
{
"nvim-lualine/lualine.nvim",
event = "VeryLazy",
opts = function()
return {
--[[add your custom lualine config here]]
}
end,
},
-- use mini.starter instead of alpha
{ import = "lazyvim.plugins.extras.ui.mini-starter" },
-- add jsonls and schemastore packages, and setup treesitter for json, json5 and jsonc
{ import = "lazyvim.plugins.extras.lang.json" },
-- add any tools you want to have installed below
{
"williamboman/mason.nvim",
opts = {
ensure_installed = {
"stylua",
"shellcheck",
"shfmt",
"flake8",
},
},
},
}
+15
View File
@@ -0,0 +1,15 @@
return {
{
"folke/snacks.nvim",
opts = {
picker = {
sources = {
explorer = {
hidden = true,
ignored = false,
},
},
},
},
},
}
+155
View File
@@ -0,0 +1,155 @@
return {
{
"nvzone/menu",
dependencies = { "nvzone/volt" },
keys = {
{
"<F4>",
function()
require("menu").open(_G.YoumuMenu, { border = true })
end,
mode = "n",
desc = "打开主菜单",
},
{
"<F4>",
"<Esc><Cmd>lua require('menu').open(_G.YoumuMenu, { border = true })<CR>",
mode = "i",
desc = "打开主菜单",
},
{
"<F4>",
"<C-\\><C-n><Cmd>lua require('menu').open(_G.YoumuMenu, { border = true })<CR>",
mode = "t",
desc = "打开主菜单",
},
},
config = function()
-- 菜单关闭并恢复原窗口后,调用现有快捷键。
-- 与直接按键使用同一套 LazyVim 功能。
local function run_keys(keys)
return function()
vim.schedule(function()
local input = vim.api.nvim_replace_termcodes(keys, true, false, true)
vim.api.nvim_feedkeys(input, "m", false)
end)
end
end
local function item(name, keys)
return {
name = name,
rtxt = keys,
cmd = run_keys(keys),
}
end
_G.YoumuMenu = {
{
name = "文件",
keybind = "f",
items = {
item("查找项目文件", "<leader><space>"),
item("已打开的文件", "<leader>,"),
item("保存当前文件", "<C-s>"),
{
name = "保存全部",
cmd = "wall",
},
item("关闭当前文件", "<leader>bd"),
item("关闭其他文件", "<leader>bo"),
{
name = "退出 Neovim",
cmd = "confirm qa",
},
},
},
{
name = "代码",
keybind = "c",
items = {
item("跳转到定义", "gd"),
item("查找引用", "gr"),
item("查看文档", "K"),
item("重命名符号", "<leader>cr"),
item("代码操作", "<leader>ca"),
item("格式化文件", "<leader>cf"),
item("当前文件符号", "<leader>ss"),
item("查看诊断", "<leader>cd"),
},
},
{
name = "视图",
keybind = "v",
items = {
item("文件树", "<leader>e"),
item("项目终端", "<leader>ft"),
item("向右分屏", "<leader>|"),
item("向下分屏", "<leader>-"),
item("最大化/还原窗格", "<leader>wm"),
item("上一个文件", "<A-Left>"),
item("下一个文件", "<A-Right>"),
},
},
{
name = "设置",
keybind = "s",
items = {
item("搜索快捷键", "<leader>sk"),
item("搜索命令", "<leader>sC"),
item("选择主题", "<leader>uC"),
{
name = "插件管理",
cmd = "Lazy",
},
{
name = "语言工具管理",
cmd = "Mason",
},
},
{
name = "切换工作区域",
rtxt = "w",
cmd = function()
vim.schedule(function()
vim.cmd("ChooseWindow")
end)
end,
},
},
}
-- 只修改菜单窗口的按键,不影响代码编辑。
vim.api.nvim_create_autocmd("FileType", {
group = vim.api.nvim_create_augroup("YoumuMenuNavigation", { clear = true }),
pattern = "NvMenu",
callback = function(event)
local opts = {
buffer = event.buf,
silent = true,
}
vim.keymap.set("n", "<Up>", "k", opts)
vim.keymap.set("n", "<Down>", "j", opts)
local remap_opts = {
buffer = event.buf,
silent = true,
remap = true,
}
-- 复用菜单自身的操作,包含关闭后的焦点恢复。
vim.keymap.set("n", "<Left>", "h", remap_opts)
vim.keymap.set("n", "<Right>", "<CR>", remap_opts)
vim.keymap.set("n", "<F4>", "q", remap_opts)
end,
})
end,
},
}