diff --git a/init.lua b/init.lua index aff5250..b74196f 100644 --- a/init.lua +++ b/init.lua @@ -11,9 +11,7 @@ ======== || || | === | ======== ======== || || |-----| ======== ======== ||:Tutor || |:::::| ======== -======== |'-..................-'| |____o| ======== -======== `"")----------------(""` ___________ ======== -======== /::::::::::| |::::::::::\ \ no mouse \ ======== +======== |'-..................-'| |____o| ======== ======== `"")----------------(""` ___________ ======== ======== /::::::::::| |::::::::::\ \ no mouse \ ======== ======== /:::========| |==hjkl==:::\ \ required \ ======== ======== '""""""""""""' '""""""""""""' '""""""""""' ======== ======== ======== @@ -96,7 +94,7 @@ do -- See `:help mapleader` -- NOTE: Must happen before plugins are loaded (otherwise wrong leader will be used) vim.g.mapleader = ' ' - vim.g.maplocalleader = ' ' + vim.g.maplocalleader = 'l' -- Set to true if you have a Nerd Font installed and selected in the terminal vim.g.have_nerd_font = false @@ -209,7 +207,7 @@ do }, } - vim.keymap.set('n', 'q', vim.diagnostic.setloclist, { desc = 'Open diagnostic [Q]uickfix list' }) + vim.keymap.set('n', 'h', vim.diagnostic.setloclist, { desc = 'Open diagnostic Quickfix list' }) -- Exit terminal mode in the builtin terminal with a shortcut that is a bit easier -- for people to discover. Otherwise, you normally need to press , which @@ -369,9 +367,9 @@ do icons = { mappings = vim.g.have_nerd_font }, -- Document existing key chains spec = { - { 's', group = '[S]earch', mode = { 'n', 'v' } }, - { 't', group = '[T]oggle' }, - { 'h', group = 'Git [H]unk', mode = { 'n', 'v' } }, -- Enable gitsigns recommended keymaps first + { 'f', group = 'Telescope Find' }, + { 'c', group = 'Config Toggle' }, + { 'h', group = 'Help Errors', mode = { 'n', 'v' } }, { 'gr', group = 'LSP Actions', mode = { 'n' } }, }, } @@ -382,18 +380,18 @@ do -- change the command under that to load whatever the name of that colorscheme is. -- -- If you want to see what colorschemes are already installed, you can use `:Telescope colorscheme`. - vim.pack.add { gh 'folke/tokyonight.nvim' } - ---@diagnostic disable-next-line: missing-fields - require('tokyonight').setup { - styles = { - comments = { italic = false }, -- Disable italics in comments - }, - } + -- vim.pack.add { gh 'folke/tokyonight.nvim' } + -- ---@diagnostic disable-next-line: missing-fields + -- require('tokyonight').setup { + -- styles = { + -- comments = { italic = false }, -- Disable italics in comments + -- }, + -- } -- Load the colorscheme here. -- Like many other themes, this one has different styles, and you could load -- any other, such as 'tokyonight-storm', 'tokyonight-moon', or 'tokyonight-day'. - vim.cmd.colorscheme 'tokyonight-night' + -- vim.cmd.colorscheme 'tokyonight-night' -- Highlight todo, notes, etc in comments vim.pack.add { gh 'folke/todo-comments.nvim' } @@ -483,6 +481,7 @@ do gh 'nvim-lua/plenary.nvim', gh 'nvim-telescope/telescope.nvim', gh 'nvim-telescope/telescope-ui-select.nvim', + gh 'debugloop/telescope-undo.nvim', } if vim.fn.executable 'make' == 1 then table.insert(telescope_plugins, gh 'nvim-telescope/telescope-fzf-native.nvim') end @@ -508,20 +507,43 @@ do -- Enable Telescope extensions if they are installed pcall(require('telescope').load_extension, 'fzf') pcall(require('telescope').load_extension, 'ui-select') + pcall(require('telescope').load_extension, 'undo') -- 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', 'v' }, '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' }) + -- 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', 'v' }, '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' }) + vim.keymap.set('n', 'fh', builtin.help_tags, { desc = 'Telescope Help Tags' }) + vim.keymap.set('n', 'fk', builtin.keymaps, { desc = 'Telescope Keymaps' }) + vim.keymap.set('n', 'ff', builtin.find_files, { desc = 'Telescope Find Files' }) + vim.keymap.set('n', 'fg', builtin.live_grep, { desc = 'Telescope Live Grep' }) + vim.keymap.set('n', '', builtin.buffers, { desc = 'Telescope Buffers' }) + + vim.keymap.set('n', 'fu', 'Telescope undo', { desc = 'Telescope Undo' }) + + vim.keymap.set( + 'n', + 'f/', + function() + builtin.live_grep { + grep_open_files = true, + prompt_title = 'Live Grep in Open Files', + } + end, + { desc = 'Telescope Live Grep in Open Files' } + ) + + -- Shortcut for searching your Neovim configuration files + vim.keymap.set('n', 'fn', function() builtin.find_files { cwd = vim.fn.stdpath 'config' } end, { desc = 'Telescope Nvim Files' }) -- Add Telescope-based LSP pickers when an LSP attaches to a buffer. -- If you later switch picker plugins, this is where to update these mappings. @@ -531,16 +553,17 @@ do 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' }) + vim.keymap.set('n', 'grr', builtin.lsp_references, { buffer = buf, desc = 'Goto References' }) + vim.keymap.set('n', 'grn', vim.lsp.buf.rename, { buffer = buf, desc = 'Goto Rename' }) -- 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' }) + vim.keymap.set('n', 'gI', builtin.lsp_implementations, { buffer = buf, desc = 'Goto Implementation' }) -- 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' }) + vim.keymap.set('n', 'gd', builtin.lsp_definitions, { buffer = buf, desc = 'Goto Definition' }) -- Fuzzy find all the symbols in your current document. -- Symbols are things like variables, functions, types, etc. @@ -553,7 +576,7 @@ do -- 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' }) + vim.keymap.set('n', 'grt', builtin.lsp_type_definitions, { buffer = buf, desc = 'Goto Type Definition' }) end, }) @@ -568,20 +591,6 @@ do -- 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', follow = true } end, { desc = '[S]earch [N]eovim files' }) end -- ============================================================ @@ -692,10 +701,10 @@ do -- See `:help lsp-config` for information about keys and how to configure ---@type table local servers = { - -- clangd = {}, + clangd = {}, -- gopls = {}, - -- pyright = {}, - -- rust_analyzer = {}, + pyright = {}, + rust_analyzer = {}, -- -- Some languages (like typescript) have entire language plugins that can be useful: -- https://github.com/pmizio/typescript-tools.nvim @@ -777,15 +786,16 @@ end do -- [[ Formatting ]] vim.pack.add { gh 'stevearc/conform.nvim' } + vim.pack.add { gh 'zapling/mason-conform.nvim' } require('conform').setup { notify_on_error = false, format_on_save = function(bufnr) -- You can specify filetypes to autoformat on save here: - local enabled_filetypes = { + local disabled_filetypes = { -- lua = true, -- python = true, } - if enabled_filetypes[vim.bo[bufnr].filetype] then + if not disabled_filetypes[vim.bo[bufnr].filetype] then return { timeout_ms = 500 } else return nil @@ -794,18 +804,28 @@ do default_format_opts = { lsp_format = 'fallback', -- Use external formatters if configured below, otherwise use LSP formatting. Set to `false` to disable LSP formatting entirely. }, - -- You can also specify external formatters in here. + formatters_by_ft = { - -- rust = { 'rustfmt' }, - -- Conform can also run multiple formatters sequentially - -- python = { "isort", "black" }, - -- - -- You can use 'stop_after_first' to run the first available formatter from the list - -- javascript = { "prettierd", "prettier", stop_after_first = true }, + lua = { 'stylua' }, + python = { 'isort', 'black' }, + rust = { 'rustfmt' }, + nix = { 'nixfmt' }, + c = { 'clang-format' }, + cpp = { 'clang-format' }, + + javascript = { 'prettierd', 'prettier', stop_after_first = true }, + typescript = { 'prettierd', 'prettier', stop_after_first = true }, + html = { 'prettierd', 'prettier', stop_after_first = true }, + css = { 'prettierd', 'prettier', stop_after_first = true }, + json = { 'prettierd', 'prettier', stop_after_first = true }, + yaml = { 'prettierd', 'prettier', stop_after_first = true }, + markdown = { 'prettierd', 'prettier', stop_after_first = true }, }, } - vim.keymap.set({ 'n', 'v' }, 'f', function() require('conform').format { async = true } end, { desc = '[F]ormat buffer' }) + require('mason-conform').setup() + + vim.keymap.set({ 'n', 'v' }, 'p', function() require('conform').format { async = true } end, { desc = 'Pretify' }) end -- ============================================================ @@ -818,7 +838,8 @@ do -- NOTE: You can also specify plugin using a version range for its git tag. -- See `:help vim.version.range()` for more info vim.pack.add { { src = gh 'L3MON4D3/LuaSnip', version = vim.version.range '2.*' } } - require('luasnip').setup {} + local luasnip = require 'luasnip' + luasnip.setup() -- `friendly-snippets` contains a variety of premade snippets. -- See the README about individual language/framework/plugin snippets: @@ -831,6 +852,28 @@ do vim.pack.add { { src = gh 'saghen/blink.cmp', version = vim.version.range '1.*' } } require('blink.cmp').setup { keymap = { + + preset = 'none', + + [''] = { 'scroll_documentation_up', 'fallback' }, + [''] = { 'scroll_documentation_down', 'fallback' }, + + [''] = { 'select_prev', 'fallback' }, + [''] = { 'select_next', 'fallback' }, + [''] = { 'accept' }, + + [''] = { + function() + if luasnip.locally_jumpable(1) then luasnip.jump(1) end + end, + }, + + [''] = { + function() + if luasnip.locally_jumpable(-1) then luasnip.jump(1) end + end, + }, + -- 'default' (recommended) for mappings similar to built-in completions -- to accept ([y]es) the completion. -- This will auto-import if your LSP supports it. @@ -852,7 +895,6 @@ do -- : Toggle signature help -- -- See `:help blink-cmp-config-keymap` for defining your own keymap - preset = 'default', -- For more advanced Luasnip keymaps (e.g. selecting choice nodes, expansion) see: -- https://github.com/L3MON4D3/LuaSnip?tab=readme-ov-file#keymaps @@ -967,16 +1009,16 @@ do -- Uncomment any of the lines below to enable them (you will need to restart nvim). -- -- require 'kickstart.plugins.debug' - -- require 'kickstart.plugins.indent_line' - -- require 'kickstart.plugins.lint' - -- require 'kickstart.plugins.autopairs' - -- require 'kickstart.plugins.neo-tree' + require 'kickstart.plugins.indent_line' + require 'kickstart.plugins.lint' + require 'kickstart.plugins.autopairs' + require 'kickstart.plugins.neo-tree' -- require 'kickstart.plugins.gitsigns' -- adds gitsigns recommended keymaps -- NOTE: You can add your own plugins, configuration, etc from `lua/custom/plugins/*.lua` -- -- Uncomment the following line and add your plugins to `lua/custom/plugins/*.lua` to get going. - -- require 'custom.plugins' + require 'custom.plugins' end -- The line beneath this is called `modeline`. See `:help modeline` diff --git a/lua/custom/plugins/keybinds.lua b/lua/custom/plugins/keybinds.lua new file mode 100644 index 0000000..c694c4b --- /dev/null +++ b/lua/custom/plugins/keybinds.lua @@ -0,0 +1,49 @@ + +-- local function map(mode, lhs, rhs, opts) +-- local options = { noremap = true, silent = true } +-- if opts then +-- if opts.desc then +-- opts.desc = 'keymaps.lua: ' .. opts.desc +-- end +-- options = vim.tbl_extend('force', options, opts) +-- end +-- vim.keymap.set(mode, lhs, rhs, options) +-- end +-- +-- vim.keymap.set('n', '/', 'gcc', { remap = true }) +-- vim.keymap.set('v', '/', 'gc', { remap = true }) +-- + +vim.keymap.set({ 'x', 'n' }, 'd', '"_d', { remap = false, desc = 'Delete without copying' }) + +vim.keymap.set({'x','n'}, '/', 'gcc', { remap = true, desc = 'Toggle comment line' }) + +vim.g.tex_flavor = 'latex' + +local list_snips = function() + local ft_list = require('luasnip').available()[vim.o.filetype] + local ft_snips = {} + for _, item in pairs(ft_list) do + ft_snips[item.trigger] = item.name + end + print(vim.inspect(ft_snips)) +end + +vim.api.nvim_create_user_command('SnipList', list_snips, {}) + +local list_all_snips = function() + local ft_lists = require('luasnip').available() + local ft_snips = {} + for _, ft_list in pairs(ft_lists) do + for _, item in pairs(ft_list) do + ft_snips[item.trigger] = item.name + end + end + print(vim.inspect(ft_snips)) +end + +vim.api.nvim_create_user_command('SnipListAll', list_all_snips, {}) + +vim.keymap.set('n', 'e', function() + require('neo-tree.command').execute({ toggle = true }) +end, { desc = 'Explorer', silent = true }) diff --git a/lua/custom/plugins/neotree.lua b/lua/custom/plugins/neotree.lua new file mode 100644 index 0000000..466e0ac --- /dev/null +++ b/lua/custom/plugins/neotree.lua @@ -0,0 +1,2 @@ + +vim.pack.add { 'https://github.com/nvim-tree/nvim-web-devicons' } diff --git a/lua/custom/plugins/theme.lua b/lua/custom/plugins/theme.lua new file mode 100644 index 0000000..43ce9b6 --- /dev/null +++ b/lua/custom/plugins/theme.lua @@ -0,0 +1,31 @@ +vim.pack.add({ + "https://github.com/ellisonleao/gruvbox.nvim" +}) + +require("gruvbox").setup( +{ + terminal_colors = true, -- add neovim terminal colors + undercurl = true, + underline = true, + bold = true, + italic = { + strings = true, + emphasis = true, + comments = true, + operators = false, + folds = true, + }, + strikethrough = true, + invert_selection = false, + invert_signs = false, + invert_tabline = false, + -- inverse = true, -- invert background for search, diffs, statuslines and errors + -- contrast = "", -- can be "hard", "soft" or empty string + -- palette_overrides = {}, + -- overrides = {}, + dim_inactive = false, + -- transparent_mode = false, + } +) + +vim.cmd.colorscheme("gruvbox")