commit a296f56268c3b404a7c80353c4a1a4e8da627935 Author: newbieQQ Date: Wed Jun 10 16:59:38 2026 +0800 initial: snapshot from ~/.config/nvim diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e033bc6 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +lazy-lock.json diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..8bb8747 --- /dev/null +++ b/init.lua @@ -0,0 +1,46 @@ +G = require('G') + +if not G.g.vscode then + + local lazypath = G.fn.stdpath("data") .. "/lazy/lazy.nvim" + + if not G.loop.fs_stat(lazypath) then + G.fn.system({ + "git", + "clone", + "--filter=blob:none", + "https://github.com/folke/lazy.nvim.git", + "--branch=stable", + lazypath, + }) + + + G.fn.system({ + "git", + "config", + "--global", + "credential.helper", + "store", + }) + end + + G.opt.rtp:prepend(lazypath) + + require("keymap") + + + if G.g.vscode then + require('vscode') + else + require("options") + local clone_prefix = G.use_ssh and "git@github.com:%s.git" or "https://github.com/%s.git" + require("lazy").setup( + require('plugs'), { + lockfile = G.fn.stdpath("data") .. "/lazy/lazy-lock.json", + git = { + url_format = clone_prefix, + } + } + ) + end +end diff --git a/lua/G.lua b/lua/G.lua new file mode 100644 index 0000000..6fe8152 --- /dev/null +++ b/lua/G.lua @@ -0,0 +1,59 @@ +local G = {} + +G.use_ssh = false + +G.g = vim.g +G.b = vim.b +G.o = vim.o +G.fn = vim.fn +G.api = vim.api +G.opt = vim.opt +G.loop = vim.loop +G.lb = vim.lsp.buf +G.dic = vim.diagnostic +G.cgp = vim.nvim_create_augroup + +function G.map(maps) + for _, map in pairs(maps) do + if #map == 3 then + vim.keymap.set(map[1], map[2], map[3], { noremap = true }) + elseif #map == 4 then + vim.keymap.set(map[1], map[2], map[3], map[4]) + else + print("太多变量了") + end + --G.api.nvim_set_keymap(map[1], map[2], map[3], map[4]) + end +end + +function G.delmap(maps) + for _, map in pairs(maps) do + if #map == 2 then + vim.keymap.del(map[1], map[2], {}) + elseif #map == 3 then + vim.keymap.del(map[1], map[2], map[3]) + else + print("太多变量了") + end + end +end + +function G.cmd(cmd) + G.api.nvim_command(cmd) +end + +function G.exec(c) + G.api.nvim_exec(c) +end + +function G.eval(c) + return G.api.nvim_eval(c) +end + +function G.au(even, opts) + return G.api.nvim_create_autocmd(even, opts) +end + +G.g.mapleader = ' ' + +return G diff --git a/lua/keymap.lua b/lua/keymap.lua new file mode 100644 index 0000000..9b04fd1 --- /dev/null +++ b/lua/keymap.lua @@ -0,0 +1,46 @@ +local opt = { noremap = true } + +-- base +G.map({ + { 'n', 'nh', ':nohlsearch', opt }, + { 'n', 'rp', ':%s/', opt }, + + { 'v', 'L', '$', opt }, + { 'v', 'H', '^', opt }, + { 'n', 'L', '$', opt }, + { 'n', 'H', '^', opt }, + { 'v', '>', '>gv', opt }, + { 'v', '<', '', '>>', opt }, + { 'n', '<', '<<', opt }, + { 'n', '?', ':set hlsearch?', opt }, + { 'n', '/', ':set hlsearch/', opt }, + + { 'n', '', ':tabn', opt }, + { 'n', '', ':tabp', opt }, + + + { 'n', '', 'j', opt }, + { 'n', '', 'h', opt }, + { 'n', '', 'k', opt }, + { 'n', '', 'l', opt }, + + + { 'n', '', ':q', opt }, + { 'n', '', ':w !sudo tee %', opt }, + { 'n', '', ':q!', opt }, + { 'v', '', '"+y', opt }, + + + + { 'n', 'y', 'ggyG', opt }, + { 'n', 'p', 'ggpG', opt }, + { 'n', 'v', 'ggVG', opt }, + + { 'n', '', ':res -5', opt }, + { 'n', '', ':res +5', opt }, + { 'n', '', ':vertical resize -5', opt }, + { 'n', '', ':vertical resize +5', opt }, + +}) diff --git a/lua/lsp/basedpyright.lua b/lua/lsp/basedpyright.lua new file mode 100644 index 0000000..3be769f --- /dev/null +++ b/lua/lsp/basedpyright.lua @@ -0,0 +1,22 @@ +return { + -- capabilities = require("cmp_nvim_lsp").default_capabilities(), + settings = { + basedpyright = { + analysis = { + autoSearchPaths = true, + diagnosticMode = "openFilesOnly", + useLibraryCodeForTypes = true, + typeCheckingMode = "standard" + }, + }, + }, + on_attach = function() + G.api.nvim_create_user_command('R', function() + G.cmd [[set splitbelow]] + G.cmd [[sp]] + G.cmd [[term python3 %]] + G.cmd [[resize 10]] + G.cmd [[startinsert]] + end, {}) + end +} diff --git a/lua/lsp/bash.lua b/lua/lsp/bash.lua new file mode 100644 index 0000000..74c9c6a --- /dev/null +++ b/lua/lsp/bash.lua @@ -0,0 +1,11 @@ +return{ + on_attach = function() + G.api.nvim_create_user_command('R', function() + G.cmd [[set splitbelow]] + G.cmd [[sp]] + G.cmd [[term sh %]] + G.cmd [[resize 10]] + G.cmd [[startinsert]] + end, {}) + end +} diff --git a/lua/lsp/c.lua b/lua/lsp/c.lua new file mode 100644 index 0000000..b34d457 --- /dev/null +++ b/lua/lsp/c.lua @@ -0,0 +1,11 @@ +return { + on_attach = function() + G.api.nvim_create_user_command('R', function() + G.cmd [[set splitbelow]] + G.cmd [[sp]] + G.cmd [[term g++ "%" -o "%<" && ./"%<" && rm "%<"]] + G.cmd [[resize 10]] + G.cmd [[startinsert]] + end, {}) + end +} diff --git a/lua/lsp/go.lua b/lua/lsp/go.lua new file mode 100644 index 0000000..4b7eef4 --- /dev/null +++ b/lua/lsp/go.lua @@ -0,0 +1,18 @@ +return { + on_attach = function() + G.api.nvim_create_user_command('R', function() + G.cmd [[set splitbelow]] + G.cmd [[sp]] + G.cmd [[term go run %]] + G.cmd [[resize 10]] + G.cmd [[startinsert]] + end, {}) + G.api.nvim_create_user_command('Rgin', function() + G.cmd [[set splitbelow]] + G.cmd [[sp]] + G.cmd [[term go run ./main.go]] + G.cmd [[resize 10]] + G.cmd [[startinsert]] + end, {}) + end +} diff --git a/lua/lsp/json.lua b/lua/lsp/json.lua new file mode 100644 index 0000000..a6cd7dd --- /dev/null +++ b/lua/lsp/json.lua @@ -0,0 +1,4 @@ +return { + on_attach = function() + end +} diff --git a/lua/lsp/lua.lua b/lua/lsp/lua.lua new file mode 100644 index 0000000..fdd0fde --- /dev/null +++ b/lua/lsp/lua.lua @@ -0,0 +1,32 @@ +local runtime_path = vim.split(package.path, ';') + +table.insert(runtime_path, "lua/?.lua") +table.insert(runtime_path, "lua/?/init.lua") + +return { + + capabilities = require('cmp_nvim_lsp').default_capabilities(), + + settings = { + + Lua = { + runtime = { + -- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim) + version = 'LuaJIT', + -- Setup your lua path + path = runtime_path, + }, + diagnostics = { + globals = {'vim', 'G', 'yield', 'Candidate'}, + }, + workspace = { + -- Make the server aware of Neovim runtime files + library = vim.api.nvim_get_runtime_file("", true), + }, + -- Do not send telemetry data containing a randomized but unique identifier + telemetry = { + enable = false + }, + }, + }, +} diff --git a/lua/lsp/markdown.lua b/lua/lsp/markdown.lua new file mode 100644 index 0000000..97aeadd --- /dev/null +++ b/lua/lsp/markdown.lua @@ -0,0 +1,2 @@ +return { +} diff --git a/lua/lsp/pyright.lua b/lua/lsp/pyright.lua new file mode 100644 index 0000000..d0898f9 --- /dev/null +++ b/lua/lsp/pyright.lua @@ -0,0 +1,11 @@ +return { + on_attach = function() + G.api.nvim_create_user_command('R', function() + G.cmd [[set splitbelow]] + G.cmd [[sp]] + G.cmd [[term python3 %]] + G.cmd [[resize 10]] + G.cmd [[startinsert]] + end, {}) + end +} diff --git a/lua/lsp/yaml.lua b/lua/lsp/yaml.lua new file mode 100644 index 0000000..7990cc8 --- /dev/null +++ b/lua/lsp/yaml.lua @@ -0,0 +1,12 @@ +return { + capabilities = require('cmp_nvim_lsp').default_capabilities(), + settings = { + yaml = { + schemas = { + ["https://json.schemastore.org/github-workflow.json"] = "/.github/workflows/*", + ["../path/relative/to/file.yml"] = "/.github/workflows/*", + ["/path/from/root/of/project"] = "/.github/workflows/*", + }, + }, + } +} diff --git a/lua/options.lua b/lua/options.lua new file mode 100644 index 0000000..1a7ef51 --- /dev/null +++ b/lua/options.lua @@ -0,0 +1,91 @@ +-- +G.opt.ttimeout = true +G.opt.ttimeoutlen = 100 + +-- 行号 +G.opt.nu = true +G.opt.rnu = true +G.opt.scrolloff = 999 + +-- 自动保存 +G.opt.autowrite = true +G.opt.autowriteall = true + +-- tab键 +G.opt.sw = 2 +G.opt.ts = 2 +G.opt.softtabstop = 2 +G.opt.smarttab = true +G.opt.expandtab = true +G.opt.autoindent = true + +-- 光标 +G.opt.cursorline = true + +-- 分屏 +G.opt.splitright = true +G.opt.splitbelow = true + +-- 搜索 +G.opt.ignorecase = true +G.opt.incsearch = true + +-- 不换行 +G.opt.textwidth = 999 +G.opt.wrap = false + + +-- 文件判断 +G.cmd("filetype plugin indent on") + +-- 取消换行注释 +G.au({ "BufEnter" }, { + pattern = { "*" }, + callback = function() + -- vim.opt.formatoptions = vim.opt.formatoptions - { "c", "r", "o" } + G.opt.formatoptions = G.opt.formatoptions + - "o" -- O and o, don't continue comments + + "r" -- But do continue when pressing enter. + end, +}) + +G.au({ "InsertEnter" }, { + pattern = { "*" }, + callback = function() + G.opt.hlsearch = false + end, +}) + +G.au({ "VimEnter", "BufEnter" }, { + pattern = { "*.code-snippets" }, + callback = function() + G.cmd("setfiletype json") + end, +}) + +-- G.au({ +-- {"CmdlineEnter"}, +-- { +-- if index +-- } +-- }) + + +local function isempty(s) + return s == nil or s == "" +end + +local function use_if_defined(val, fallback) + return val ~= nil and val or fallback +end + + +local conda_prefix = os.getenv("CONDA_PREFIX") +if not isempty(conda_prefix) then + vim.g.python_host_prog = use_if_defined(vim.g.python_host_prog, conda_prefix .. "/bin/python") + vim.g.python3_host_prog = use_if_defined(vim.g.python3_host_prog, conda_prefix .. "/bin/python") +else + vim.g.python_host_prog = use_if_defined(vim.g.python_host_prog, "python") + vim.g.python3_host_prog = use_if_defined(vim.g.python3_host_prog, "python3") +end + diff --git a/lua/plugs.lua b/lua/plugs.lua new file mode 100644 index 0000000..586ff2b --- /dev/null +++ b/lua/plugs.lua @@ -0,0 +1,32 @@ +return { + + require('plugs.nvim-lspconfig'), + require('plugs.nvimtree'), -- nvimtree + require('plugs.theme'), -- theme + require("plugs.edit-plugs"), + require("plugs.dev"), + + + -- leetcode刷题 + -- { + -- "kawre/leetcode.nvim", + -- build = ":TSUpdate html", + -- dependencies = { + -- "nvim-telescope/telescope.nvim", + -- "nvim-lua/plenary.nvim", -- telescope 所需 + -- "MunifTanjim/nui.nvim", + + -- -- 可选 + -- "nvim-treesitter/nvim-treesitter", + -- "rcarriga/nvim-notify", + -- "nvim-tree/nvim-web-devicons", + -- }, + -- opts = { + -- -- 配置放在这里 + -- cn = { + -- enabled = true, + -- }, + -- }, + -- }, + +} diff --git a/lua/plugs/dev.lua b/lua/plugs/dev.lua new file mode 100644 index 0000000..e332706 --- /dev/null +++ b/lua/plugs/dev.lua @@ -0,0 +1,51 @@ +return { + 'lilydjwg/colorizer', -- 颜色识别 + -- "rest-nvim/rest.nvim", + -- dependencies = { { "nvim-lua/plenary.nvim" } }, + -- config = function() + -- require("rest-nvim").setup({ + -- --- Get the same options from Packer setup + -- }) + -- end + -- }, + -- { + -- -- go开发 + -- "ray-x/go.nvim", + -- dependencies = { -- optional packages + -- "ray-x/guihua.lua", + -- "neovim/nvim-lspconfig", + -- "nvim-treesitter/nvim-treesitter", + -- }, + -- config = function() + -- require("go").setup() + -- end, + -- -- event = { "CmdlineEnter" }, + -- ft = { "go", 'gomod' }, + -- build = ':lua require("go.install").update_all_sync()' -- if you need to install/update all binaries + -- }, + { + -- conda 环境 + "kmontocam/nvim-conda", + dependencies = { "nvim-lua/plenary.nvim" }, + }, + { + -- 终端 + 'akinsho/toggleterm.nvim', + version = "*", + config = function() + require("toggleterm").setup { + -- size can be a number or function which is passed the current terminal + size = 10, + open_mapping = [[]], + hide_numbers = true, -- hide the number column in toggleterm buffers + shade_filetypes = {}, + shade_terminals = true, + shading_factor = 1, -- the degree by which to darken to terminal colour, default: 1 for dark backgrounds, 3 for light + start_in_insert = true, + insert_mappings = true, -- whether or not the open mapping applies in insert mode + persist_size = true, + direction = 'horizontal', + } + end + } +} diff --git a/lua/plugs/edit-plugs.lua b/lua/plugs/edit-plugs.lua new file mode 100644 index 0000000..d7fe61b --- /dev/null +++ b/lua/plugs/edit-plugs.lua @@ -0,0 +1,109 @@ +return { + 'vijaymarupudi/nvim-fzf', -- fzf + { + -- surround 和 wildfire 配合有神奇的效果 + 'tpope/vim-surround', + 'gcmt/wildfire.vim', + + -- 括号箭头 + 'yaocccc/nvim-hlchunk', + + }, + -- 多光标 + { + 'terryma/vim-multiple-cursors', + }, + { + --格式整理 + { + 'junegunn/vim-easy-align', + config = function() + G.map({ + { "v", "ga", ":EasyAlign", { noremap = true } }, + { "v", "=", ":EasyAlign", { noremap = true } }, + }) + end + }, + }, + { + -- 注释插件 + { + 'tpope/vim-commentary', + } + }, + { + 'github/copilot.vim', -- github copilot + }, + { + 'windwp/nvim-autopairs', + event = "InsertEnter", + opts = {}, -- this is equalent to setup({}) function + config = function() + require('nvim-autopairs').setup({ + disable_filetype = { "vim" }, + }) + end + }, + -- { + -- 'kevinhwang91/nvim-ufo', + -- dependencies = { + -- 'kevinhwang91/promise-async' + -- }, + -- config = function () + -- require("ufo").setup() + -- end + + -- }, + { + -- hop + "phaazon/hop.nvim", + branch = "v2", + keys = { + "f", "F", "t", "T", + "" + }, + lazy = true, + config = function() + require("hop").setup { keys = 'asdfghjkl;' } + local hop = require('hop') + local directions = require('hop.hint').HintDirection + G.map({ + { "n", "", ":HopChar2MW", { noremap = true } }, + { "n", "f", + function() + hop.hint_char1({ + direction = directions.AFTER_CURSOR, + current_line_only = true + }) + end, { noremap = true } + }, + { "n", "F", + function() + hop.hint_char1({ + direction = directions.BEFORE_CURSOR, + current_line_only = true + }) + end, { noremap = true } + }, + { "n", "t", + function() + hop.hint_char1({ + direction = directions.AFTER_CURSOR, + current_line_only = true, + hint_offset = -1 + }) + end, { noremap = true } + }, + { "n", "T", + function() + hop.hint_char1({ + direction = directions.BEFORE_CURSOR, + current_line_only = true, + hint_offset = -1 + }) + end, { noremap = true } + }, + }) + end + } +} diff --git a/lua/plugs/nvim-lspconfig.lua b/lua/plugs/nvim-lspconfig.lua new file mode 100644 index 0000000..9edd0b6 --- /dev/null +++ b/lua/plugs/nvim-lspconfig.lua @@ -0,0 +1,352 @@ +return { + { + -- lsp的config + "neovim/nvim-lspconfig", + dependencies = { + "folke/neodev.nvim", + }, + config = function() + require 'neodev'.setup {} + + -- 定义需要启用的服务器列表及其对应的配置 + local servers = { + lua_ls = require('lsp.lua'), + clangd = require('lsp.c'), + bashls = require('lsp.bash'), + basedpyright = require('lsp.basedpyright'), + yamlls = require('lsp.yaml'), + gopls = require('lsp.go'), + jsonls = require('lsp.json'), + } + + -- 使用 Neovim 0.11+ 的新 API 进行配置和启用 + for server, config in pairs(servers) do + vim.lsp.config(server, config) + vim.lsp.enable(server) + end + -- require 'lspconfig'.lua_ls.setup(require('lsp.lua')) + -- require 'lspconfig'.clangd.setup(require('lsp.c')) + -- require 'lspconfig'.bashls.setup(require('lsp.bash')) + -- require 'lspconfig'.basedpyright.setup(require('lsp.basedpyright')) + -- require 'lspconfig'.yamlls.setup(require('lsp.yaml')) + -- require 'lspconfig'.gopls.setup(require('lsp.go')) + -- require 'lspconfig'.jsonls.setup(require('lsp.json')) + + + G.map({ + + { 'n', 'rn', 'lua vim.lsp.buf.rename()' }, + + { 'n', 'gd', 'lua vim.lsp.buf.definition()' }, + { 'n', 'gh', 'lua vim.lsp.buf.hover()' }, + { 'n', 'gD', 'lua vim.lsp.buf.declaration()' }, + { 'n', 'gi', 'lua vim.lsp.buf.implementation()' }, + { 'n', 'gr', 'lua vim.lsp.buf.references()' }, + { 'n', '', 'lua vim.lsp.buf.format()' }, + + }) + end + + }, + { + -- lsp + "williamboman/mason-lspconfig.nvim", + dependencies = { + "williamboman/mason.nvim", -- lsp 下载器 + }, + config = function() + require "mason".setup { + ui = { + icons = { + package_installed = "✓", + package_pending = "➜", + package_uninstalled = "✗" + } + } + } + require("mason-lspconfig").setup({ + ensure_installed = { + "bashls", + -- "basedpyright", + "lua_ls", + "jsonls", + "yamlls", + } + }) + end + }, + { -- + 'simrat39/symbols-outline.nvim', + config = function() + local opts = { + highlight_hovered_item = true, + show_guides = true, + auto_preview = false, + position = 'right', + relative_width = true, + width = 25, + auto_close = false, + show_numbers = false, + show_relative_numbers = false, + show_symbol_details = true, + preview_bg_highlight = 'Pmenu', + autofold_depth = nil, + auto_unfold_hover = true, + fold_markers = { '', '' }, + wrap = false, + keymaps = { -- These keymaps can be a string or a table for multiple keys + close = { "", "q" }, + goto_location = "", + focus_location = "h", + hover_symbol = "", + toggle_preview = "K", + rename_symbol = "r", + code_actions = "a", + fold = "o", + unfold = "l", + fold_all = "W", + unfold_all = "E", + fold_reset = "R", + }, + lsp_blacklist = {}, + symbol_blacklist = {}, + symbols = { + File = { icon = "", hl = "@text.uri" }, + Module = { icon = "", hl = "@namespace" }, + Namespace = { icon = "", hl = "@namespace" }, + Package = { icon = "", hl = "@namespace" }, + Class = { icon = "𝓒", hl = "@type" }, + Method = { icon = "ƒ", hl = "@method" }, + Property = { icon = "", hl = "@method" }, + Field = { icon = "", hl = "@field" }, + Constructor = { icon = "", hl = "@constructor" }, + Enum = { icon = "ℰ", hl = "@type" }, + Interface = { icon = "ﰮ", hl = "@type" }, + Function = { icon = "", hl = "@function" }, + Variable = { icon = "", hl = "@constant" }, + Constant = { icon = "", hl = "@constant" }, + String = { icon = "𝓐", hl = "@string" }, + Number = { icon = "#", hl = "@number" }, + Boolean = { icon = "⊨", hl = "@boolean" }, + Array = { icon = "", hl = "@constant" }, + Object = { icon = "⦿", hl = "@type" }, + Key = { icon = "🔐", hl = "@type" }, + Null = { icon = "NULL", hl = "@type" }, + EnumMember = { icon = "", hl = "@field" }, + Struct = { icon = "𝓢", hl = "@type" }, + Event = { icon = "🗲", hl = "@type" }, + Operator = { icon = "+", hl = "@operator" }, + TypeParameter = { icon = "𝙏", hl = "@parameter" }, + Component = { icon = "", hl = "@function" }, + Fragment = { icon = "", hl = "@constant" }, + }, + } + require("symbols-outline").setup(opts) + G.map({ + { "n", "", "SymbolsOutline", { noremap = true } }, + }) + end + }, + { + -- lsp补全 + { + "hrsh7th/nvim-cmp", + dependencies = { + 'hrsh7th/cmp-nvim-lsp', -- { name = 'nvim_lua' } + 'hrsh7th/cmp-buffer', -- { name = 'buffer' }, + 'hrsh7th/cmp-path', -- { name = 'path' } + 'hrsh7th/cmp-cmdline', -- { name = 'cmdline' } + { + 'hrsh7th/vim-vsnip', + config = function() + G.g.vsnip_snippet_dir = G.fn.stdpath("config") .. "/snippets" + end + }, + 'hrsh7th/cmp-vsnip', + 'onsails/lspkind-nvim', + }, + config = function() + local has_words_before = function() + unpack = unpack or table.unpack + local line, col = unpack(G.api.nvim_win_get_cursor(0)) + return col ~= 0 and G.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match('%s') == nil + end + + local feedkey = function(key, mode) + vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(key, true, true, true), mode, true) + end + local cmp = require('cmp') + local cmp_opt = { + snippet = { + expand = function(args) + vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users. + end, + }, + sources = cmp.config.sources({ + { name = 'nvim_lsp' }, + { name = 'vsnip' }, + }, + { name = 'buffer' }, + { name = 'path' } + ), + mapping = cmp.mapping.preset.insert({ + + [""] = cmp.mapping({ + i = cmp.mapping.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = true }), + c = function(fallback) + if cmp.visible() then + cmp.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = true }) + else + fallback() + end + end, + }), + + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif vim.fn["vsnip#available"](1) == 1 then + feedkey("(vsnip-expand-or-jump)", "") + elseif has_words_before() then + cmp.complete() + else + fallback() + end + end, { "i", "s" }), + + [""] = cmp.mapping(function() + if cmp.visible() then + cmp.select_prev_item() + elseif vim.fn["vsnip#jumpable"](-1) == 1 then + feedkey("(vsnip-jump-prev)", "") + end + end, { "i", "s" }), + + }), + + window = { + completion = { + winhighlight = "Normal:Pmenu,FloatBorder:Pmenu,Search:None", + col_offset = -3, + side_padding = 0, + border = "rounded", + scrollbar = false, + }, + documentation = { + winhighlight = "Normal:Pmenu,FloatBorder:Pmenu,Search:None", + border = "rounded", + scrollbar = false, + }, + }, + + formatting = { + fields = { "kind", "abbr", "menu" }, + format = function(entry, vim_item) + local kind = require("lspkind").cmp_format({ mode = "symbol_text", maxwidth = 50, })(entry, vim_item) + local strings = vim.split(kind.kind, "%s", { trimempty = true }) + kind.kind = " " .. (strings[1] or "") .. " " + kind.menu = " (" .. (strings[2] or "") .. ")" + return kind + end, + }, + } + require('cmp').setup(cmp_opt) + end, + }, + + { + -- 语法高亮 -- + 'nvim-treesitter/nvim-treesitter', + config = function() + local treesitter_opt = { + ensure_installed = { + -- "c", + -- "cpp", + -- "python", + -- "java", + -- "lua", + -- "bash", + -- "vimdoc", + }, + indent = { enable = true }, + ignore_install = { + "txt", + "go" + }, + sync_install = false, + auto_install = true, + highlight = { + enable = true, + disable = function(_, buf) + local max_filesize = 100 * 1024 -- 100 KB + local ok, stats = pcall(G.loop.fs_stat, G.api.nvim_buf_get_name(buf)) + if ok and stats and stats.size > max_filesize then + return true + end + end, + additional_vim_regex_highlighting = false, + }, + parsers = { + html = { + install_info = { + url = "https://github.com/ikatyang/tree-sitter-vue", + files = { "src/parser.c" }, + branch = "main" + } + } + } + } + require 'nvim-treesitter'.setup(treesitter_opt) + require 'nvim-treesitter.install'.prefer_git = true + if G.use_ssh then + local parsers = require 'nvim-treesitter.parsers'.get_parser_configs() + for _, p in pairs(parsers) do + p.install_info.url = p.install_info.url:gsub("https://github/com/", "git@github.com:") + end + end + end + }, + }, + { + 'fgheng/winbar.nvim', + config = function() + require('winbar').setup({ + enabled = true, -- 是否启动winbar + + -- show_file_path = true, -- 是否显示文件路径 + show_symbols = true, -- 是否显示函数标签 + + -- 颜色配置,为空,将使用默认配色 + colors = { + path = '#aaffff', -- 路径的颜色,比如#ababab + file_name = '#bbbbff', -- 文件名称的颜色,比如#acacac + symbols = '#aaffaa', -- 函数颜色 + }, + + -- 图标配置 + icons = { + seperator = '>', -- 路径分割符号 + editor_state = '●', + lock_icon = '', + }, + + -- 关闭winbar的窗口 + exclude_filetype = { + 'help', + 'startify', + 'dashboard', + 'packer', + 'neogitstatus', + 'NvimTree', + 'Trouble', + 'alpha', + 'lir', + 'Outline', + 'spectre_panel', + 'toggleterm', + 'qf', + } + }) + end + }, +} diff --git a/lua/plugs/nvimtree.lua b/lua/plugs/nvimtree.lua new file mode 100644 index 0000000..c2f2607 --- /dev/null +++ b/lua/plugs/nvimtree.lua @@ -0,0 +1,40 @@ +return { + "nvim-tree/nvim-tree.lua", + dependencies = { + 'kyazdani42/nvim-web-devicons' + }, + keys = { + "" + }, + config = function() + require 'nvim-web-devicons'.setup {} + + require 'nvim-tree'.setup { + sort_by = "case_sensitive", + view = { + width = 30, + }, + filters = { dotfiles = true, }, + git = { enable = true }, + on_attach = function(bufnr) + local api = require 'nvim-tree.api' + api.config.mappings.default_on_attach(bufnr) + + -- override a default + G.map({ + { 'n', 'v', api.node.open.vertical, { buffer = bufnr } }, + { 'n', 's', api.node.open.horizontal, { buffer = bufnr } }, + }) + + G.delmap({ + { 'n', '', { buffer = bufnr } }, + { 'n', '', { buffer = bufnr } }, + { 'n', '', { buffer = bufnr } }, + }) + end + } + G.map({ + { "n", "", ":NvimTreeToggle", { noremap = true } }, + }) + end +} diff --git a/lua/plugs/theme.lua b/lua/plugs/theme.lua new file mode 100644 index 0000000..013bed5 --- /dev/null +++ b/lua/plugs/theme.lua @@ -0,0 +1,82 @@ +return { + { + 'folke/tokyonight.nvim', + config = function() + G.cmd("colorscheme tokyonight") -- 主题 + G.opt.background = 'dark' -- 背景 + end + }, + { + -- line插件 + 'kdheepak/tabline.nvim', + 'nvim-lualine/lualine.nvim', + config = function() + require('lualine').setup { + options = { + icons_enabled = true, + theme = 'auto', + component_separators = { left = '', right = '' }, + section_separators = { left = '', right = '' }, + disabled_filetypes = { + statusline = {}, + winbar = {}, + }, + ignore_focus = {}, + always_divide_middle = true, + globalstatus = false, + refresh = { + statusline = 1000, + tabline = 1000, + winbar = 1000, + } + }, + sections = { + lualine_a = { 'mode' }, + lualine_b = { 'branch', 'diff', 'diagnostics' }, + lualine_c = { { + 'filename', + file_status = false, + path = 1 + } }, + lualine_x = { 'encoding', 'fileformat', 'filetype' }, + lualine_y = { 'progress' }, + lualine_z = {} + }, + inactive_sections = { + lualine_a = {}, + lualine_b = {}, + lualine_c = { 'filename' }, + lualine_x = { 'location' }, + lualine_y = {}, + lualine_z = {} + }, + tabline = {}, + winbar = {}, + inactive_winbar = {}, + extensions = {} + } + require('tabline').setup { + -- Defaults configuration options + enable = true, + options = { + -- If lualine is installed tabline will use separators configured in lualine by default. + -- These options can be used to override those settings. + section_separators = { ' ', ' ' }, + component_separators = { '', '' }, + max_bufferline_percent = 66, -- set to nil by default, and it uses vim.o.columns * 2/3 + show_tabs_always = false, -- this shows tabs only when there are more than one tab or if the first tab is named + show_devicons = true, -- this shows devicons in buffer section + show_bufnr = false, -- this appends [bufnr] to buffer section, + show_filename_only = true, -- shows base filename only instead of relative path in filename + modified_icon = "+ ", -- change the default modified icon + modified_italic = false, -- set to true by default; this determines whether the filename turns italic if modified + show_tabs_only = false, -- this shows only tabs instead of tabs + buffers + }, + G.cmd [[ + set guioptions-=e " Use showtabline in gui vim + set sessionoptions+=tabpages,globals " store tabpages and globals in session + ]] + } + end, + }, +} diff --git a/lua/vsc.lua b/lua/vsc.lua new file mode 100644 index 0000000..0abf89d --- /dev/null +++ b/lua/vsc.lua @@ -0,0 +1,4 @@ +require 'lazy'.setup({ + require('plugs.edit-plugs'), + -- 'vijaymarupudi/nvim-fzf', -- fzf +}) diff --git a/snippets/c.json b/snippets/c.json new file mode 100644 index 0000000..94d29ce --- /dev/null +++ b/snippets/c.json @@ -0,0 +1,26 @@ +{ + "for": { + "prefix": "for", + "body": [ + " for(int $1 = $2; $1 < $3; $1+=$4) {", + " $5", + " }" + ] + }, + "for1": { + "prefix": "for1", + "body": [ + " for(int $1 = $2; $1 < $3; $1++) {", + " $4", + " }" + ] + }, + "fori": { + "prefix": "fori", + "body": [ + " for(int i = $1; i < $2; i++) {", + " $3", + " }" + ] + } +} diff --git a/snippets/c/acm/Class_Data.code-snippets b/snippets/c/acm/Class_Data.code-snippets new file mode 100644 index 0000000..bc82d63 --- /dev/null +++ b/snippets/c/acm/Class_Data.code-snippets @@ -0,0 +1,303 @@ +{ + "Class_Array_tree": { + "prefix": "Class_Array_tree", + "body": [ + "", + "template ", + "class Array_tree {", + " public:", + " Array_tree() {}", + " Array_tree(int n) { this->n = n, tree = vector(n + 1); }", + " void add(int id, T key) {", + " for (int i = id; i <= n; i += lowbit(i)) tree[i] += key;", + " }", + "", + " T get_sum(int id) {", + " T sum = 0;", + " for (int i = id; i; i -= lowbit(i)) sum += tree[i];", + " return sum;", + " }", + "", + " T get_sum(int l, int r) { return get_sum(r) - get_sum(l - 1); }", + "", + " private:", + " int n;", + " vector tree;", + " int lowbit(int x) { return x & -x; }", + "};", + "" + ] + }, + "Class_SGM_Tree": { + "prefix": "Class_SGM_Tree", + "body": [ + "", + "class SGM_Tree {", + " public:", + " class point {", + " public:", + " ll sum, maxi, mini;", + " };", + "", + " vll a, lazy;", + " int n;", + " ll sum, maxi, mini;", + " vector tree;", + "", + " SGM_Tree() {}", + " SGM_Tree(int n, vi v) {", + " // a下标默认从1开始,只需开n个点,不需要n + 1", + " this->n = n;", + " lazy = vll(n * 4 + 1);", + " a.push_back(0);", + " for (int i = 1; i <= n; i++) a.push_back(v[i]);", + " tree = vector(4 * n + 1), build(1, n, 1);", + " }", + " SGM_Tree(int n, vll v) {", + " // a下标默认从1开始,只需开n个点,不需要n + 1", + " this->n = n;", + " lazy = vll(n * 4 + 1);", + " a.push_back(0);", + " for (int i = 1; i <= n; i++) a.push_back(v[i]);", + " tree = vector(4 * n + 1), build(1, n, 1);", + " }", + " SGM_Tree(int n, int* v) {", + " // a下标默认从1开始,只需开n个点,不需要n + 1", + " this->n = n;", + " lazy = vll(n * 4 + 1);", + " a.push_back(0);", + " for (int i = 1; i <= n; i++) a.push_back(v[i]);", + " tree = vector(4 * n + 1), build(1, n, 1);", + " }", + "", + " void push_up(int k) {", + " int l = k * 2, r = k * 2 + 1;", + " tree[k].sum = tree[l].sum + tree[r].sum;", + " tree[k].maxi = max(tree[l].maxi, tree[r].maxi);", + " tree[k].mini = min(tree[l].mini, tree[r].mini);", + " }", + "", + " void push_down(int l, int r, int k) {", + " if (lazy[k]) {", + " int mid = l + r >> 1;", + " lazy[k * 2] += lazy[k];", + " lazy[k * 2 + 1] += lazy[k];", + " tree[k * 2].sum += lazy[k] * (mid - l + 1);", + " tree[k * 2 + 1].sum += lazy[k] * (r - mid);", + " tree[k * 2].maxi += lazy[k];", + " tree[k * 2 + 1].maxi += lazy[k];", + " tree[k * 2].mini += lazy[k];", + " tree[k * 2 + 1].mini += lazy[k];", + " lazy[k] = 0;", + " }", + " }", + "", + " void get_updata(int l, int r, int k, ll value) {", + " tree[k].sum += value * (r - l + 1);", + " tree[k].maxi += value;", + " tree[k].mini += value;", + " lazy[k] += value;", + " }", + "", + " void get(int k) {", + " sum += tree[k].sum;", + " maxi = max(maxi, tree[k].maxi);", + " mini = min(mini, tree[k].mini);", + " }", + "", + " void build(int l, int r, int k) {", + " if (l == r) {", + " tree[k].maxi = tree[k].mini = tree[k].sum = a[l];", + " return;", + " }", + " int mid = l + r >> 1;", + " build(l, mid, k * 2);", + " build(mid + 1, r, k * 2 + 1);", + " push_up(k);", + " }", + "", + " void updata(int l, int r, int L, int R, int k, ll value) {", + " if (L <= l && r <= R) {", + " get_updata(l, r, k, value);", + " return;", + " }", + " push_down(l, r, k);", + " int mid = l + r >> 1;", + " if (L <= mid) updata(l, mid, L, R, k * 2, value);", + " if (R > mid) updata(mid + 1, r, L, R, k * 2 + 1, value);", + " push_up(k);", + " }", + "", + " void query(int l, int r, int L, int R, int k) {", + " if (L <= l && r <= R) {", + " get(k);", + " return;", + " }", + " push_down(l, r, k);", + " int mid = l + r >> 1;", + " if (mid >= L) query(l, mid, L, R, 2 * k);", + " if (mid < R) query(mid + 1, r, L, R, 2 * k + 1);", + " }", + "", + " ll get_sum(int L, int R) {", + " sum = 0;", + " query(1, n, L, R, 1);", + " return sum;", + " }", + "", + " ll get_max(int L, int R) {", + " maxi = -inf;", + " query(1, n, L, R, 1);", + " return maxi;", + " }", + "", + " ll get_min(int L, int R) {", + " mini = inf;", + " query(1, n, L, R, 1);", + " return mini;", + " }", + "};", + "" + ] + }, + "Class_Dsu": { + "prefix": "Class_Dsu", + "body": [ + "", + "class Dsu {", + " public:", + "", + " vll fa, num;", + "", + " Dsu(int n) { fa = vll(n + 1), num = vll(n + 1); }", + " int find(int x) {", + " if (!fa[x]) return x;", + " return fa[x] = find(fa[x]);", + " }", + "", + " bool Dunion(int p, int q) {", + " int v = find(p), u = find(q);", + " if (v == u) return 0;", + " fa[u] = v;", + " num[v] += num[u];", + " num[u] = num[v];", + " return 1;", + " }", + " ", + "};", + "", + "ll num(int x) { return num[find(x)]; }", + "" + ] + }, + "class_Stmap": { + "prefix": "Class_StMap", + "body": [ + "", + "class st_map {", + " public:", + " st_map() {}", + " st_map(vll v) {", + " this->n = v.size(), this->a = v;", + " this->st = vector>(n + 1);", + " st_init();", + " }", + " int query(int l, int r) {", + " int len = r - l + 1;", + " int k = log(len) / log(2);", + " return max(st[l][k], st[r - (1 << k) + 1][k]);", + " }", + "", + " private:", + " int n;", + " vll a;", + " vector> st;", + " void st_init() {", + " for (int j = 0; j <= 17; j++) {", + " for (int i = 1; i + (1 << j) - 1 <= n; i++) {", + " if (j == 0)", + " st[i][j] = a[i];", + " else", + " st[i][j] = max(st[i][j - 1], st[i + (1 << j - 1)][j - 1]);", + " }", + " }", + " }", + "};", + "" + ] + }, + "Class_HJT_tree": { + "prefix": "Class_HJT_tree", + "body": [ + "", + "template ", + "class HJT_tree {", + " //处理数据默认下标从1开始", + " public:", + " //构造函数", + " HJT_tree() {}", + " HJT_tree(vector v) {", + " base = v, this->n = base.size() - 1;", + " tree = vector(n * 32), root.push_back(build(1, n));", + " }", + "", + " void updata(int v, int x, T value) {", + " //插入函数(版本,修改位置,修改值)", + " root.push_back(insert(root[v], 1, n, x, value));", + " }", + "", + " T query(int v, int x) {", + " //查询函数(版本,查询位置)", + " return get_se(root[v], 1, n, x, x);", + " }", + "", + " T query(int v, int l, int r) {", + " //查询函数(版本,查询区间)", + " return get_se(root[v], 1, n, l, r);", + " }", + "", + " private:", + " vi root;", + " vector base;", + " int n, idx = 0;", + " struct node {", + " int l, r;", + " T data;", + " };", + " vector tree;", + " void pushup(int q) { tree[q].data = op(tree[q].l, tree[q].r); }", + " T op(int l, int r) { return max(tree[l].data, tree[r].data); }", + " T e() { return -inf; }", + " int build(int l, int r) {", + " int now = ++idx, mid = l + r >> 1;", + " if (l != r)", + " tree[now].l = build(l, mid), tree[now].r = build(mid + 1, r), pushup(now);", + " return now;", + " }", + " int insert(int old, int l, int r, int x, int value) {", + " int now = ++idx, mid = l + r >> 1;", + " tree[now] = tree[old];", + " if (l == r)", + " tree[now].data = value;", + " else {", + " if (x <= mid)", + " tree[now].l = insert(tree[old].l, l, mid, x, value);", + " else", + " tree[now].r = insert(tree[old].r, mid + 1, r, x, value);", + " pushup(now);", + " }", + " return now;", + " }", + " T get_se(int v, int l, int r, int L, int R) {", + " if (L <= l && r <= R) return tree[v].data;", + " ll mid = l + r >> 1;", + " T res = e();", + " if (L <= mid) res = max(res, get_se(tree[v].l, l, mid, L, R));", + " if (R > mid) res = max(res, get_se(tree[v].r, mid + 1, r, L, R));", + " return res;", + " }", + "};", + "" + ] + } +} diff --git a/snippets/c/acm/Class_Graph.code-snippets b/snippets/c/acm/Class_Graph.code-snippets new file mode 100644 index 0000000..cfa9bb2 --- /dev/null +++ b/snippets/c/acm/Class_Graph.code-snippets @@ -0,0 +1,359 @@ +{ + "Graph": { + "prefix": "Class_Graph", + "body": [ + "", + "template ", + "class Graph {", + " public:", + " struct edge {", + " int next, to;", + " T w;", + " };", + " int n;", + " vector> maps;", + " vector dis;", + " vector e;", + " vi head, bj;", + " Graph() {}", + "", + " Graph(int n) {", + " this->n = n, this->m = n * (n - 1);", + " head = vi(n + 1, -1), e = vector(m * 2 + 1);", + " }", + "", + " Graph(int n, int m) {", + " this->n = n, this->m = m, head = vi(n + 1, -1), e = vector(m * 2 + 1);", + " }", + "", + " void add(int u, int v, T w) {", + " e[cnt].to = v, e[cnt].next = head[u], e[cnt].w = w, head[u] = cnt++;", + " }", + "", + " void add(int u, int v) {", + " e[cnt].to = v, e[cnt].next = head[u], head[u] = cnt++;", + " }", + "", + " private:", + " int m, cnt = 0;", + "};", + "#define e g.e", + "#define head g.head", + "#define maps g.maps", + "#define add g.add", + "" + ] + }, + "Class_Graph_Dijkstra": { + "prefix": "Class_Graph_Dijkstra", + "body": [ + "", + "#define dis g.dis", + "#define bj g.bj", + "ll dijkstra(Graph g, int st, int en) {", + " dis = vll(g.n + 1, inf),", + " bj = vi(g.n + 1);", + " priority_queue, greater> q;", + " dis[st] = 0;", + " q.push({0, st});", + " while (!q.empty()) {", + " int u = q.top().y;", + " q.pop();", + " if (bj[u]) continue;", + " bj[u] = 1;", + " for (int i = head[u]; ~i; i = e[i].next) {", + " int v = e[i].to;", + " if (dis[v] > dis[u] + e[i].w) {", + " dis[v] = dis[u] + e[i].w;", + " q.push({dis[v], v});", + " }", + " }", + " }", + " if (dis[en] != inf)", + " return dis[en];", + " else", + " return -1;", + "}", + "" + ] + }, + "Class_Graph_SPFA": { + "prefix": "Class_Graph_SPFA", + "body": [ + "", + "ll spfa(Graph g, int st, int en) {", + " vll bj(g.n + 1), dis(g.n + 1, inf), num(g.n + 1);", + " queue q;", + " dis[st] = 0;", + " bj[st] = 1;", + " q.push(st);", + " while (q.size()) {", + " int u = q.front();", + " if (!bj[u]) continue;", + " if (num[u] > g.n + 1) return inf;//判断是否产生负环", + " bj[u] = 0, num[u]++;", + " for (int i = head[u]; ~i; i = e[i].next) {", + " int w = e[i].w, v = e[i].to;", + " if (dis[v] > dis[u] + w) {", + " dis[v] = dis[u] + w;", + " if (!bj[v]) q.push(v);", + " }", + " }", + " }", + " if(dis[en] == inf) return -1;", + " return dis[en];", + "}", + "" + ] + }, + "Class_Graph_Kurskal": { + "prefix": "Class_Graph_Kurskal", + "body": [ + "", + "ll kruskal(Graph g, Dsu d) {", + " ll res = 0, cnt = 0;", + " sort(e.begin(), e.end());", + " for (auto i : e) {", + " int u = i.u, v = i.v, w = i.w;", + " int q = d.find(i.u), p = d.find(i.v);", + " if (d.Dunion(q, p)) cnt++, res += w;", + " if (cnt == n - 1) break;", + " }", + " return res;", + "}", + "" + ] + }, + "Class_Graph_Prim": { + "prefix": "Class_Graph_Prim", + "body": [] + }, + "Class_Graph_TreeDiam": { + "prefix": "Class_Graph_TreeDiam", + "description": "树的直径", + "body": [ + "ll TreeDiam(Graph g) {", + " vll dis1(n + 1), dis2(n + 1), p(n + 1), up(n + 1);", + " function dfs = [&](ll u, ll fa) {", + " for (int i = head[u]; ~i; i = e[i].next) {", + " int v = e[i].to, w = 1;", + " if (v == fa) continue;", + " ll x = dfs(v, u) + 1;", + " if (x >= dis1[u])", + " dis2[u] = dis1[u], dis1[u] = x, p[u] = v;", + " else if (x >= dis2[u])", + " dis2[u] = x;", + " }", + " return dis1[u];", + " };", + " function dfs0 = [&](ll u, ll fa) {", + " for (int i = head[u]; ~i; i = e[i].next) {", + " int v = e[i].to, w = 1;", + " if (v == fa) continue;", + " if (p[u] == v)", + " up[v] = max(dis2[u], up[u]) + w;", + " else", + " up[v] = max(dis1[u], up[u]) + w;", + " dfs0(v, u);", + " }", + " };", + " dfs(1, -1), dfs0(1, -1);", + " ll ans = -1;", + " for (int i = 1; i <= n + m; i++) {", + " if (dis1[i] == dis2[i] && dis1[i] == 0)", + " ans = max(ans, up[i]);", + " else", + " ans = max(ans, max(up[i], dis1[i]));", + " }", + " return ans;", + "}" + ] + }, + "Class_Graph_SCC": { + "prefix": "Class_Graph_SCC", + "body": [ + "", + "class SCC {", + " public:", + " stack stk;", + " int timestamp = 0, scc_cnt = 0, n, m;", + " vll dfn, low, in_stk, Size, id;", + " Graph g;", + "", + " SCC() {}", + "", + " SCC(Graph g) {", + " this->n = g.n, this->m = g.m, this->g = g;", + " dfn = vll(n + 1, 0);", + " low = vll(n + 1, 0);", + " in_stk = vll(n + 1, 0);", + " Size = vll(n + 1, 0);", + " id = vll(n + 1, 0);", + " for (int i = 1; i <= n; i++)", + " if (!dfn[i]) tarjan(i);", + " }", + "", + " void tarjan(int u) {", + " dfn[u] = low[u] = ++timestamp;", + " stk.push(u), in_stk[u] = 1;", + " for (int i = head[u]; ~i; i = e[i].next) {", + " int v = e[i].to;", + " if (!dfn[v]) {", + " tarjan(v);", + " low[u] = min(low[u], low[v]);", + " } else if (in_stk[v])", + " low[u] = min(low[u], dfn[v]);", + " }", + " if (low[u] == dfn[u]) {", + " ++scc_cnt;", + " int v;", + " do {", + " v = stk.top();", + " stk.pop();", + " in_stk[v] = 0;", + " id[v] = scc_cnt;", + " Size[scc_cnt]++;", + " } while (v != u);", + " }", + " return;", + " }", + "};", + "" + ] + }, + "Class_Graph_Euler": { + "prefix": "Class_Graph_Euler", + "body": [ + "", + "vll din, dout;", + "", + "class Euler {", + " public:", + " int n, m;", + " Graph g;", + " vector used;", + " vll path;", + " Euler() {}", + " Euler(Graph g) {", + " this->n = g.n, this->m = g.m, this->g = g;", + " used = vector(n + 1);", + " }", + "", + " void dfs_u(int u) {", + " //无向图", + " for (long long &i = head[u]; i; i = e[i].next) {", + " long long j = i & 1 ? i + 1 : i - 1;", + " if(used[i]) {", + " i = e[i].next;", + " continue;", + " }", + " used[j] = used[i] = true;", + " int t = i / 2 + 1;", + " dfs_u(e[i].to);", + " path.push_back(t);", + " }", + " }", + "", + " void dfs_o(int u) {", + " // 有向图", + " for (long long &i = head[u]; i; i = e[i].next) {", + " if(used[i]) {", + " i = e[i].next;", + " continue;", + " }", + " used[i] = true;", + " int t = i + 1;", + " dfs_o(e[i].to);", + " path.push_back(t);", + " }", + " }", + "", + "};", + "#define path eu.path", + "" + ] + }, + "Class_Graph_LCA": { + "prefix": "Class_Graph_LCA", + "body": [ + "", + "class LCA {", + " public:", + " int n;", + " vll depth, fa[33];", + "", + " LCA() {}", + " LCA(Graph g, int root) {", + " n = g.n, depth = vll(n + 1, inf);", + " for (int i = 0; i <= 32; i++) fa[i] = vll(n + 1);", + " bfs(g, root);", + " }", + "", + " void bfs(Graph g, int root) {", + " depth[0] = 0, depth[root] = 1;", + " queue q;", + " q.push(root);", + " while (q.size()) {", + " auto u = q.front();", + " q.pop();", + " for (int i = head[u]; ~i; i = e[i].next) {", + " int v = e[i].to;", + " if (depth[v] > depth[u] + 1) {", + " depth[v] = depth[u] + 1;", + " q.push(v);", + " fa[0][v] = u;", + " for (int k = 1; k <= 32; k++) fa[k][v] = fa[k - 1][fa[k - 1][v]];", + " }", + " }", + " }", + " }", + "", + " int query(int a, int b) {", + " if (depth[a] < depth[b]) swap(a, b);", + " for (int i = 32; i >= 0; i--)", + " if (depth[fa[i][a]] >= depth[b]) a = fa[i][a];", + " if (a == b) return a;", + " for (int i = 32; i >= 0; i--)", + " if (fa[i][a] != fa[i][b]) a = fa[i][a], b = fa[i][b];", + " return fa[0][a];", + " }", + "};", + "" + ] + }, + "Class_Graph_erfen": { + "prefix": "Class_Graph_erfen", + "body": [ + "", + "class erfen_graph {", + " public:", + " ll res, n;", + " vi match, st;", + " Graph g;", + " erfen_graph(Graph g) {", + " this->g = g, this->n = g.n;", + " st = vector(n + 1), match = vector(n + 1);", + " res = 0;", + " for (int i = 1; i <= n; i++) {", + " st = vector(n + 1);", + " if (find(i)) res++;", + " }", + " }", + "", + " bool find(int u) {", + " for (int i = head[u]; ~i; i = e[i].next) {", + " if (!st[e[i].to]) {", + " st[e[i].to] = true;", + " if (!match[e[i].to] || find(match[e[i].to])) {", + " match[e[i].to] = u;", + " return true;", + " }", + " }", + " }", + " return false;", + " }", + "};", + "" + ] + } +} diff --git a/snippets/c/acm/Class_Math.code-snippets b/snippets/c/acm/Class_Math.code-snippets new file mode 100644 index 0000000..685c88e --- /dev/null +++ b/snippets/c/acm/Class_Math.code-snippets @@ -0,0 +1,108 @@ +{ + "Math_QuickPow": { + "prefix": "Math_QuickPow", + "body": [ + "", + "ll quick_Pow(ll a, ll b, ll mod) {", + " // a的b次方模mod", + " ll res = 1, t = a;", + " while (b) {", + " if (b & 1) res = (res * t) % mod;", + " t = t * t % mod;", + " b >>= 1;", + " }", + " return res;", + "}", + "", + ], + }, + "Math_Fm": { + "prefix": "Math_Fm", + "body": [ + "", + "ll quick_Pow(ll a, ll b, ll mod) {", + " // a的b次方模mod", + " ll res = 1, t = a;", + " while (b) {", + " if (b & 1) res = (res * t) % mod;", + " t = t * t % mod;", + " b >>= 1;", + " }", + " return res;", + "}", + "", + "ll Fm(ll a, ll mod) {", + " //费马小定理求逆元", + " return quick_Pow(a, mod - 2, mod);", + "}", + "", + ], + }, + "Math_C": { + "prefix": "Math_C", + "body": [ + "", + "ll quick_Pow(ll a, ll b, ll mod) {", + " // a的b次方模mod", + " ll res = 1, t = a;", + " while (b) {", + " if (b & 1) res = (res * t) % mod;", + " t = t * t % mod;", + " b >>= 1;", + " }", + " return res;", + "}", + "", + "ll Fm(ll a, ll mod) {", + " //费马小定理求逆元", + " return quick_Pow(a, mod - 2, mod);", + "}", + "", + "ll C(ll n, ll m, ll mod) {", + " ll fz = 1, fm = 1;", + " for (ll i = n; i >= n - m + 1; i--) fz = fz * i % mod;", + " for (ll i = 1; i <= m; i++) fm = fm * i % mod;", + " return (fz * Fm(fm, mod)) % mod;", + "}", + "", + ], + }, + "Class_Math_Bignum": { + "prefix": "Class_Math_Bignum", + "body": [ + "", + "class Math_Bignum {", + " public:", + " string Bignum;", + "", + " vll num;", + "", + " Math_Bignum(string s) {", + " Bignum = s;", + " for (auto i : s) num.push_back(i - '0');", + " }", + "", + " Math_Bignum(vll v) {", + " string s;", + " num = v;", + " for (auto i : v) s.push_back(i + '0');", + " }", + "", + " Math_Bignum(ll l) {", + " string s;", + " while (l) s.push_back(l % 10 + '0'), num.push_back(l % 10), l /= 10;", + " reverse(num.begin(), num.end());", + " reverse(s.begin(), s.end());", + " Bignum = s;", + " }", + "", + " ll get(ll l, ll r) {", + " ll res = 0;", + " for (int i = l - 1; i <= r - 1; i++) res = res * 10 + num[i];", + " return res;", + " }", + "};", + "", + ], + }, +} \ No newline at end of file diff --git a/snippets/go.json b/snippets/go.json new file mode 100644 index 0000000..79edb5b --- /dev/null +++ b/snippets/go.json @@ -0,0 +1,43 @@ +{ + "class": { + "prefix": "class", + "body": "type $1 struct{$2}\n$0" + }, + "errnil": { + "prefix": "errnil", + "body": [ + "if err != nil {", + " $1", + "}" + ] + }, + "init": { + "prefix": "init", + "body": [ + "func init() {", + " $1", + "}" + ] + }, + "ctx": { + "prefix": "ctx", + "body": [ + "ctx := context.Background()" + ] + }, + "cok": { + "prefix": "cok", + "body": [ + "c.JSON(http.StatusOK, vo.Success($1))" + ] + }, + "cbad": { + "prefix": "cbad", + "body": [ + "if err != nil {", + " c.JSON(http.StatusBadRequest, vo.Fail(err))", + " return", + "}" + ] + } +} diff --git a/snippets/json.json b/snippets/json.json new file mode 100644 index 0000000..59098d5 --- /dev/null +++ b/snippets/json.json @@ -0,0 +1,13 @@ +{ + "mod": { + "prefix": "mod", + "body": [ + " \"$1\": {", + " \"prefix\": \"$1\",", + " \"body\": [", + " $2", + " ]", + " }" + ] + } +} diff --git a/snippets/lua.json b/snippets/lua.json new file mode 100644 index 0000000..0db3279 --- /dev/null +++ b/snippets/lua.json @@ -0,0 +1,3 @@ +{ + +}