diff --git a/init.lua b/init.lua index b56ce29814c..2717822223b 100644 --- a/init.lua +++ b/init.lua @@ -91,7 +91,7 @@ vim.g.mapleader = ' ' vim.g.maplocalleader = ' ' -- Set to true if you have a Nerd Font installed and selected in the terminal -vim.g.have_nerd_font = false +vim.g.have_nerd_font = true -- [[ Setting options ]] -- See `:help vim.o` @@ -114,7 +114,9 @@ vim.o.showmode = false -- Schedule the setting after `UiEnter` because it can increase startup-time. -- Remove this option if you want your OS clipboard to remain independent. -- See `:help 'clipboard'` -vim.schedule(function() vim.o.clipboard = 'unnamedplus' end) +vim.schedule(function() + vim.o.clipboard = 'unnamedplus' +end) -- Enable break indent vim.o.breakindent = true @@ -146,9 +148,13 @@ vim.o.splitbelow = true -- Notice listchars is set using `vim.opt` instead of `vim.o`. -- It is very similar to `vim.o` but offers an interface for conveniently interacting with tables. -- See `:help lua-options` --- and `:help lua-guide-options` +-- and `:help lua-options-guide` vim.o.list = true vim.opt.listchars = { tab = '» ', trail = '·', nbsp = '␣' } +vim.opt.tabstop = 4 -- Visual width of a tab +vim.opt.softtabstop = 4 -- The number of spaces inserted when hitting Tab +vim.opt.shiftwidth = 4 -- Size of an indentation +vim.opt.expandtab = true -- Turn tabs into spaces -- Preview substitutions live, as you type! vim.o.inccommand = 'split' @@ -227,7 +233,9 @@ vim.keymap.set('n', '', '', { desc = 'Move focus to the upper win vim.api.nvim_create_autocmd('TextYankPost', { desc = 'Highlight when yanking (copying) text', group = vim.api.nvim_create_augroup('kickstart-highlight-yank', { clear = true }), - callback = function() vim.hl.on_yank() end, + callback = function() + vim.hl.on_yank() + end, }) -- [[ Install `lazy.nvim` plugin manager ]] @@ -236,7 +244,9 @@ 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 error('Error cloning lazy.nvim:\n' .. out) end + if vim.v.shell_error ~= 0 then + error('Error cloning lazy.nvim:\n' .. out) + end end ---@type vim.Option @@ -255,8 +265,15 @@ rtp:prepend(lazypath) -- -- NOTE: Here is where you install your plugins. require('lazy').setup({ - -- NOTE: Plugins can be added via a link or github org/name. To run setup automatically, use `opts = {}` - { 'NMAC427/guess-indent.nvim', opts = {} }, + -- NOTE: Plugins can be added with a link (or for a github repo: 'owner/repo' link). + 'NMAC427/guess-indent.nvim', -- Detect tabstop and shiftwidth automatically + + -- NOTE: Plugins can also be added by using a table, + -- with the first argument being the link and the following + -- keys can be used to configure plugin behavior/loading/etc. + -- + -- Use `opts = {}` to automatically pass options to a plugin's `setup()` function, forcing the plugin to be loaded. + -- -- Alternatively, use `config = function() ... end` for full control over the configuration. -- If you prefer to call `setup` explicitly, use: @@ -311,12 +328,48 @@ require('lazy').setup({ ---@diagnostic disable-next-line: missing-fields opts = { -- delay between pressing a key and opening which-key (milliseconds) + -- this setting is independent of vim.o.timeoutlen delay = 0, - icons = { mappings = vim.g.have_nerd_font }, + icons = { + -- set icon mappings to true if you have a Nerd Font + mappings = vim.g.have_nerd_font, + -- If you are using a Nerd Font: set icons.keys to an empty table which will use the + -- default which-key.nvim defined Nerd Font icons, otherwise define a string table + keys = vim.g.have_nerd_font and {} or { + Up = ' ', + Down = ' ', + Left = ' ', + Right = ' ', + C = ' ', + M = ' ', + D = ' ', + S = ' ', + CR = ' ', + Esc = ' ', + ScrollWheelDown = ' ', + ScrollWheelUp = ' ', + NL = ' ', + BS = ' ', + Space = ' ', + Tab = ' ', + F1 = '', + F2 = '', + F3 = '', + F4 = '', + F5 = '', + F6 = '', + F7 = '', + F8 = '', + F9 = '', + F10 = '', + F11 = '', + F12 = '', + }, + }, -- Document existing key chains spec = { - { 's', group = '[S]earch', mode = { 'n', 'v' } }, + { 's', group = '[S]earch' }, { 't', group = '[T]oggle' }, { 'h', group = 'Git [H]unk', mode = { 'n', 'v' } }, -- Enable gitsigns recommended keymaps first { 'gr', group = 'LSP Actions', mode = { 'n' } }, @@ -333,16 +386,6 @@ require('lazy').setup({ { -- Fuzzy Finder (files, lsp, etc) 'nvim-telescope/telescope.nvim', - -- By default, Telescope is included and acts as your picker for everything. - - -- If you would like to switch to a different picker (like snacks, or fzf-lua) - -- you can disable the Telescope plugin by setting enabled to false and enable - -- your replacement picker by requiring it explicitly (e.g. 'custom.plugins.snacks') - - -- Note: If you customize your config for yourself, - -- it’s best to remove the Telescope plugin config entirely - -- instead of just disabling it here, to keep your config clean. - enabled = true, event = 'VimEnter', dependencies = { 'nvim-lua/plenary.nvim', @@ -355,7 +398,9 @@ require('lazy').setup({ -- `cond` is a condition used to determine whether this plugin should be -- installed and loaded. - cond = function() return vim.fn.executable 'make' == 1 end, + cond = function() + return vim.fn.executable 'make' == 1 + end, }, { 'nvim-telescope/telescope-ui-select.nvim' }, @@ -395,7 +440,9 @@ require('lazy').setup({ -- }, -- pickers = {} extensions = { - ['ui-select'] = { require('telescope.themes').get_dropdown() }, + ['ui-select'] = { + require('telescope.themes').get_dropdown(), + }, }, } @@ -409,49 +456,14 @@ require('lazy').setup({ vim.keymap.set('n', 'sk', builtin.keymaps, { desc = '[S]earch [K]eymaps' }) vim.keymap.set('n', 'sf', builtin.find_files, { desc = '[S]earch [F]iles' }) vim.keymap.set('n', 'ss', builtin.builtin, { desc = '[S]earch [S]elect Telescope' }) - vim.keymap.set({ 'n', 'v' }, 'sw', builtin.grep_string, { desc = '[S]earch current [W]ord' }) + vim.keymap.set('n', 'sw', builtin.grep_string, { desc = '[S]earch current [W]ord' }) vim.keymap.set('n', 'sg', builtin.live_grep, { desc = '[S]earch by [G]rep' }) vim.keymap.set('n', 'sd', builtin.diagnostics, { desc = '[S]earch [D]iagnostics' }) vim.keymap.set('n', 'sr', builtin.resume, { desc = '[S]earch [R]esume' }) vim.keymap.set('n', 's.', builtin.oldfiles, { desc = '[S]earch Recent Files ("." for repeat)' }) - vim.keymap.set('n', 'sc', builtin.commands, { desc = '[S]earch [C]ommands' }) vim.keymap.set('n', '', builtin.buffers, { desc = '[ ] Find existing buffers' }) - -- This runs on LSP attach per buffer (see main LSP attach function in 'neovim/nvim-lspconfig' config for more info, - -- it is better explained there). This allows easily switching between pickers if you prefer using something else! - vim.api.nvim_create_autocmd('LspAttach', { - group = vim.api.nvim_create_augroup('telescope-lsp-attach', { clear = true }), - callback = function(event) - local buf = event.buf - - -- Find references for the word under your cursor. - vim.keymap.set('n', 'grr', builtin.lsp_references, { buffer = buf, desc = '[G]oto [R]eferences' }) - - -- Jump to the implementation of the word under your cursor. - -- Useful when your language has ways of declaring types without an actual implementation. - vim.keymap.set('n', 'gri', builtin.lsp_implementations, { buffer = buf, desc = '[G]oto [I]mplementation' }) - - -- Jump to the definition of the word under your cursor. - -- This is where a variable was first declared, or where a function is defined, etc. - -- To jump back, press . - vim.keymap.set('n', 'grd', builtin.lsp_definitions, { buffer = buf, desc = '[G]oto [D]efinition' }) - - -- Fuzzy find all the symbols in your current document. - -- Symbols are things like variables, functions, types, etc. - vim.keymap.set('n', 'gO', builtin.lsp_document_symbols, { buffer = buf, desc = 'Open Document Symbols' }) - - -- Fuzzy find all the symbols in your current workspace. - -- Similar to document symbols, except searches over your entire project. - vim.keymap.set('n', 'gW', builtin.lsp_dynamic_workspace_symbols, { buffer = buf, desc = 'Open Workspace Symbols' }) - - -- Jump to the type of the word under your cursor. - -- Useful when you're not sure what type a variable is and you want to see - -- the definition of its *type*, not where it was *defined*. - vim.keymap.set('n', 'grt', builtin.lsp_type_definitions, { buffer = buf, desc = '[G]oto [T]ype Definition' }) - end, - }) - - -- Override default behavior and theme when searching + -- Slightly advanced example of overriding default behavior and theme vim.keymap.set('n', '/', function() -- You can pass additional configuration to Telescope to change the theme, layout, etc. builtin.current_buffer_fuzzy_find(require('telescope.themes').get_dropdown { @@ -462,24 +474,33 @@ require('lazy').setup({ -- It's also possible to pass additional configuration options. -- See `:help telescope.builtin.live_grep()` for information about particular keys - vim.keymap.set( - 'n', - 's/', - function() - builtin.live_grep { - grep_open_files = true, - prompt_title = 'Live Grep in Open Files', - } - end, - { desc = '[S]earch [/] in Open Files' } - ) + vim.keymap.set('n', 's/', function() + builtin.live_grep { + grep_open_files = true, + prompt_title = 'Live Grep in Open Files', + } + end, { desc = '[S]earch [/] in Open Files' }) -- Shortcut for searching your Neovim configuration files - vim.keymap.set('n', 'sn', function() builtin.find_files { cwd = vim.fn.stdpath 'config' } end, { desc = '[S]earch [N]eovim files' }) + vim.keymap.set('n', 'sn', function() + builtin.find_files { cwd = vim.fn.stdpath 'config' } + end, { desc = '[S]earch [N]eovim files' }) end, }, -- LSP Plugins + { + -- `lazydev` configures Lua LSP for your Neovim config, runtime and plugins + -- used for completion, annotations and signatures of Neovim apis + 'folke/lazydev.nvim', + ft = 'lua', + opts = { + library = { + -- Load luvit types when the `vim.uv` word is found + { path = '${3rd}/luv/library', words = { 'vim%.uv' } }, + }, + }, + }, { -- Main LSP Configuration 'neovim/nvim-lspconfig', @@ -552,17 +573,55 @@ require('lazy').setup({ -- or a suggestion from your LSP for this to activate. map('gra', vim.lsp.buf.code_action, '[G]oto Code [A]ction', { 'n', 'x' }) + -- Find references for the word under your cursor. + map('grr', require('telescope.builtin').lsp_references, '[G]oto [R]eferences') + + -- Jump to the implementation of the word under your cursor. + -- Useful when your language has ways of declaring types without an actual implementation. + map('gri', require('telescope.builtin').lsp_implementations, '[G]oto [I]mplementation') + + -- Jump to the definition of the word under your cursor. + -- This is where a variable was first declared, or where a function is defined, etc. + -- To jump back, press . + map('grd', require('telescope.builtin').lsp_definitions, '[G]oto [D]efinition') + -- WARN: This is not Goto Definition, this is Goto Declaration. -- For example, in C this would take you to the header. map('grD', vim.lsp.buf.declaration, '[G]oto [D]eclaration') + -- Fuzzy find all the symbols in your current document. + -- Symbols are things like variables, functions, types, etc. + map('gO', require('telescope.builtin').lsp_document_symbols, 'Open Document Symbols') + + -- Fuzzy find all the symbols in your current workspace. + -- Similar to document symbols, except searches over your entire project. + map('gW', require('telescope.builtin').lsp_dynamic_workspace_symbols, 'Open Workspace Symbols') + + -- Jump to the type of the word under your cursor. + -- Useful when you're not sure what type a variable is and you want to see + -- the definition of its *type*, not where it was *defined*. + map('grt', require('telescope.builtin').lsp_type_definitions, '[G]oto [T]ype Definition') + + -- This function resolves a difference between neovim nightly (version 0.11) and stable (version 0.10) + ---@param client vim.lsp.Client + ---@param method vim.lsp.protocol.Method + ---@param bufnr? integer some lsp support methods only in specific files + ---@return boolean + local function client_supports_method(client, method, bufnr) + if vim.fn.has 'nvim-0.11' == 1 then + return client:supports_method(method, bufnr) + else + return client.supports_method(method, { bufnr = bufnr }) + end + end + -- The following two autocommands are used to highlight references of the -- word under your cursor when your cursor rests there for a little while. -- See `:help CursorHold` for information about when this is executed -- -- When you move your cursor, the highlights will be cleared (the second autocommand). local client = vim.lsp.get_client_by_id(event.data.client_id) - if client and client:supports_method('textDocument/documentHighlight', event.buf) then + if client and client_supports_method(client, vim.lsp.protocol.Methods.textDocument_documentHighlight, event.buf) then local highlight_augroup = vim.api.nvim_create_augroup('kickstart-lsp-highlight', { clear = false }) vim.api.nvim_create_autocmd({ 'CursorHold', 'CursorHoldI' }, { buffer = event.buf, @@ -589,21 +648,64 @@ require('lazy').setup({ -- code, if the language server you are using supports them -- -- This may be unwanted, since they displace some of your code - if client and client:supports_method('textDocument/inlayHint', event.buf) then - map('th', function() vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled { bufnr = event.buf }) end, '[T]oggle Inlay [H]ints') + if client and client_supports_method(client, vim.lsp.protocol.Methods.textDocument_inlayHint, event.buf) then + map('th', function() + vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled { bufnr = event.buf }) + end, '[T]oggle Inlay [H]ints') end end, }) + -- Diagnostic Config + -- See :help vim.diagnostic.Opts + vim.diagnostic.config { + severity_sort = true, + float = { border = 'rounded', source = 'if_many' }, + underline = { severity = vim.diagnostic.severity.ERROR }, + signs = vim.g.have_nerd_font and { + text = { + [vim.diagnostic.severity.ERROR] = '󰅚 ', + [vim.diagnostic.severity.WARN] = '󰀪 ', + [vim.diagnostic.severity.INFO] = '󰋽 ', + [vim.diagnostic.severity.HINT] = '󰌶 ', + }, + } or {}, + virtual_text = { + source = 'if_many', + spacing = 2, + format = function(diagnostic) + local diagnostic_message = { + [vim.diagnostic.severity.ERROR] = diagnostic.message, + [vim.diagnostic.severity.WARN] = diagnostic.message, + [vim.diagnostic.severity.INFO] = diagnostic.message, + [vim.diagnostic.severity.HINT] = diagnostic.message, + } + return diagnostic_message[diagnostic.severity] + end, + }, + } + + -- LSP servers and clients are able to communicate to each other what features they support. + -- By default, Neovim doesn't support everything that is in the LSP specification. + -- When you add blink.cmp, luasnip, etc. Neovim now has *more* capabilities. + -- So, we create new capabilities with blink.cmp, and then broadcast that to the servers. + local capabilities = require('blink.cmp').get_lsp_capabilities() + -- Enable the following language servers -- Feel free to add/remove any LSPs that you want here. They will automatically be installed. - -- See `:help lsp-config` for information about keys and how to configure - ---@type table + -- + -- Add any additional override configuration in the following tables. Available keys are: + -- - cmd (table): Override the default command used to start the server + -- - filetypes (table): Override the default list of associated filetypes for the server + -- - capabilities (table): Override fields in capabilities. Can be used to disable certain LSP features. + -- - settings (table): Override the default settings passed when initializing the server. + -- For example, to see the options for `lua_ls`, you could go to: https://luals.github.io/wiki/settings/ local servers = { -- clangd = {}, -- gopls = {}, -- pyright = {}, -- rust_analyzer = {}, + -- ... etc. See `:help lspconfig-all` for a list of all the pre-configured LSPs -- -- Some languages (like typescript) have entire language plugins that can be useful: -- https://github.com/pmizio/typescript-tools.nvim @@ -650,11 +752,16 @@ require('lazy').setup({ -- :Mason -- -- You can press `g?` for help in this menu. + -- + -- `mason` had to be setup earlier: to configure its options see the + -- `dependencies` table for `nvim-lspconfig` above. + -- + -- You can add other tools here that you want Mason to install + -- for you, so that they are available from within Neovim. local ensure_installed = vim.tbl_keys(servers or {}) vim.list_extend(ensure_installed, { - -- You can add other tools here that you want Mason to install + 'stylua', -- Used to format Lua code }) - require('mason-tool-installer').setup { ensure_installed = ensure_installed } for name, server in pairs(servers) do @@ -671,7 +778,9 @@ require('lazy').setup({ keys = { { 'f', - function() require('conform').format { async = true, lsp_format = 'fallback' } end, + function() + require('conform').format { async = true, lsp_format = 'fallback' } + end, mode = '', desc = '[F]ormat buffer', }, @@ -718,7 +827,9 @@ require('lazy').setup({ -- Build Step is needed for regex support in snippets. -- This step is not supported in many windows environments. -- Remove the below condition to re-enable on windows. - if vim.fn.has 'win32' == 1 or vim.fn.executable 'make' == 0 then return end + if vim.fn.has 'win32' == 1 or vim.fn.executable 'make' == 0 then + return + end return 'make install_jsregexp' end)(), dependencies = { @@ -734,6 +845,7 @@ require('lazy').setup({ }, opts = {}, }, + 'folke/lazydev.nvim', }, ---@module 'blink.cmp' ---@type blink.cmp.Config @@ -779,7 +891,10 @@ require('lazy').setup({ }, sources = { - default = { 'lsp', 'path', 'snippets' }, + default = { 'lsp', 'path', 'snippets', 'lazydev' }, + providers = { + lazydev = { module = 'lazydev.integrations.blink', score_offset = 100 }, + }, }, snippets = { preset = 'luasnip' }, @@ -832,7 +947,7 @@ require('lazy').setup({ }, { -- Collection of various small independent plugins/modules - 'nvim-mini/mini.nvim', + 'echasnovski/mini.nvim', config = function() -- Better Around/Inside textobjects -- @@ -860,13 +975,14 @@ require('lazy').setup({ -- default behavior. For example, here we set the section for -- cursor location to LINE:COLUMN ---@diagnostic disable-next-line: duplicate-set-field - statusline.section_location = function() return '%2l:%-2v' end + statusline.section_location = function() + return '%2l:%-2v' + end -- ... and there is more! - -- Check out: https://github.com/nvim-mini/mini.nvim + -- Check out: https://github.com/echasnovski/mini.nvim end, }, - { -- Highlight, edit, and navigate code 'nvim-treesitter/nvim-treesitter', lazy = false, @@ -944,7 +1060,7 @@ require('lazy').setup({ -- This is the easiest way to modularize your config. -- -- Uncomment the following line and add your plugins to `lua/custom/plugins/*.lua` to get going. - -- { import = 'custom.plugins' }, + { import = 'custom.plugins' }, -- -- For additional information with loading, sourcing and examples see `:help lazy.nvim-🔌-plugin-spec` -- Or use telescope! @@ -972,5 +1088,7 @@ require('lazy').setup({ }, }) +require 'custom.init' + -- The line beneath this is called `modeline`. See `:help modeline` -- vim: ts=2 sts=2 sw=2 et diff --git a/lua/custom/init.lua b/lua/custom/init.lua new file mode 100644 index 00000000000..7ce3deb0ed7 --- /dev/null +++ b/lua/custom/init.lua @@ -0,0 +1,13 @@ +-- require("custom.keymaps") -- Custom keybindings +-- require("custom.plugins") -- Custom plugins +require 'custom.snippets.edhliicpp' -- Custom snippets +require 'custom.snippets.edhliic' -- Custom snippets +require 'custom.snippets.testgen' + +-- Set some editor options +vim.opt.number = true +vim.opt.relativenumber = true +vim.opt.tabstop = 4 +vim.opt.shiftwidth = 4 + +-- print 'Custom Neovim setup loaded!' diff --git a/lua/custom/plugins/alpha.lua b/lua/custom/plugins/alpha.lua new file mode 100644 index 00000000000..0a0b02ba140 --- /dev/null +++ b/lua/custom/plugins/alpha.lua @@ -0,0 +1,12 @@ +return { + 'goolord/alpha-nvim', + -- dependencies = { 'echasnovski/mini.icons' }, + dependencies = { 'nvim-tree/nvim-web-devicons' }, + config = function() + local startify = require 'alpha.themes.startify' + -- available: devicons, mini, default is mini + -- if provider not loaded and enabled is true, it will try to use another provider + startify.file_icons.provider = 'devicons' + require('alpha').setup(startify.config) + end, +} diff --git a/lua/custom/plugins/bufferline.lua b/lua/custom/plugins/bufferline.lua new file mode 100644 index 00000000000..969762b8871 --- /dev/null +++ b/lua/custom/plugins/bufferline.lua @@ -0,0 +1,17 @@ +return { + 'akinsho/bufferline.nvim', + dependencies = { 'nvim-tree/nvim-web-devicons' }, + config = function() + require('bufferline').setup { + options = { + diagnostics = 'nvim_lsp', + show_buffer_close_icons = true, + show_close_icon = true, + separator_style = 'slant', + }, + } + vim.keymap.set('n', '', ':BufferLineCycleNext', { silent = true }) + vim.keymap.set('n', '', ':BufferLineCyclePrev', { silent = true }) + vim.keymap.set('n', 'bd', ':bdelete', { silent = true }) + end, +} diff --git a/lua/custom/plugins/competitest.lua b/lua/custom/plugins/competitest.lua new file mode 100644 index 00000000000..a8fa39dffb0 --- /dev/null +++ b/lua/custom/plugins/competitest.lua @@ -0,0 +1,9 @@ +return { + { + 'xeluxee/competitest.nvim', + dependencies = 'MunifTanjim/nui.nvim', + config = function() + require('competitest').setup() + end, + }, +} diff --git a/lua/custom/plugins/luasnip.lua b/lua/custom/plugins/luasnip.lua new file mode 100644 index 00000000000..3cce2054126 --- /dev/null +++ b/lua/custom/plugins/luasnip.lua @@ -0,0 +1,10 @@ +return { + { + 'L3MON4D3/LuaSnip', + version = 'v2.*', -- Latest version + dependencies = { 'rafamadriz/friendly-snippets' }, + config = function() + require('luasnip.loaders.from_vscode').lazy_load() + end, + }, +} diff --git a/lua/custom/plugins/minipairs.lua b/lua/custom/plugins/minipairs.lua new file mode 100644 index 00000000000..4d28f04388c --- /dev/null +++ b/lua/custom/plugins/minipairs.lua @@ -0,0 +1,9 @@ +return { + { + 'echasnovski/mini.pairs', + version = false, -- Use the latest version + config = function() + require('mini.pairs').setup() + end, + }, +} diff --git a/lua/custom/plugins/minisurround.lua b/lua/custom/plugins/minisurround.lua new file mode 100644 index 00000000000..aa5e3be2920 --- /dev/null +++ b/lua/custom/plugins/minisurround.lua @@ -0,0 +1 @@ +return { 'echasnovski/mini.surround', version = false } diff --git a/lua/custom/plugins/neo-tree.lua b/lua/custom/plugins/neo-tree.lua new file mode 100644 index 00000000000..2f1fbcb3ca0 --- /dev/null +++ b/lua/custom/plugins/neo-tree.lua @@ -0,0 +1,32 @@ +return { + 'nvim-neo-tree/neo-tree.nvim', + branch = 'v3.x', + dependencies = { + 'nvim-lua/plenary.nvim', + 'nvim-tree/nvim-web-devicons', + 'MunifTanjim/nui.nvim', + }, + config = function() + require('neo-tree').setup { + filesystem = { + filtered_items = { + visible = true, + hide_dotfiles = false, + hide_gitignored = false, + }, + follow_current_file = { enabled = true }, -- Highlight current file + use_libuv_file_watcher = true, -- Auto-update tree when files change + }, + window = { + mappings = { + ['l'] = 'open', -- Set 'l' to open files + ['h'] = 'close_node', -- Collapse folders with 'h' + [''] = 'open', + }, + }, + } + + -- Set keymap to open Neo-tree with + e + vim.keymap.set('n', 'e', ':Neotree toggle', { noremap = true, silent = true }) + end, +} diff --git a/lua/custom/plugins/theme.lua b/lua/custom/plugins/theme.lua new file mode 100644 index 00000000000..1a1d832ceaf --- /dev/null +++ b/lua/custom/plugins/theme.lua @@ -0,0 +1,12 @@ +return { + 'folke/tokyonight.nvim', + priority = 1000, + config = function() + require('tokyonight').setup { + style = 'moon', -- Options: night, storm, moon, day + transparent = false, -- Enable transparent background + terminal_colors = true, + } + vim.cmd [[colorscheme tokyonight]] + end, +} diff --git a/lua/custom/snippets/edhliic.lua b/lua/custom/snippets/edhliic.lua new file mode 100644 index 00000000000..b643b290e90 --- /dev/null +++ b/lua/custom/snippets/edhliic.lua @@ -0,0 +1,27 @@ +local ls = require 'luasnip' +local s = ls.snippet +local t = ls.text_node + +ls.add_snippets('c', { + s('ctemplate', { + t { + '#include ', + '#include ', + '#include ', + '#include ', + '#define N 1000006', + '#define MOD 1000000007', + 'typedef long long ll;', + 'typedef unsigned long long ull;', + '', + 'void process() {}', + '', + 'int main() {', + ' int T;', + ' scanf("%d", &T);', + ' while (T--)', + ' process();', + '}', + }, + }), +}) diff --git a/lua/custom/snippets/edhliicpp.lua b/lua/custom/snippets/edhliicpp.lua new file mode 100644 index 00000000000..c10a73d1dff --- /dev/null +++ b/lua/custom/snippets/edhliicpp.lua @@ -0,0 +1,291 @@ +-- print 'Custom C++ snippets loaded!' + +local ls = require 'luasnip' +local s = ls.snippet +local t = ls.text_node +local i = ls.insert_node +local fmt = require('luasnip.extras.fmt').fmt +local rep = require('luasnip.extras').rep + +ls.add_snippets('cpp', { + s('cpptemplate', { + t { + '#include ', + '#define fi first', + '#define se second', + 'using namespace std;', + 'typedef long long ll;', + 'typedef unsigned long long ull;', + 'const int N = 1000006;', + 'const ll MOD = 1000000007;', + '', + 'int main() {', + ' ios_base::sync_with_stdio(false);', + ' cin.tie(0);', + ' cout.tie(0);', + '', + ' cout << "edhlii\\n";', + '}', + }, + }), + s('segtree', { + t { + 'struct SegTree {', + ' int n;', + ' vector tree;', + '', + ' inline int combine(int a, int b) {', + ' // TODO: chỉnh sửa hàm combine cho phù hợp (vd: min(a, b), max(a, b), a + b, ...)', + ' return a + b;', + ' }', + '', + ' SegTree(const vector &arr) {', + ' n = arr.size();', + ' tree.resize(n << 1);', + ' for (int i = 0; i < n; ++i)', + ' tree[i + n] = arr[i];', + ' for (int i = n - 1; i > 0; --i)', + ' tree[i] = combine(tree[i << 1], tree[i << 1 | 1]);', + ' }', + '', + ' inline void update(int pos, int val) {', + ' pos += n;', + ' tree[pos] = val;', + ' for (pos >>= 1; pos; pos >>= 1)', + ' tree[pos] = combine(tree[pos << 1], tree[pos << 1 | 1]);', + ' }', + '', + ' inline int query(int l, int r) {', + ' int resL = 0, resR = 0; // TODO: chỉnh phần tử đơn vị phù hợp', + ' l += n;', + ' r += n;', + ' while (l < r) {', + ' if (l & 1)', + ' resL = combine(resL, tree[l++]);', + ' if (r & 1)', + ' resR = combine(tree[--r], resR);', + ' l >>= 1;', + ' r >>= 1;', + ' }', + ' return combine(resL, resR);', + ' }', + '};', + }, + }), + s('binpow', { + t { + 'll binpow(ll a, ll b, ll c) {', + ' ll res = 1;', + ' while (b != 0) {', + ' if (b & 1) {', + ' res = (res * a) % c;', + ' }', + ' b = b >> 1;', + ' a = (a * a) % c;', + ' }', + ' return res;', + '}', + }, + }), + s('bigint', { + t { + 'struct BigInt {', + ' string value;', + ' bool negative;', + ' BigInt() : value("0"), negative(false) {}', + ' BigInt(const string &s) { fromString(s); }', + ' void fromString(const string &s) {', + ' int i = 0;', + ' negative = false;', + ' value.clear();', + " if (s[i] == '-') {", + ' negative = true;', + ' i++;', + " } else if (s[i] == '+')", + ' i++;', + " while (i < (int)s.size() && s[i] == '0')", + ' i++;', + ' value = s.substr(i);', + ' if (value.empty())', + ' value = "0", negative = false;', + ' }', + ' string toString() const {', + ' return (negative && value != "0" ? "-" : "") + value;', + ' }', + ' friend ostream &operator<<(ostream &os, const BigInt &b) {', + ' return os << b.toString();', + ' }', + ' int absCompare(const BigInt &other) const {', + ' if (value.size() != other.value.size())', + ' return value.size() < other.value.size() ? -1 : 1;', + ' return value.compare(other.value);', + ' }', + ' bool operator==(const BigInt &other) const {', + ' return negative == other.negative && value == other.value;', + ' }', + ' bool operator<(const BigInt &other) const {', + ' if (negative != other.negative)', + ' return negative;', + ' int cmp = absCompare(other);', + ' return negative ? cmp > 0 : cmp < 0;', + ' }', + ' bool operator>(const BigInt &other) const { return other < *this; }', + ' BigInt operator+(const BigInt &other) const {', + ' if (negative == other.negative) {', + ' return BigInt(add(value, other.value), negative);', + ' } else {', + ' int cmp = absCompare(other);', + ' if (cmp == 0)', + ' return BigInt("0");', + ' if (cmp > 0)', + ' return BigInt(sub(value, other.value), negative);', + ' else', + ' return BigInt(sub(other.value, value), other.negative);', + ' }', + ' }', + ' BigInt operator-(const BigInt &other) const {', + ' BigInt negOther = other;', + ' negOther.negative = !other.negative;', + ' return *this + negOther;', + ' }', + ' BigInt operator*(const BigInt &other) const {', + " string result(value.size() + other.value.size(), '0');", + ' for (int i = value.size() - 1; i >= 0; --i) {', + ' int carry = 0;', + ' for (int j = other.value.size() - 1; j >= 0; --j) {', + " int tmp = (value[i] - '0') * (other.value[j] - '0') +", + " (result[i + j + 1] - '0') + carry;", + " result[i + j + 1] = tmp % 10 + '0';", + ' carry = tmp / 10;', + ' }', + ' result[i] += carry;', + ' }', + ' int i = 0;', + " while (i < (int)result.size() - 1 && result[i] == '0')", + ' i++;', + ' return BigInt(result.substr(i), negative != other.negative);', + ' }', + ' BigInt operator/(const BigInt &other) const {', + ' return divmod(*this, other).first;', + ' }', + ' BigInt operator%(const BigInt &other) const {', + ' return divmod(*this, other).second;', + ' }', + 'private:', + ' BigInt(const string &s, bool neg) : value(s), negative(neg) {', + ' if (value == "0")', + ' negative = false;', + ' }', + ' static string add(const string &a, const string &b) {', + ' string res;', + ' int carry = 0, i = a.size() - 1, j = b.size() - 1;', + ' while (i >= 0 || j >= 0 || carry) {', + ' int sum = carry;', + " if (i >= 0) sum += a[i--] - '0';", + " if (j >= 0) sum += b[j--] - '0';", + " res += sum % 10 + '0';", + ' carry = sum / 10;', + ' }', + ' reverse(res.begin(), res.end());', + ' return res;', + ' }', + ' static string sub(const string &a, const string &b) {', + ' string res;', + ' int borrow = 0, i = a.size() - 1, j = b.size() - 1;', + ' while (i >= 0) {', + " int diff = a[i] - '0' - (j >= 0 ? b[j--] - '0' : 0) - borrow;", + ' if (diff < 0) diff += 10, borrow = 1;', + ' else borrow = 0;', + " res += diff + '0';", + ' i--;', + ' }', + " while (res.size() > 1 && res.back() == '0')", + ' res.pop_back();', + ' reverse(res.begin(), res.end());', + ' return res;', + ' }', + ' static pair divmod(BigInt a, BigInt b) {', + ' if (b.value == "0")', + ' throw runtime_error("Division by zero");', + ' BigInt quotient, remainder;', + ' quotient.value.clear();', + ' remainder = BigInt("0");', + ' for (char digit : a.value) {', + ' remainder = remainder * BigInt("10") + BigInt(string(1, digit));', + ' int count = 0;', + ' while (remainder > b || remainder == b) {', + ' remainder = remainder - b;', + ' count++;', + ' }', + " quotient.value += count + '0';", + ' }', + ' int i = 0;', + " while (i < (int)quotient.value.size() - 1 && quotient.value[i] == '0')", + ' i++;', + ' quotient.value = quotient.value.substr(i);', + ' quotient.negative = a.negative != b.negative;', + ' remainder.negative = a.negative;', + ' if (quotient.value == "0")', + ' quotient.negative = false;', + ' if (remainder.value == "0")', + ' remainder.negative = false;', + ' return {quotient, remainder};', + ' }', + '};', + }, + }), + s('rollinghash', { + t { + 'struct RollingHash {', + ' using ll = long long;', + ' ll base, mod;', + ' vector power;', + ' vector prefix_hash;', + ' RollingHash(const string &s, ll base, ll mod) : base(base), mod(mod) {', + ' int n = s.size();', + ' power.resize(n + 1, 1);', + ' prefix_hash.resize(n + 1, 0);', + ' for (int i = 0; i < n; ++i) {', + ' power[i + 1] = (__int128)power[i] * base % mod;', + ' prefix_hash[i + 1] = ((__int128)prefix_hash[i] * base + s[i]) % mod;', + ' }', + ' }', + ' ll get_hash(int l, int r) {', + ' ll hash_r = prefix_hash[r + 1];', + ' ll hash_l = (__int128)prefix_hash[l] * power[r - l + 1] % mod;', + ' ll res = (hash_r - hash_l + mod) % mod;', + ' return res;', + ' }', + '};', + }, + }), + s( + 'fib', + fmt( + [[ +pair {}(ll {}) {{ + if ({} == 0) + return {{0, 1}}; + auto p = {}({} >> 1); + ll a = p.first; + ll b = p.second; + ll c = (a * ((2 * b % MOD - a + MOD) % MOD)) % MOD; + ll d = ((a * a) % MOD + (b * b) % MOD) % MOD; + if ({} & 1) {{ + return {{d, (c + d) % MOD}}; + }} else {{ + return {{c, d}}; + }} +}} +]], + { + i(1, 'fibonacci'), -- function name + i(2, 'n'), -- input variable + rep(2), -- reuse n + rep(1), -- reuse function name + rep(2), -- reuse n + rep(2), -- reuse n + } + ) + ), +}) diff --git a/lua/custom/snippets/testgen.lua b/lua/custom/snippets/testgen.lua new file mode 100644 index 00000000000..cc81e97b7e2 --- /dev/null +++ b/lua/custom/snippets/testgen.lua @@ -0,0 +1,48 @@ +local ls = require 'luasnip' +local s = ls.snippet +local t = ls.text_node + +ls.add_snippets('cpp', { + s('testgen', { + t { + '#include ', + '#define NAME "BAI1"', + 'using namespace std;', + 'typedef long long ll;', + 'typedef unsigned long long ull;', + 'const int N = 1000006;', + 'const ll MOD = 1000000007;', + '', + 'const int NTEST = 100;', + 'mt19937 rd(chrono::steady_clock::now().time_since_epoch().count());', + '', + 'long long Rand(long long l, long long h) {', + ' unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();', + ' mt19937 gen(seed);', + ' uniform_int_distribution dis(l, h);', + ' long long x = dis(gen);', + ' return x;', + '}', + '', + 'void MakeTest() {', + ' ofstream cout(NAME ".INP");', + ' cout << "test";', + '}', + '', + 'int main() {', + ' srand(time(0));', + ' for (int iTest = 1; iTest <= NTEST; iTest++) {', + ' MakeTest();', + ' system("./" NAME "_trau");', + ' system("./" NAME);', + ' if (system("diff " NAME ".OUT " NAME ".ANS") != 0) {', + ' cout << "Test " << iTest << ": WRONG!\\n";', + ' return 0;', + ' }', + ' cout << "Test " << iTest << ": CORRECT!\\n";', + ' }', + ' return 0;', + '}', + }, + }), +})