diff --git a/init.lua b/init.lua index 220d3045..d29fecee 100644 --- a/init.lua +++ b/init.lua @@ -160,9 +160,66 @@ vim.opt.scrolloff = 10 -- [[ Basic Keymaps ]] -- See `:help vim.keymap.set()` --- Clear highlights on search when pressing in normal mode --- See `:help hlsearch` -vim.keymap.set('n', '', 'nohlsearch') +-- MY KEYMAPS BEGIN +vim.api.nvim_exec( + [[ + function! s:ZoomToggle() abort + if exists('t:zoomed') && t:zoomed + execute t:zoom_winrestcmd + let t:zoomed = 0 + else + let t:zoom_winrestcmd = winrestcmd() + resize + vertical resize + let t:zoomed = 1 + endif + endfunction + command! ZoomToggle call s:ZoomToggle() + ]], + false +) + +vim.cmd [[ + set listchars=eol:¬ + " hi NonText guibg=#eee + nnoremap ,h (&hls && v:hlsearch ? ':nohls' : ':set hls')."\n" +]] + +vim.keymap.set('n', ';', ':', { noremap = true, desc = 'Command mode' }) +vim.keymap.set('n', "'", '`', { noremap = true, desc = 'Mark character' }) +vim.keymap.set('n', '`', "'", { noremap = true, desc = 'Mark line' }) +-- vim.keymap.set("n", "œ", "bdelete", { silent = true, desc = "Buffer Delete" }) +vim.keymap.set('n', '', 'ZoomToggle', { noremap = true, desc = 'Zoom Toggle' }) + +vim.keymap.set('i', 'df', '', { noremap = true, desc = 'ESC' }) +vim.keymap.set('n', '', 'o', { noremap = true, desc = 'ESC' }) + +vim.keymap.set('n', 'L', 'bn', { noremap = true, desc = 'buffer next' }) +vim.keymap.set('n', 'H', 'bp', { noremap = true, desc = 'buffer previous' }) + +vim.keymap.set('n', ',n', 'Neotree toggle', { noremap = true, desc = 'Tree Toggle' }) +vim.keymap.set('n', ',N', 'Neotree reveal left', { noremap = true, desc = 'Follow File Toggle' }) + +vim.keymap.set('n', 'w', ':w', { noremap = true, desc = 'Save file' }) + +vim.g.diagnostics_active = false +function _G.toggle_diagnostics() + if vim.g.diagnostics_active then + vim.g.diagnostics_active = false + vim.diagnostic.config { virtual_text = false } + else + vim.g.diagnostics_active = true + vim.diagnostic.config { virtual_text = true } + end +end + +vim.api.nvim_set_keymap('n', 'uv', ':call v:lua.toggle_diagnostics()', { noremap = true, silent = true, desc = 'Toggle diagnostic text' }) + +-- NOTES +-- :g/^$/d delete empty lines +-- :v/\w\+/d (skip lines with one or more words) delete empty lines +-- !column -t column format +-- MY KEYMAPS END -- Diagnostic keymaps vim.keymap.set('n', 'q', vim.diagnostic.setloclist, { desc = 'Open diagnostic [Q]uickfix list' }) @@ -275,7 +332,9 @@ require('lazy').setup({ '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() + require('which-key').setup { triggers = { + { '', mode = { 'n', 'v' } }, + } } -- Document existing key chains require('which-key').add { @@ -343,6 +402,7 @@ require('lazy').setup({ -- [[ Configure Telescope ]] -- See `:help telescope` and `:help telescope.setup()` + local actions = require 'telescope.actions' require('telescope').setup { -- You can put your default mappings / updates / etc. in here -- All the info you're looking for is in `:help telescope.setup()` @@ -353,6 +413,34 @@ require('lazy').setup({ -- }, -- }, -- pickers = {} + require('telescope').setup { + pickers = { + find_files = { + follow = true, + cache_picker = false, + }, + buffers = { + cache_picker = false, + }, + }, + defaults = { + cache_picker = { + num_pickers = 8, + }, + mappings = { + i = { + [''] = actions.close, + }, + }, + layout_strategy = 'horizontal', + layout_config = { + horizontal = { + prompt_position = 'top', + }, + }, + sorting_strategy = 'ascending', + }, + }, extensions = { ['ui-select'] = { require('telescope.themes').get_dropdown(), @@ -373,13 +461,15 @@ require('lazy').setup({ 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', '', builtin.buffers, { desc = '[ ] Find existing buffers' }) + vim.keymap.set('n', '', builtin.find_files, { desc = '[S]earch [F]iles' }) + vim.keymap.set('n', '', builtin.buffers, { desc = '[ ] Find existing buffers' }) + vim.keymap.set('n', '', builtin.resume, { desc = '[S]earch [R]esume' }) -- 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. + -- You can pass additional configuration po Telescope to change the theme, layout, etc. builtin.current_buffer_fuzzy_find(require('telescope.themes').get_dropdown { winblend = 10, previewer = false, @@ -497,7 +587,7 @@ require('lazy').setup({ -- Fuzzy find all the symbols in your current workspace. -- Similar to document symbols, except searches over your entire project. - map('ws', require('telescope.builtin').lsp_dynamic_workspace_symbols, '[W]orkspace [S]ymbols') + map('sW', require('telescope.builtin').lsp_dynamic_workspace_symbols, '[W]orkspace [S]ymbols') -- Rename the variable under your cursor. -- Most Language Servers support renaming across files, etc. @@ -540,6 +630,16 @@ require('lazy').setup({ }) end + -- custom auto format + if client then + client.server_capabilities.documentFormattingProvider = true + vim.api.nvim_create_autocmd('BufWritePre', { + callback = function() + vim.lsp.buf.format() + end, + }) + end + -- The following code creates a keymap to toggle inlay hints in your -- code, if the language server you are using supports them -- @@ -649,7 +749,7 @@ require('lazy').setup({ -- Disable "format_on_save lsp_fallback" for languages that don't -- have a well standardized coding style. You can add additional -- languages here or re-enable it for the disabled ones. - local disable_filetypes = { c = true, cpp = true } + local disable_filetypes = { c = true, cpp = true, javascript = true } return { timeout_ms = 500, lsp_fallback = not disable_filetypes[vim.bo[bufnr].filetype], @@ -661,7 +761,7 @@ require('lazy').setup({ -- 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 }, + -- javascript = { 'prettierd', 'prettier', stop_after_first = true }, }, }, }, @@ -686,12 +786,12 @@ require('lazy').setup({ -- `friendly-snippets` contains a variety of premade snippets. -- See the README about individual language/framework/plugin snippets: -- https://github.com/rafamadriz/friendly-snippets - -- { - -- 'rafamadriz/friendly-snippets', - -- config = function() - -- require('luasnip.loaders.from_vscode').lazy_load() - -- end, - -- }, + { + 'rafamadriz/friendly-snippets', + config = function() + require('luasnip.loaders.from_vscode').lazy_load() + end, + }, }, }, 'saadparwaiz1/cmp_luasnip', @@ -714,7 +814,10 @@ require('lazy').setup({ luasnip.lsp_expand(args.body) end, }, - completion = { completeopt = 'menu,menuone,noinsert' }, + preselect = cmp.PreselectMode.None, + completion = { + completeopt = 'menu,menuone,noinsert,noselect', + }, -- For an understanding of why these mappings were -- chosen, you will need to read `:help ins-completion` @@ -725,6 +828,8 @@ require('lazy').setup({ [''] = cmp.mapping.select_next_item(), -- Select the [p]revious item [''] = cmp.mapping.select_prev_item(), + -- [''] = cmp.mapping.select_next_item { behavior = cmp.SelectBehavior.Select }, + -- [''] = cmp.mapping.select_prev_item { behavior = cmp.SelectBehavior.Select }, -- Scroll the documentation window [b]ack / [f]orward [''] = cmp.mapping.scroll_docs(-4), @@ -733,7 +838,7 @@ require('lazy').setup({ -- Accept ([y]es) the completion. -- This will auto-import if your LSP supports it. -- This will expand snippets if the LSP sent a snippet. - [''] = cmp.mapping.confirm { select = true }, + [''] = cmp.mapping.confirm { select = true }, -- If you prefer more traditional completion keymaps, -- you can uncomment the following lines @@ -782,64 +887,9 @@ require('lazy').setup({ end, }, - { -- You can easily change to a different colorscheme. - -- Change the name of the colorscheme plugin below, and then - -- change the command in the config to whatever the name of that colorscheme is. - -- - -- If you want to see what colorschemes are already installed, you can use `:Telescope colorscheme`. - 'folke/tokyonight.nvim', - priority = 1000, -- Make sure to load this before all the other start plugins. - init = function() - -- 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' - - -- You can configure highlights by doing something like: - vim.cmd.hi 'Comment gui=none' - end, - }, - -- Highlight todo, notes, etc in comments { 'folke/todo-comments.nvim', event = 'VimEnter', dependencies = { 'nvim-lua/plenary.nvim' }, opts = { signs = false } }, - { -- Collection of various small independent plugins/modules - 'echasnovski/mini.nvim', - config = function() - -- Better Around/Inside textobjects - -- - -- Examples: - -- - va) - [V]isually select [A]round [)]paren - -- - yinq - [Y]ank [I]nside [N]ext [Q]uote - -- - ci' - [C]hange [I]nside [']quote - require('mini.ai').setup { n_lines = 500 } - - -- Add/delete/replace surroundings (brackets, quotes, etc.) - -- - -- - saiw) - [S]urround [A]dd [I]nner [W]ord [)]Paren - -- - sd' - [S]urround [D]elete [']quotes - -- - sr)' - [S]urround [R]eplace [)] ['] - require('mini.surround').setup() - - -- Simple and easy statusline. - -- You could remove this setup call if you don't like it, - -- and try some other statusline plugin - local statusline = require 'mini.statusline' - -- set use_icons to true if you have a Nerd Font - statusline.setup { use_icons = vim.g.have_nerd_font } - - -- You can configure sections in the statusline by overriding their - -- 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 - - -- ... and there is more! - -- Check out: https://github.com/echasnovski/mini.nvim - end, - }, { -- Highlight, edit, and navigate code 'nvim-treesitter/nvim-treesitter', build = ':TSUpdate', @@ -892,7 +942,7 @@ require('lazy').setup({ -- -- Uncomment the following line and add your plugins to `lua/custom/plugins/*.lua` to get going. -- For additional information, see `:help lazy.nvim-lazy.nvim-structuring-your-plugins` - -- { import = 'custom.plugins' }, + { import = 'custom.plugins' }, }, { ui = { -- If you are using a Nerd Font: set icons to an empty table which will use the diff --git a/lua/custom/plugins/bufferline.lua b/lua/custom/plugins/bufferline.lua new file mode 100644 index 00000000..266634eb --- /dev/null +++ b/lua/custom/plugins/bufferline.lua @@ -0,0 +1,13 @@ +return { + 'akinsho/bufferline.nvim', + version = '*', + dependencies = 'nvim-tree/nvim-web-devicons', + config = function() + local bufferline = require 'bufferline' + bufferline.setup { + options = { + separator_style = 'slope', + }, + } + end, +} diff --git a/lua/custom/plugins/bufremove.lua b/lua/custom/plugins/bufremove.lua new file mode 100644 index 00000000..8a9555c1 --- /dev/null +++ b/lua/custom/plugins/bufremove.lua @@ -0,0 +1,34 @@ +local function miniDeleteBuffer() + local bd = require('mini.bufremove').delete + if vim.bo.modified then + local choice = vim.fn.confirm(('Save changes to %q?'):format(vim.fn.bufname()), '&Yes\n&No\n&Cancel') + if choice == 1 then -- Yes + vim.cmd.write() + bd(0) + elseif choice == 2 then -- No + bd(0, true) + end + else + bd(0) + end +end + +return { + { + 'echasnovski/mini.bufremove', + keys = { + { + 'bd', + miniDeleteBuffer, + desc = 'Delete Buffer', + }, + { + 'œ', + miniDeleteBuffer, + desc = 'Delete Buffer', + }, + -- stylua: ignore + { "bD", function() require("mini.bufremove").delete(0, true) end, desc = "Delete Buffer (Force)" }, + }, + }, +} diff --git a/lua/custom/plugins/flash.lua b/lua/custom/plugins/flash.lua new file mode 100644 index 00000000..89ea1c4e --- /dev/null +++ b/lua/custom/plugins/flash.lua @@ -0,0 +1,14 @@ +return { + 'folke/flash.nvim', + event = 'VeryLazy', + config = function() + require('flash').setup() + vim.keymap.set('n', 'f', 'lua require("flash").jump()', { noremap = true, desc = 'flash search' }) + vim.keymap.set( + 'n', + 'F', + 'lua require("flash").jump({search = { forward = false, wrap = false, multi_window = false }})', + { noremap = true, desc = 'flash search backwards' } + ) + end, +} diff --git a/lua/custom/plugins/git.lua b/lua/custom/plugins/git.lua new file mode 100644 index 00000000..449b0406 --- /dev/null +++ b/lua/custom/plugins/git.lua @@ -0,0 +1,6 @@ +return { + 'FabijanZulj/blame.nvim', + config = function() + require('blame').setup() + end, +} diff --git a/lua/custom/plugins/init.lua b/lua/custom/plugins/init.lua index be0eb9d8..673c826f 100644 --- a/lua/custom/plugins/init.lua +++ b/lua/custom/plugins/init.lua @@ -2,4 +2,39 @@ -- I promise not to create any merge conflicts in this directory :) -- -- See the kickstart.nvim README for more information -return {} +return { + { + 'christoomey/vim-tmux-navigator', + cmd = { + 'TmuxNavigateLeft', + 'TmuxNavigateDown', + 'TmuxNavigateUp', + 'TmuxNavigateRight', + 'TmuxNavigatePrevious', + }, + keys = { + { '', 'TmuxNavigateLeft' }, + { '', 'TmuxNavigateDown' }, + { '', 'TmuxNavigateUp' }, + { '', 'TmuxNavigateRight' }, + { '', 'TmuxNavigatePrevious' }, + }, + }, + { + 'nxstynate/oneDarkPro.nvim', + priority = 1000, + opts = { + palette_overrides = { + dark0 = '#282c34', + }, + }, + init = function() + vim.cmd.colorscheme 'oneDarkPro' + end, + }, + { 'NvChad/nvim-colorizer.lua', opts = { + user_default_options = { + css = true, + }, + } }, +} diff --git a/lua/custom/plugins/lualine.lua b/lua/custom/plugins/lualine.lua new file mode 100644 index 00000000..de7aeb8d --- /dev/null +++ b/lua/custom/plugins/lualine.lua @@ -0,0 +1,7 @@ +return { + 'nvim-lualine/lualine.nvim', + dependencies = { 'nvim-tree/nvim-web-devicons' }, + config = function() + require('lualine').setup {} + end, +} diff --git a/lua/custom/plugins/nvimtree.lua b/lua/custom/plugins/nvimtree.lua new file mode 100644 index 00000000..f72be33e --- /dev/null +++ b/lua/custom/plugins/nvimtree.lua @@ -0,0 +1,19 @@ +return { + '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 + }, + opts = { + window = { + width = 34, + mappings = { + [''] = 'open_vsplit', + [''] = 'open_split', + }, + }, + }, +} diff --git a/lua/custom/plugins/pairs.lua b/lua/custom/plugins/pairs.lua new file mode 100644 index 00000000..d4d2c617 --- /dev/null +++ b/lua/custom/plugins/pairs.lua @@ -0,0 +1,7 @@ +return { + 'windwp/nvim-autopairs', + event = 'InsertEnter', + config = true, + -- use opts = {} for passing setup options + -- this is equalent to setup({}) function +} diff --git a/lua/custom/plugins/ss.lua b/lua/custom/plugins/ss.lua new file mode 100644 index 00000000..a504be29 --- /dev/null +++ b/lua/custom/plugins/ss.lua @@ -0,0 +1,7 @@ +return { + 'MagicDuck/grug-far.nvim', + config = function() + require('grug-far').setup() + vim.keymap.set('n', 'sr', 'GrugFar', { desc = '[S]earch and [R]eplace' }) + end, +} diff --git a/lua/custom/plugins/surround.lua b/lua/custom/plugins/surround.lua new file mode 100644 index 00000000..1be40e67 --- /dev/null +++ b/lua/custom/plugins/surround.lua @@ -0,0 +1,8 @@ +return { + { + 'kylechui/nvim-surround', + version = '*', -- Use for stability; omit to use `main` branch for the latest features + event = 'VeryLazy', + opts = {}, + }, +}