-- See `:help mapleader` -- Must happen before plugins are loaded (otherwise wrong leader will be used) vim.g.mapleader = ' ' vim.g.maplocalleader = ' ' -- vim.keymap.set('i', 'kj', '') vim.keymap.set('n', ';', ':') vim.keymap.set('n', 'nt', ':Neotree') vim.keymap.set('v', 'p', '"_dP') vim.keymap.set('v', 'y', '"+y') vim.keymap.set('n', 'Y', 'gg"+yG') vim.keymap.set('n', 'lb', ':set linebreak wrap', { desc = 'set [l]ine[b]reak and wrap' }) -- vim.keymap.set('n', 'sh', builtin.help_tags, { desc = '[S]earch [H]elp' }) -- vim.keymap.set('n', 'ex', ':Vex') -- vim.keymap.set('n', '', '') -- -- See `:help 'clipboard'` vim.opt.clipboard = 'unnamed' vim.schedule(function() vim.opt.clipboard = 'unnamedplus' end) -- Move selected text down vim.api.nvim_set_keymap('v', 'J', ":m '>+1gv=gv", { noremap = true, silent = true }) -- Move selected text up vim.api.nvim_set_keymap('v', 'K', ":m '<-2gv=gv", { noremap = true, silent = true }) vim.opt.relativenumber = true vim.opt.number = true vim.opt.scrolloff = 12 vim.opt.tabstop = 4 vim.opt.shiftwidth = 4 vim.opt.softtabstop = 4 vim.opt.expandtab = true vim.opt.smartindent = true vim.opt.wrap = false vim.opt.mouse = 'a' vim.opt.termguicolors = true vim.o.confirm = true vim.g.have_nerd_font = true vim.opt.spell = false -- This clears the background color of nvim vim.cmd [[ highlight Normal guibg=none highlight NonText guibg=none highlight Normal ctermbg=none highlight NonText ctermbg=none ]] vim.api.nvim_create_autocmd({"BufRead", "BufNewFile"}, { pattern = "*.tmpl", callback = function() vim.opt_local.commentstring = "" -- Use the HTML comment string end, }) -- Set to true if you have a Nerd Font installed and selected in the terminal -- [[ Setting options ]] -- See `:help vim.opt` -- NOTE: You can change these options as you wish! -- For more options, you can see `:help option-list` -- Make line numbers default -- You can also add relative line numbers, to help with jumping. -- Experiment for yourself to see if you like it! -- Don't show the mode, since it's already in the status line vim.opt.showmode = false -- Enable break indent vim.opt.breakindent = true -- Save undo history vim.opt.undofile = true -- Case-insensitive searching UNLESS \C or one or more capital letters in the search term vim.opt.ignorecase = true vim.opt.smartcase = true -- Keep signcolumn on by default vim.opt.signcolumn = 'yes' -- Decrease update time vim.opt.updatetime = 250 -- Decrease mapped sequence wait time -- Displays which-key popup sooner vim.opt.timeoutlen = 300 -- Configure how new splits should be opened vim.opt.splitright = true vim.opt.splitbelow = true -- Sets how neovim will display certain whitespace characters in the editor. -- See `:help 'list'` -- and `:help 'listchars'` -- vim.opt.list = true -- vim.opt.listchars = { space ='·' ,tab = '» ', trail = '·', nbsp = '␣' } -- Preview substitutions live, as you type! vim.opt.inccommand = 'split' -- Show which line your cursor is on vim.opt.cursorline = true -- nvim-ufo fold settings vim.opt.foldcolumn = '1' vim.opt.foldlevel = 99 vim.opt.foldlevelstart = 99 vim.opt.foldenable = true -- [[ Basic Autocommands ]] -- See `:help lua-guide-autocommands` -- Highlight when yanking (copying) text -- Try it with `yap` in normal mode -- See `:help vim.highlight.on_yank()` 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.highlight.on_yank() end, }) -- [[ Install `lazy.nvim` plugin manager ]] -- See `:help lazy.nvim.txt` or https://github.com/folke/lazy.nvim for more info local lazypath = vim.fn.stdpath 'data' .. '/lazy/lazy.nvim' if not vim.uv.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 end ---@diagnostic disable-next-line: undefined-field vim.opt.rtp:prepend(lazypath) require('lazy').setup({ 'brenoprata10/nvim-highlight-colors', { 'ThePrimeagen/harpoon', branch = 'harpoon2', dependencies = { 'nvim-lua/plenary.nvim' }, }, -- { "rose-pine/neovim", name = "rose-pine" }, { 'sphamba/smear-cursor.nvim', opts = {}, }, { -- Useful plugin to show you pending keybinds. 'folke/which-key.nvim', event = 'VimEnter', -- Sets the loading event to 'VimEnter' config = function() -- This is the function that runs, AFTER loading require('which-key').setup() -- Document existing key chains require('which-key').add { { 'c', group = '[C]ode' }, { 'd', group = '[D]ocument' }, { 'g', group = '[G]it' }, { 'r', group = '[R]ename' }, { 's', group = '[S]earch' }, { 'w', group = '[W]orkspace' }, { 't', group = '[T]oggle' }, -- { 'h', group = 'Git [H]unk', mode = { 'n', 'v' } }, } end, }, { 'nvim-neo-tree/neo-tree.nvim', branch = 'v3.x', dependencies = { 'nvim-lua/plenary.nvim', 'nvim-tree/nvim-web-devicons', -- not strictly required, but recommended 'MunifTanjim/nui.nvim', -- "3rd/image.nvim", -- Optional image support in preview window: See `# Preview Mode` for more information }, config = function() require('neo-tree').setup { commands = { -- open the node (toggling directories); if it's a file, also close neo-tree open_and_close = function(state) local node = state.tree and state.tree:get_node() require('neo-tree.sources.filesystem.commands').open(state) if node and node.type == 'file' then require('neo-tree.command').execute { action = 'close' } end end, }, window = { mappings = { -- enter: open file and close neo-tree [''] = 'open_and_close', -- shift+enter: open file but keep neo-tree open -- NOTE: is only distinguishable from if the terminal sends a -- distinct escape sequence (kitty keyboard protocol terminals, or tmux with -- extended-keys on, plus nvim 0.10+). Otherwise it acts like plain -- and closes neo-tree too. If so, swap it for or e.g. . [''] = 'open', }, }, } end, }, { -- Fuzzy Finder (files, lsp, etc) 'nvim-telescope/telescope.nvim', event = 'VimEnter', version = '*', dependencies = { 'nvim-lua/plenary.nvim', { -- If encountering errors, see telescope-fzf-native README for installation instructions 'nvim-telescope/telescope-fzf-native.nvim', -- `build` is used to run some command when the plugin is installed/updated. -- This is only run then, not every time neovim starts up. build = 'make', -- `cond` is a condition used to determine whether this plugin should be -- installed and loaded. cond = function() return vim.fn.executable 'make' == 1 end, }, { 'nvim-telescope/telescope-ui-select.nvim' }, -- Useful for getting pretty icons, but requires a Nerd Font. { 'nvim-tree/nvim-web-devicons', enabled = vim.g.have_nerd_font }, }, config = function() -- :Telescope help_tags -- See `:help telescope` and `:help telescope.setup()` require('telescope').setup { extensions = { ['ui-select'] = { require('telescope.themes').get_dropdown(), }, }, } -- Enable Telescope extensions if they are installed pcall(require('telescope').load_extension, 'fzf') pcall(require('telescope').load_extension, 'ui-select') -- See `:help telescope.builtin` local builtin = require 'telescope.builtin' vim.keymap.set('n', 'sh', builtin.help_tags, { desc = '[S]earch [H]elp' }) 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', 'sw', builtin.grep_string, { desc = '[S]earch current [W]ord' }) vim.keymap.set('n', 'sg', builtin.live_grep, { desc = '[S]earch by [G]rep' }) local function get_visual_selection() vim.cmd('noau normal! "vy"') local text = vim.fn.getreg('v') vim.fn.setreg('v', {}) text = text:gsub('\n', ' '):gsub('^%s+', ''):gsub('%s+$', '') if text == '' then return nil end return text end vim.keymap.set('v', 'sg', function() local text = get_visual_selection() if not text then return end builtin.live_grep { default_text = text, additional_args = { '--fixed-strings' }, } end, { desc = '[S]earch visual selection 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', '', builtin.buffers, { desc = '[ ] Find existing buffers' }) -- 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 { winblend = 10, previewer = false, }) end, { desc = '[/] Fuzzily search in current buffer' }) -- 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' }) -- 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' }) end, }, -- extra color theme plugins { "savq/melange-nvim" }, { "dgox16/oldworld.nvim", lazy = false, priority = 1000, init = function() vim.cmd.colorscheme 'oldworld' -- You can configure highlights by doing something like: vim.cmd.hi 'Comment gui=none' end, }, { -- Available fallback colorscheme (switch with `:colorscheme tokyonight-night` etc.) 'folke/tokyonight.nvim', priority = 1000, -- Make sure to load this before all the other start plugins. }, -- Highlight todo, notes, etc in comments { 'folke/todo-comments.nvim', event = 'VimEnter', dependencies = { 'nvim-lua/plenary.nvim' }, opts = { signs = false } }, { 'windwp/nvim-autopairs', event = "InsertEnter", config = true -- use opts = {} for passing setup options -- this is equivalent to setup({}) function }, -- [[ Embedded Language LSP (Otter) ]] { 'jmbuhr/otter.nvim', dependencies = { 'nvim-treesitter/nvim-treesitter' }, config = function() require('otter').setup() vim.api.nvim_create_autocmd('FileType', { pattern = { 'html', 'htmldjango', 'blade' }, callback = function(args) -- Otter requires an active treesitter parser for the host buffer. pcall(vim.treesitter.start, args.buf) require('otter').activate({ 'javascript', 'css' }) end, }) end, }, -- [[ Tree-sitter ]] { 'nvim-treesitter/nvim-treesitter', branch = 'main', lazy = false, build = ':TSUpdate', config = function() require('nvim-treesitter').setup() local install_langs = { 'python', 'go', 'javascript', 'typescript', 'rust', 'lua', 'c', 'html', 'css', 'vim', 'vimdoc', 'query', 'markdown', 'markdown_inline', } -- Ensure parsers are installed/updated (async is fine at startup). require('nvim-treesitter').install(install_langs) -- Register the HTML parser for templating filetypes that lack one. vim.treesitter.language.register('html', { 'htmldjango', 'blade' }) -- Enable treesitter highlighting and indentation per filetype. local ts_filetypes = { 'python', 'go', 'javascript', 'typescript', 'rust', 'lua', 'c', 'html', 'htmldjango', 'blade', 'css', 'vim', 'vimdoc', 'query', 'markdown', } vim.api.nvim_create_autocmd('FileType', { pattern = ts_filetypes, callback = function(args) pcall(vim.treesitter.start, args.buf) vim.bo[args.buf].indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()" end, }) end, }, -- [[ LSP ]] { 'williamboman/mason.nvim', config = function() -- Mason manages no JS/TS servers; those come from TypeScript 7's -- native tsc (tsc --lsp) plus html/cssls, installed globally -- and pinned via dev_env.sh. require('mason').setup() end, }, { 'williamboman/mason-lspconfig.nvim', dependencies = { 'williamboman/mason.nvim', 'neovim/nvim-lspconfig' }, config = function() require('mason-lspconfig').setup { -- Mason handles only the Lua/C servers. JS/TS/HTML/CSS come from -- TypeScript 7's native tsc + html/cssls, installed globally -- (pinned) via dev_env.sh; Python comes from ty (uv), also via -- dev_env.sh; gopls is pinned via `go install` and rust-analyzer -- via `rustup component add` in dev_env.sh — neither managed here. ensure_installed = { 'lua_ls', 'clangd', }, automatic_enable = { -- ty replaces pyright; never auto-enable it even if a stale -- Mason copy is still installed. exclude = { 'pyright' }, }, } end, }, { 'neovim/nvim-lspconfig', dependencies = { 'williamboman/mason-lspconfig.nvim', 'hrsh7th/cmp-nvim-lsp', }, config = function() local capabilities = require('cmp_nvim_lsp').default_capabilities() -- Apply capabilities to all servers via wildcard config vim.lsp.config('*', { capabilities = capabilities, }) -- Server-specific overrides vim.lsp.config('lua_ls', { settings = { Lua = { runtime = { version = 'LuaJIT' }, workspace = { checkThirdParty = false, library = { '${3rd}/luv/library', unpack(vim.api.nvim_get_runtime_file('', true)), }, }, completion = { callSnippet = 'Replace' }, diagnostics = { disable = { 'spell-check' }, }, }, }, }) -- Node-based servers, installed globally (pinned) via dev_env.sh: -- - tsc: JS/TS via TypeScript 7's native LSP (tsc --lsp --stdio). -- - html / cssls: vscode-langservers-extracted. -- ty (Python type checker + LSP, via uv) uses nvim-lspconfig defaults. vim.lsp.enable({ 'tsc', 'html', 'cssls', 'ty' }) vim.api.nvim_create_autocmd('LspAttach', { group = vim.api.nvim_create_augroup('kickstart-lsp-attach', { clear = true }), callback = function(ev) local bufnr = ev.buf local map = function(keys, func, desc) vim.keymap.set('n', keys, func, { buffer = bufnr, desc = 'LSP: ' .. desc }) end map('gd', vim.lsp.buf.definition, '[G]oto [D]efinition') map('gr', vim.lsp.buf.references, '[G]oto [R]eferences') map('gI', vim.lsp.buf.implementation, '[G]oto [I]mplementation') map('D', vim.lsp.buf.type_definition, 'Type [D]efinition') map('K', vim.lsp.buf.hover, 'Hover Documentation') map('rn', vim.lsp.buf.rename, '[R]e[n]ame') map('ca', vim.lsp.buf.code_action, '[C]ode [A]ction') map('f', function() vim.lsp.buf.format { async = true } end, '[F]ormat buffer') map('ds', vim.lsp.buf.document_symbol, '[D]ocument [S]ymbols') map('e', vim.diagnostic.open_float, '[E]xplain diagnostic') vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, { buffer = bufnr, desc = 'LSP: Previous diagnostic' }) vim.keymap.set('n', ']d', vim.diagnostic.goto_next, { buffer = bufnr, desc = 'LSP: Next diagnostic' }) end, }) end, }, { 'j-hui/fidget.nvim', opts = {}, }, { 'folke/lazydev.nvim', ft = 'lua', opts = {}, }, -- [[ Completion ]] { 'hrsh7th/nvim-cmp', event = 'InsertEnter', dependencies = { 'hrsh7th/cmp-nvim-lsp', 'hrsh7th/cmp-buffer', 'hrsh7th/cmp-path', 'hrsh7th/cmp-cmdline', { 'L3MON4D3/LuaSnip', dependencies = { 'rafamadriz/friendly-snippets' }, config = function() require('luasnip').setup { load_ft_func = require('luasnip.extras.filetype_functions').extend_load_ft { html = { 'javascript', 'jsdoc' }, }, } require('luasnip.loaders.from_vscode').lazy_load() end, }, 'saadparwaiz1/cmp_luasnip', }, config = function() local cmp = require('cmp') local luasnip = require('luasnip') cmp.setup { snippet = { expand = function(args) luasnip.lsp_expand(args.body) end, }, mapping = cmp.mapping.preset.insert { [''] = cmp.mapping.select_next_item(), [''] = cmp.mapping.select_prev_item(), [''] = cmp.mapping.scroll_docs(-4), [''] = cmp.mapping.scroll_docs(4), [''] = cmp.mapping.confirm { select = true }, [''] = cmp.mapping.complete {}, [''] = cmp.mapping(function(fallback) if luasnip.expand_or_jumpable() then luasnip.expand_or_jump() else fallback() end end, { 'i', 's' }), [''] = cmp.mapping(function(fallback) if luasnip.jumpable(-1) then luasnip.jump(-1) else fallback() end end, { 'i', 's' }), }, sources = cmp.config.sources { { name = 'nvim_lsp' }, { name = 'luasnip' }, { name = 'buffer' }, { name = 'path' }, }, } -- Use buffer source for `/` and `?` cmp.setup.cmdline({ '/', '?' }, { mapping = cmp.mapping.preset.cmdline(), sources = { { name = 'buffer' }, }, }) -- Use cmdline & path source for `:` cmp.setup.cmdline(':', { mapping = cmp.mapping.preset.cmdline(), sources = cmp.config.sources { { name = 'path' }, { name = 'cmdline' }, }, }) end, }, { 'kevinhwang91/nvim-ufo', dependencies = 'kevinhwang91/promise-async', config = function() vim.keymap.set('n', 'zR', require('ufo').openAllFolds) vim.keymap.set('n', 'zM', require('ufo').closeAllFolds) vim.keymap.set('n', 'zr', require('ufo').openFoldsExceptKinds) vim.keymap.set('n', 'zm', require('ufo').closeFoldsWith) require('ufo').setup({ provider_selector = function(bufnr, filetype, buftype) return { 'lsp', 'indent' } end, }) end, }, { 'tpope/vim-fugitive', }, { 'stevearc/quicker.nvim', ft = 'qf', ---@module "quicker" ---@type quicker.SetupOptions opts = { keys = { { '>', function() require('quicker').expand({ before = 2, after = 2, add_to_existing = true }) end, desc = 'Expand quickfix context', }, { '<', function() require('quicker').collapse() end, desc = 'Collapse quickfix context', }, }, }, }, }, { ui = { -- If you are using a Nerd Font: set icons to an empty table which will use the -- default lazy.nvim defined Nerd Font icons, otherwise define a unicode icons table icons = vim.g.have_nerd_font and {} or { cmd = '⌘', config = '🛠', event = '📅', ft = '📂', init = '⚙', keys = '🗝', plugin = '🔌', runtime = '💻', require = '🌙', source = '📄', start = '🚀', task = '📌', lazy = '💤 ', }, }, }) require('nvim-highlight-colors').setup { render = 'virtual', } local harpoon = require 'harpoon' -- REQUIRED harpoon:setup() -- REQUIRED vim.keymap.set('n', 'h', function() harpoon:list():add() end, { desc = 'add to [H]arpoon' }) -- vim.keymap.set('n', 'a', function() -- harpoon:list():add() -- end, { desc = '[a]dd to Harpoon' }) vim.keymap.set('n', '', function() harpoon.ui:toggle_quick_menu(harpoon:list()) end) vim.keymap.set('n', '', function() harpoon:list():select(1) end) vim.keymap.set('n', '', function() harpoon:list():select(2) end) vim.keymap.set('n', '', function() harpoon:list():select(3) end) vim.keymap.set('n', '', function() harpoon:list():select(4) end) vim.keymap.set('n', '', function() harpoon:list():select(5) end) vim.keymap.set('n', '', function() harpoon:list():select(6) end) vim.keymap.set('n', '', function() harpoon:list():select(7) end) -- Toggle previous & next buffers stored within Harpoon list vim.keymap.set('n', '', function() harpoon:list():prev() end) vim.keymap.set('n', '', function() harpoon:list():next() end) -- basic telescope configuration local conf = require('telescope.config').values local function toggle_telescope(harpoon_files) local file_paths = {} for _, item in ipairs(harpoon_files.items) do table.insert(file_paths, item.value) end require('telescope.pickers') .new({}, { prompt_title = 'Harpoon', finder = require('telescope.finders').new_table { results = file_paths, }, previewer = conf.file_previewer {}, sorter = conf.generic_sorter {}, }) :find() end vim.keymap.set('n', '', function() toggle_telescope(harpoon:list()) end, { desc = 'Open harpoon window' }) -- Fugitive (Git) keymaps vim.keymap.set('n', 'gs', ':G', { desc = '[G]it [S]tatus' }) vim.keymap.set('n', 'gd', ':Gdiffsplit', { desc = '[G]it [D]iff' }) vim.keymap.set('n', 'gb', ':G blame', { desc = '[G]it [B]lame' }) vim.keymap.set('n', 'gl', ':G log', { desc = '[G]it [L]og' }) vim.keymap.set('n', 'gw', ':G write', { desc = '[G]it [W]rite (stage file)' }) -- Quicker (quickfix) keymaps vim.keymap.set('n', 'q', function() require('quicker').toggle() end, { desc = 'Toggle quickfix' }) vim.keymap.set('n', 'l', function() require('quicker').toggle({ loclist = true }) end, { desc = 'Toggle loclist' })