From debdd50051abf93fe87754924528dadc31f02e0a Mon Sep 17 00:00:00 2001 From: psychhim Date: Tue, 7 Oct 2025 01:49:59 +0530 Subject: [PATCH] Fixed Spaces with Tabs for indents in lua --- .stylua.toml | 4 +- init.lua | 988 +++++++++++++-------------- lazy-lock.json | 82 ++- lua/copy_to_clipboard_fix.lua | 12 +- lua/custom/plugins/filetree.lua | 330 ++++----- lua/custom/plugins/telescope.lua | 456 ++++++------- lua/custom/plugins/undotree.lua | 22 +- lua/keymaps.lua | 390 +++++------ lua/kickstart/plugins/autoformat.lua | 128 ++-- lua/kickstart/plugins/debug.lua | 134 ++-- 10 files changed, 1282 insertions(+), 1264 deletions(-) diff --git a/.stylua.toml b/.stylua.toml index 139e939..59914c9 100644 --- a/.stylua.toml +++ b/.stylua.toml @@ -1,6 +1,6 @@ column_width = 160 line_endings = "Unix" -indent_type = "Spaces" -indent_width = 2 +indent_type = "Tabs" +indent_width = 4 quote_style = "AutoPreferSingle" call_parentheses = "None" diff --git a/init.lua b/init.lua index 6700922..d78439a 100644 --- a/init.lua +++ b/init.lua @@ -6,14 +6,14 @@ vim.g.maplocalleader = ' ' -- `:help lazy.nvim.txt` for more info local lazypath = vim.fn.stdpath 'data' .. '/lazy/lazy.nvim' if not vim.loop.fs_stat(lazypath) then - vim.fn.system { - 'git', - 'clone', - '--filter=blob:none', - 'https://github.com/folke/lazy.nvim.git', - '--branch=stable', -- latest stable release - lazypath, - } + vim.fn.system { + 'git', + 'clone', + '--filter=blob:none', + 'https://github.com/folke/lazy.nvim.git', + '--branch=stable', -- latest stable release + lazypath, + } end vim.opt.rtp:prepend(lazypath) @@ -25,242 +25,242 @@ vim.opt.rtp:prepend(lazypath) -- Disables which-key healthcheck notifications do - local orig_notify = vim.notify - vim.notify = function(msg, ...) - if type(msg) == 'string' and msg:match 'which%-key' then - return -- ignore WhichKey health messages - end - return orig_notify(msg, ...) - end + local orig_notify = vim.notify + vim.notify = function(msg, ...) + if type(msg) == 'string' and msg:match 'which%-key' then + return -- ignore WhichKey health messages + end + return orig_notify(msg, ...) + end end require('lazy').setup({ - -- NOTE: First, some plugins that don't require any configuration - -- Git related plugins - 'tpope/vim-fugitive', - 'tpope/vim-rhubarb', + -- NOTE: First, some plugins that don't require any configuration + -- Git related plugins + 'tpope/vim-fugitive', + 'tpope/vim-rhubarb', - -- NOTE: This is where your plugins related to LSP can be installed. - -- The configuration is done below. Search for lspconfig to find it below. - { - -- LSP Configuration & Plugins - 'neovim/nvim-lspconfig', - dependencies = { - -- Automatically install LSPs to stdpath for neovim - 'williamboman/mason.nvim', - 'williamboman/mason-lspconfig.nvim', + -- NOTE: This is where your plugins related to LSP can be installed. + -- The configuration is done below. Search for lspconfig to find it below. + { + -- LSP Configuration & Plugins + 'neovim/nvim-lspconfig', + dependencies = { + -- Automatically install LSPs to stdpath for neovim + 'williamboman/mason.nvim', + 'williamboman/mason-lspconfig.nvim', - -- Conform - { - 'stevearc/conform.nvim', - opts = { - formatters_by_ft = { - lua = { 'stylua' }, - python = { 'isort', 'yapf' }, - javascript = { - 'prettierd', - }, - typescript = { - 'prettierd', - }, - css = { - 'prettierd', - }, - html = { - 'prettierd', - }, - json = { - 'prettierd', - }, - c = { - 'clang-format', - }, - cpp = { - 'clang-format', - }, - bash = { 'shfmt' }, - rust = { 'rustfmt' }, - }, - format_on_save = { - timeout_ms = 500, - lsp_format = 'fallback', - }, - }, - -- format without saving - vim.keymap.set('n', 'f', function() - require('conform').format { async = true } - end, { desc = 'Format buffer' }), - }, + -- Conform + { + 'stevearc/conform.nvim', + opts = { + formatters_by_ft = { + lua = { 'stylua' }, + python = { 'isort', 'yapf' }, + javascript = { + 'prettierd', + }, + typescript = { + 'prettierd', + }, + css = { + 'prettierd', + }, + html = { + 'prettierd', + }, + json = { + 'prettierd', + }, + c = { + 'clang-format', + }, + cpp = { + 'clang-format', + }, + bash = { 'shfmt' }, + rust = { 'rustfmt' }, + }, + format_on_save = { + timeout_ms = 500, + lsp_format = 'fallback', + }, + }, + -- format without saving + vim.keymap.set('n', 'f', function() + require('conform').format { async = true } + end, { desc = 'Format buffer' }), + }, - -- Install formatters automatically - { - 'zapling/mason-conform.nvim', - dependencies = { 'williamboman/mason.nvim', 'stevearc/conform.nvim' }, - config = function() - require('mason-conform').setup { - ensure_installed = true, -- auto-install all formatters listed in Conform - } - end, - }, - -- Useful status updates for LSP - -- NOTE: `opts = {}` is the same as calling `require('fidget').setup({})` - { 'j-hui/fidget.nvim', opts = {} }, + -- Install formatters automatically + { + 'zapling/mason-conform.nvim', + dependencies = { 'williamboman/mason.nvim', 'stevearc/conform.nvim' }, + config = function() + require('mason-conform').setup { + ensure_installed = true, -- auto-install all formatters listed in Conform + } + end, + }, + -- Useful status updates for LSP + -- NOTE: `opts = {}` is the same as calling `require('fidget').setup({})` + { 'j-hui/fidget.nvim', opts = {} }, - -- Additional lua configuration, makes nvim stuff amazing! - 'folke/neodev.nvim', - }, - }, - { -- Autocompletion - 'hrsh7th/nvim-cmp', - dependencies = { - -- Snippet Engine & its associated nvim-cmp source - 'L3MON4D3/LuaSnip', - dependencies = { 'rafamadriz/friendly-snippets' }, - 'saadparwaiz1/cmp_luasnip', + -- Additional lua configuration, makes nvim stuff amazing! + 'folke/neodev.nvim', + }, + }, + { -- Autocompletion + 'hrsh7th/nvim-cmp', + dependencies = { + -- Snippet Engine & its associated nvim-cmp source + 'L3MON4D3/LuaSnip', + dependencies = { 'rafamadriz/friendly-snippets' }, + 'saadparwaiz1/cmp_luasnip', - -- Adds LSP completion capabilities - 'hrsh7th/cmp-nvim-lsp', - 'hrsh7th/cmp-path', + -- Adds LSP completion capabilities + 'hrsh7th/cmp-nvim-lsp', + 'hrsh7th/cmp-path', - -- Adds a number of user-friendly snippets + -- Adds a number of user-friendly snippets - 'rafamadriz/friendly-snippets', - }, - }, + 'rafamadriz/friendly-snippets', + }, + }, - -- Useful plugin to show you pending keybinds. - { 'folke/which-key.nvim', opts = {} }, - { - -- Adds git related signs to the gutter, as well as utilities for managing changes - 'lewis6991/gitsigns.nvim', - opts = { - -- See `:help gitsigns.txt` - signs = { - add = { text = '+' }, - change = { text = '~' }, - delete = { text = '_' }, - topdelete = { text = '‾' }, - changedelete = { text = '~' }, - }, - on_attach = function(bufnr) - local gs = package.loaded.gitsigns + -- Useful plugin to show you pending keybinds. + { 'folke/which-key.nvim', opts = {} }, + { + -- Adds git related signs to the gutter, as well as utilities for managing changes + 'lewis6991/gitsigns.nvim', + opts = { + -- See `:help gitsigns.txt` + signs = { + add = { text = '+' }, + change = { text = '~' }, + delete = { text = '_' }, + topdelete = { text = '‾' }, + changedelete = { text = '~' }, + }, + on_attach = function(bufnr) + local gs = package.loaded.gitsigns - local function map(mode, l, r, opts) - opts = opts or {} - opts.buffer = bufnr - vim.keymap.set(mode, l, r, opts) - end + local function map(mode, l, r, opts) + opts = opts or {} + opts.buffer = bufnr + vim.keymap.set(mode, l, r, opts) + end - -- Navigation - map({ 'n', 'v' }, ']c', function() - if vim.wo.diff then - return ']c' - end - vim.schedule(function() - gs.next_hunk() - end) - return '' - end, { expr = true, desc = 'Jump to next hunk' }) + -- Navigation + map({ 'n', 'v' }, ']c', function() + if vim.wo.diff then + return ']c' + end + vim.schedule(function() + gs.next_hunk() + end) + return '' + end, { expr = true, desc = 'Jump to next hunk' }) - map({ 'n', 'v' }, '[c', function() - if vim.wo.diff then - return '[c' - end - vim.schedule(function() - gs.prev_hunk() - end) - return '' - end, { expr = true, desc = 'Jump to previous hunk' }) + map({ 'n', 'v' }, '[c', function() + if vim.wo.diff then + return '[c' + end + vim.schedule(function() + gs.prev_hunk() + end) + return '' + end, { expr = true, desc = 'Jump to previous hunk' }) - -- Actions - -- visual mode - map('v', 'hs', function() - gs.stage_hunk { vim.fn.line '.', vim.fn.line 'v' } - end, { desc = 'stage git hunk' }) - map('v', 'hr', function() - gs.reset_hunk { vim.fn.line '.', vim.fn.line 'v' } - end, { desc = 'reset git hunk' }) - -- normal mode - map('n', 'hs', gs.stage_hunk, { desc = 'git stage hunk' }) - map('n', 'hr', gs.reset_hunk, { desc = 'git reset hunk' }) - map('n', 'hS', gs.stage_buffer, { desc = 'git Stage buffer' }) - map('n', 'hu', gs.undo_stage_hunk, { desc = 'undo stage hunk' }) - map('n', 'hR', gs.reset_buffer, { desc = 'git Reset buffer' }) - map('n', 'hp', gs.preview_hunk, { desc = 'preview git hunk' }) - map('n', 'hb', function() - gs.blame_line { full = false } - end, { desc = 'git blame line' }) - map('n', 'hd', gs.diffthis, { desc = 'git diff against index' }) - map('n', 'hD', function() - gs.diffthis '~' - end, { desc = 'git diff against last commit' }) + -- Actions + -- visual mode + map('v', 'hs', function() + gs.stage_hunk { vim.fn.line '.', vim.fn.line 'v' } + end, { desc = 'stage git hunk' }) + map('v', 'hr', function() + gs.reset_hunk { vim.fn.line '.', vim.fn.line 'v' } + end, { desc = 'reset git hunk' }) + -- normal mode + map('n', 'hs', gs.stage_hunk, { desc = 'git stage hunk' }) + map('n', 'hr', gs.reset_hunk, { desc = 'git reset hunk' }) + map('n', 'hS', gs.stage_buffer, { desc = 'git Stage buffer' }) + map('n', 'hu', gs.undo_stage_hunk, { desc = 'undo stage hunk' }) + map('n', 'hR', gs.reset_buffer, { desc = 'git Reset buffer' }) + map('n', 'hp', gs.preview_hunk, { desc = 'preview git hunk' }) + map('n', 'hb', function() + gs.blame_line { full = false } + end, { desc = 'git blame line' }) + map('n', 'hd', gs.diffthis, { desc = 'git diff against index' }) + map('n', 'hD', function() + gs.diffthis '~' + end, { desc = 'git diff against last commit' }) - -- Toggles - map('n', 'tb', gs.toggle_current_line_blame, { desc = 'toggle git blame line' }) - map('n', 'td', gs.toggle_deleted, { desc = 'toggle git show deleted' }) + -- Toggles + map('n', 'tb', gs.toggle_current_line_blame, { desc = 'toggle git blame line' }) + map('n', 'td', gs.toggle_deleted, { desc = 'toggle git show deleted' }) - -- Text object - map({ 'o', 'x' }, 'ih', ':Gitsigns select_hunk', { desc = 'select git hunk' }) - end, - }, - }, - { - --kanagawa colorscheme - 'rebelot/kanagawa.nvim', - lazy = false, - priority = 1000, - opts = {}, - }, - { - -- Set lualine as statusline - 'nvim-lualine/lualine.nvim', - -- See `:help lualine.txt` - opts = { - options = { - icons_enabled = true, - component_separators = '|', - section_separators = '', - }, - }, - }, - { - -- Add indentation guides even on blank lines - 'lukas-reineke/indent-blankline.nvim', - -- Enable `lukas-reineke/indent-blankline.nvim` - -- See `:help ibl` - main = 'ibl', - opts = {}, - }, - -- "gc" to comment visual regions/lines - { 'numToStr/Comment.nvim', opts = {} }, - { - -- Highlight, edit, and navigate code - 'nvim-treesitter/nvim-treesitter', - dependencies = { - 'nvim-treesitter/nvim-treesitter-textobjects', - }, - build = ':TSUpdate', - }, - { --Autopairs - 'windwp/nvim-autopairs', - event = 'InsertEnter', - config = true, - -- use opts = {} for passing setup options - -- this is equalent to setup({}) function - }, - -- NOTE: Next Step on Your Neovim Journey: Add/Configure additional "plugins" for kickstart - -- These are some example plugins that I've included in the kickstart repository. - -- Uncomment any of the lines below to enable them. - require 'kickstart.plugins.autoformat', - --require 'kickstart.plugins.debug' + -- Text object + map({ 'o', 'x' }, 'ih', ':Gitsigns select_hunk', { desc = 'select git hunk' }) + end, + }, + }, + { + --kanagawa colorscheme + 'rebelot/kanagawa.nvim', + lazy = false, + priority = 1000, + opts = {}, + }, + { + -- Set lualine as statusline + 'nvim-lualine/lualine.nvim', + -- See `:help lualine.txt` + opts = { + options = { + icons_enabled = true, + component_separators = '|', + section_separators = '', + }, + }, + }, + { + -- Add indentation guides even on blank lines + 'lukas-reineke/indent-blankline.nvim', + -- Enable `lukas-reineke/indent-blankline.nvim` + -- See `:help ibl` + main = 'ibl', + opts = {}, + }, + -- "gc" to comment visual regions/lines + { 'numToStr/Comment.nvim', opts = {} }, + { + -- Highlight, edit, and navigate code + 'nvim-treesitter/nvim-treesitter', + dependencies = { + 'nvim-treesitter/nvim-treesitter-textobjects', + }, + build = ':TSUpdate', + }, + { --Autopairs + 'windwp/nvim-autopairs', + event = 'InsertEnter', + config = true, + -- use opts = {} for passing setup options + -- this is equalent to setup({}) function + }, + -- NOTE: Next Step on Your Neovim Journey: Add/Configure additional "plugins" for kickstart + -- These are some example plugins that I've included in the kickstart repository. + -- Uncomment any of the lines below to enable them. + require 'kickstart.plugins.autoformat', + --require 'kickstart.plugins.debug' - -- NOTE: The import below can automatically add your own plugins, configuration, etc from `lua/custom/plugins/*.lua` - -- You can use this folder to prevent any conflicts with this init.lua if you're interested in keeping - -- up-to-date with whatever is in the kickstart repo. - -- Uncomment the following line and add your plugins to `lua/custom/plugins/*.lua` to get going. - -- - -- For additional information see: https://github.com/folke/lazy.nvim#-structuring-your-plugins - { import = 'custom.plugins' }, + -- NOTE: The import below can automatically add your own plugins, configuration, etc from `lua/custom/plugins/*.lua` + -- You can use this folder to prevent any conflicts with this init.lua if you're interested in keeping + -- up-to-date with whatever is in the kickstart repo. + -- Uncomment the following line and add your plugins to `lua/custom/plugins/*.lua` to get going. + -- + -- For additional information see: https://github.com/folke/lazy.nvim#-structuring-your-plugins + { import = 'custom.plugins' }, }, {}) -- custom/keymaps.lua file @@ -322,143 +322,143 @@ vim.o.smartindent = true -- auto-indent new lines -- See `:help vim.highlight.on_yank()` local highlight_group = vim.api.nvim_create_augroup('YankHighlight', { clear = true }) vim.api.nvim_create_autocmd('TextYankPost', { - callback = function() - vim.highlight.on_yank() - end, - group = highlight_group, - pattern = '*', + callback = function() + vim.highlight.on_yank() + end, + group = highlight_group, + pattern = '*', }) -- [[ Configure Treesitter ]] -- See `:help nvim-treesitter` -- Defer Treesitter setup after first render to improve startup time of 'nvim {filename}' vim.defer_fn(function() - require('nvim-treesitter.configs').setup { - -- Add languages to be installed here that you want installed for treesitter - ensure_installed = { 'c', 'cpp', 'go', 'lua', 'python', 'rust', 'tsx', 'javascript', 'typescript', 'vimdoc', 'vim', 'bash' }, + require('nvim-treesitter.configs').setup { + -- Add languages to be installed here that you want installed for treesitter + ensure_installed = { 'c', 'cpp', 'go', 'lua', 'python', 'rust', 'tsx', 'javascript', 'typescript', 'vimdoc', 'vim', 'bash' }, - -- Autoinstall languages that are not installed. Defaults to false (but you can change for yourself!) - auto_install = false, + -- Autoinstall languages that are not installed. Defaults to false (but you can change for yourself!) + auto_install = false, - highlight = { enable = true }, - indent = { enable = true }, - incremental_selection = { - enable = true, - keymaps = { - init_selection = '', - node_incremental = '', - scope_incremental = '', - node_decremental = '', - }, - }, - textobjects = { - select = { - enable = true, - lookahead = true, -- Automatically jump forward to textobj, similar to targets.vim - keymaps = { - -- You can use the capture groups defined in textobjects.scm - ['aa'] = '@parameter.outer', - ['ia'] = '@parameter.inner', - ['af'] = '@function.outer', - ['if'] = '@function.inner', - ['ac'] = '@class.outer', - ['ic'] = '@class.inner', - }, - }, - move = { - enable = true, - set_jumps = true, -- whether to set jumps in the jumplist - goto_next_start = { - [']m'] = '@function.outer', - [']]'] = '@class.outer', - }, - goto_next_end = { - [']M'] = '@function.outer', - [']['] = '@class.outer', - }, - goto_previous_start = { - ['[m'] = '@function.outer', - ['[['] = '@class.outer', - }, - goto_previous_end = { - ['[M'] = '@function.outer', - ['[]'] = '@class.outer', - }, - }, - swap = { - enable = true, - swap_next = { - ['a'] = '@parameter.inner', - }, - swap_previous = { - ['A'] = '@parameter.inner', - }, - }, - }, - } + highlight = { enable = true }, + indent = { enable = true }, + incremental_selection = { + enable = true, + keymaps = { + init_selection = '', + node_incremental = '', + scope_incremental = '', + node_decremental = '', + }, + }, + textobjects = { + select = { + enable = true, + lookahead = true, -- Automatically jump forward to textobj, similar to targets.vim + keymaps = { + -- You can use the capture groups defined in textobjects.scm + ['aa'] = '@parameter.outer', + ['ia'] = '@parameter.inner', + ['af'] = '@function.outer', + ['if'] = '@function.inner', + ['ac'] = '@class.outer', + ['ic'] = '@class.inner', + }, + }, + move = { + enable = true, + set_jumps = true, -- whether to set jumps in the jumplist + goto_next_start = { + [']m'] = '@function.outer', + [']]'] = '@class.outer', + }, + goto_next_end = { + [']M'] = '@function.outer', + [']['] = '@class.outer', + }, + goto_previous_start = { + ['[m'] = '@function.outer', + ['[['] = '@class.outer', + }, + goto_previous_end = { + ['[M'] = '@function.outer', + ['[]'] = '@class.outer', + }, + }, + swap = { + enable = true, + swap_next = { + ['a'] = '@parameter.inner', + }, + swap_previous = { + ['A'] = '@parameter.inner', + }, + }, + }, + } end, 0) -- [[ Configure LSP ]] -- This function gets run when an LSP connects to a particular buffer. local on_attach = function(_, bufnr) - -- NOTE: Remember that lua is a real programming language, and as such it is possible - -- to define small helper and utility functions so you don't have to repeat yourself - -- many times. - -- - -- In this case, we create a function that lets us more easily define mappings specific - -- for LSP related items. It sets the mode, buffer and description for us each time. - local nmap = function(keys, func, desc) - if desc then - desc = 'LSP: ' .. desc - end + -- NOTE: Remember that lua is a real programming language, and as such it is possible + -- to define small helper and utility functions so you don't have to repeat yourself + -- many times. + -- + -- In this case, we create a function that lets us more easily define mappings specific + -- for LSP related items. It sets the mode, buffer and description for us each time. + local nmap = function(keys, func, desc) + if desc then + desc = 'LSP: ' .. desc + end - vim.keymap.set('n', keys, func, { buffer = bufnr, desc = desc }) - end + vim.keymap.set('n', keys, func, { buffer = bufnr, desc = desc }) + end - nmap('rn', vim.lsp.buf.rename, '[R]e[n]ame') - nmap('ca', vim.lsp.buf.code_action, '[C]ode [A]ction') + nmap('rn', vim.lsp.buf.rename, '[R]e[n]ame') + nmap('ca', vim.lsp.buf.code_action, '[C]ode [A]ction') - nmap('gd', require('telescope.builtin').lsp_definitions, '[G]oto [D]efinition') - nmap('gr', require('telescope.builtin').lsp_references, '[G]oto [R]eferences') - nmap('gI', require('telescope.builtin').lsp_implementations, '[G]oto [I]mplementation') - nmap('D', require('telescope.builtin').lsp_type_definitions, 'Type [D]efinition') - nmap('ds', require('telescope.builtin').lsp_document_symbols, '[D]ocument [S]ymbols') - nmap('ws', require('telescope.builtin').lsp_dynamic_workspace_symbols, '[W]orkspace [S]ymbols') + nmap('gd', require('telescope.builtin').lsp_definitions, '[G]oto [D]efinition') + nmap('gr', require('telescope.builtin').lsp_references, '[G]oto [R]eferences') + nmap('gI', require('telescope.builtin').lsp_implementations, '[G]oto [I]mplementation') + nmap('D', require('telescope.builtin').lsp_type_definitions, 'Type [D]efinition') + nmap('ds', require('telescope.builtin').lsp_document_symbols, '[D]ocument [S]ymbols') + nmap('ws', require('telescope.builtin').lsp_dynamic_workspace_symbols, '[W]orkspace [S]ymbols') - -- See `:help K` for why this keymap - nmap('K', vim.lsp.buf.hover, 'Hover Documentation') - nmap('', vim.lsp.buf.signature_help, 'Signature Documentation') + -- See `:help K` for why this keymap + nmap('K', vim.lsp.buf.hover, 'Hover Documentation') + nmap('', vim.lsp.buf.signature_help, 'Signature Documentation') - -- Lesser used LSP functionality - nmap('gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration') - nmap('wa', vim.lsp.buf.add_workspace_folder, '[W]orkspace [A]dd Folder') - nmap('wr', vim.lsp.buf.remove_workspace_folder, '[W]orkspace [R]emove Folder') - nmap('wl', function() - print(vim.inspect(vim.lsp.buf.list_workspace_folders())) - end, '[W]orkspace [L]ist Folders') + -- Lesser used LSP functionality + nmap('gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration') + nmap('wa', vim.lsp.buf.add_workspace_folder, '[W]orkspace [A]dd Folder') + nmap('wr', vim.lsp.buf.remove_workspace_folder, '[W]orkspace [R]emove Folder') + nmap('wl', function() + print(vim.inspect(vim.lsp.buf.list_workspace_folders())) + end, '[W]orkspace [L]ist Folders') - -- Create a command `:Format` local to the buffer using Conform - vim.api.nvim_buf_create_user_command(bufnr, 'Format', function() - require('conform').format { bufnr = bufnr } - end, { desc = 'Format current buffer with Conform' }) + -- Create a command `:Format` local to the buffer using Conform + vim.api.nvim_buf_create_user_command(bufnr, 'Format', function() + require('conform').format { bufnr = bufnr } + end, { desc = 'Format current buffer with Conform' }) end -- document existing key chains require('which-key').register { - ['c'] = { name = '[C]ode', _ = 'which_key_ignore' }, - ['d'] = { name = '[D]ocument', _ = 'which_key_ignore' }, - ['g'] = { name = '[G]it', _ = 'which_key_ignore' }, - ['h'] = { name = 'Git [H]unk', _ = 'which_key_ignore' }, - ['r'] = { name = '[R]ename', _ = 'which_key_ignore' }, - ['s'] = { name = '[S]earch', _ = 'which_key_ignore' }, - ['t'] = { name = '[T]oggle', _ = 'which_key_ignore' }, - ['w'] = { name = '[W]orkspace', _ = 'which_key_ignore' }, + ['c'] = { name = '[C]ode', _ = 'which_key_ignore' }, + ['d'] = { name = '[D]ocument', _ = 'which_key_ignore' }, + ['g'] = { name = '[G]it', _ = 'which_key_ignore' }, + ['h'] = { name = 'Git [H]unk', _ = 'which_key_ignore' }, + ['r'] = { name = '[R]ename', _ = 'which_key_ignore' }, + ['s'] = { name = '[S]earch', _ = 'which_key_ignore' }, + ['t'] = { name = '[T]oggle', _ = 'which_key_ignore' }, + ['w'] = { name = '[W]orkspace', _ = 'which_key_ignore' }, } -- register which-key VISUAL mode -- required for visual hs (hunk stage) to work require('which-key').register({ - [''] = { name = 'VISUAL ' }, - ['h'] = { 'Git [H]unk' }, + [''] = { name = 'VISUAL ' }, + ['h'] = { 'Git [H]unk' }, }, { mode = 'v' }) -- mason-lspconfig requires that these setup functions are called in this order @@ -473,21 +473,21 @@ require('mason-lspconfig').setup() -- If you want to override the default filetypes that your language server will attach to you can -- define the property 'filetypes' to the map in question. local servers = { - -- clangd = {}, - -- gopls = {}, - -- pyright = {}, - -- rust_analyzer = {}, - -- tsserver = {}, - -- html = { filetypes = { 'html', 'twig', 'hbs'} }, + -- clangd = {}, + -- gopls = {}, + -- pyright = {}, + -- rust_analyzer = {}, + -- tsserver = {}, + -- html = { filetypes = { 'html', 'twig', 'hbs'} }, - lua_ls = { - Lua = { - workspace = { checkThirdParty = false }, - telemetry = { enable = false }, - -- NOTE: toggle below to ignore Lua_LS's noisy `missing-fields` warnings - -- diagnostics = { disable = { 'missing-fields' } }, - }, - }, + lua_ls = { + Lua = { + workspace = { checkThirdParty = false }, + telemetry = { enable = false }, + -- NOTE: toggle below to ignore Lua_LS's noisy `missing-fields` warnings + -- diagnostics = { disable = { 'missing-fields' } }, + }, + }, } -- Setup neovim lua configuration @@ -501,17 +501,17 @@ capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities) local mason_lspconfig = require 'mason-lspconfig' mason_lspconfig.setup { - ensure_installed = vim.tbl_keys(servers), - handlers = { - function(server_name) - require('lspconfig')[server_name].setup { - capabilities = capabilities, - on_attach = on_attach, - settings = servers[server_name], - filetypes = (servers[server_name] or {}).filetypes, - } - end, - }, + ensure_installed = vim.tbl_keys(servers), + handlers = { + function(server_name) + require('lspconfig')[server_name].setup { + capabilities = capabilities, + on_attach = on_attach, + settings = servers[server_name], + filetypes = (servers[server_name] or {}).filetypes, + } + end, + }, } -- [[ Configure nvim-cmp ]] @@ -523,48 +523,48 @@ local luasnip = require 'luasnip' luasnip.config.setup {} cmp.setup { - snippet = { - expand = function(args) - luasnip.lsp_expand(args.body) - end, - }, - completion = { - completeopt = 'menu,menuone,noinsert', - }, - 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.complete {}, - [''] = cmp.mapping.confirm { - behavior = cmp.ConfirmBehavior.Replace, - select = true, - }, - [''] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_next_item() - elseif luasnip.expand_or_locally_jumpable() then - luasnip.expand_or_jump() - else - fallback() - end - end, { 'i', 's' }), - [''] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_prev_item() - elseif luasnip.locally_jumpable(-1) then - luasnip.jump(-1) - else - fallback() - end - end, { 'i', 's' }), - }, - sources = { - { name = 'nvim_lsp' }, - { name = 'luasnip' }, - { name = 'path' }, - }, + snippet = { + expand = function(args) + luasnip.lsp_expand(args.body) + end, + }, + completion = { + completeopt = 'menu,menuone,noinsert', + }, + 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.complete {}, + [''] = cmp.mapping.confirm { + behavior = cmp.ConfirmBehavior.Replace, + select = true, + }, + [''] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif luasnip.expand_or_locally_jumpable() then + luasnip.expand_or_jump() + else + fallback() + end + end, { 'i', 's' }), + [''] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_prev_item() + elseif luasnip.locally_jumpable(-1) then + luasnip.jump(-1) + else + fallback() + end + end, { 'i', 's' }), + }, + sources = { + { name = 'nvim_lsp' }, + { name = 'luasnip' }, + { name = 'path' }, + }, } --Load Luasnip.loaders require('luasnip.loaders.from_vscode').lazy_load() @@ -579,63 +579,63 @@ _G.tab_offset = 1 local max_visible_tabs = 8 -- maximum number of tabs visible at once function _G.Tabline() - local current_tab = vim.fn.tabpagenr() - local tab_count = vim.fn.tabpagenr '$' - local win_width = vim.o.columns - local tab_width = math.floor(win_width / max_visible_tabs) -- FIXED width + local current_tab = vim.fn.tabpagenr() + local tab_count = vim.fn.tabpagenr '$' + local win_width = vim.o.columns + local tab_width = math.floor(win_width / max_visible_tabs) -- FIXED width - local tabs = {} - for i = 1, tab_count do - local buflist = vim.fn.tabpagebuflist(i) - local winnr = vim.fn.tabpagewinnr(i) - local bufname = vim.fn.bufname(buflist[winnr]) - if bufname == '' then - bufname = '[No Name]' - end - local modified = vim.fn.getbufvar(buflist[winnr], '&mod') == 1 and ' ●' or '' - local label = i .. ': ' .. vim.fn.fnamemodify(bufname, ':t') .. modified + local tabs = {} + for i = 1, tab_count do + local buflist = vim.fn.tabpagebuflist(i) + local winnr = vim.fn.tabpagewinnr(i) + local bufname = vim.fn.bufname(buflist[winnr]) + if bufname == '' then + bufname = '[No Name]' + end + local modified = vim.fn.getbufvar(buflist[winnr], '&mod') == 1 and ' ●' or '' + local label = i .. ': ' .. vim.fn.fnamemodify(bufname, ':t') .. modified - -- truncate/pad to fixed tab_width - if #label > tab_width - 2 then - label = label:sub(1, tab_width - 3) .. '…' - end - label = label .. string.rep(' ', tab_width - #label) + -- truncate/pad to fixed tab_width + if #label > tab_width - 2 then + label = label:sub(1, tab_width - 3) .. '…' + end + label = label .. string.rep(' ', tab_width - #label) - tabs[i] = (i == current_tab and '%#TabLineSel#' or '%#TabLine#') .. label - end + tabs[i] = (i == current_tab and '%#TabLineSel#' or '%#TabLine#') .. label + end - -- scrolling logic to keep active tab visible - local start_index = _G.tab_offset - if current_tab < start_index then - start_index = current_tab - elseif current_tab >= start_index + max_visible_tabs then - start_index = current_tab - max_visible_tabs + 1 - end - _G.tab_offset = start_index + -- scrolling logic to keep active tab visible + local start_index = _G.tab_offset + if current_tab < start_index then + start_index = current_tab + elseif current_tab >= start_index + max_visible_tabs then + start_index = current_tab - max_visible_tabs + 1 + end + _G.tab_offset = start_index - -- select visible tabs - local visible_tabs = {} - for i = start_index, math.min(start_index + max_visible_tabs - 1, tab_count) do - table.insert(visible_tabs, tabs[i]) - end + -- select visible tabs + local visible_tabs = {} + for i = start_index, math.min(start_index + max_visible_tabs - 1, tab_count) do + table.insert(visible_tabs, tabs[i]) + end - -- scrolling arrows - local left_arrow = start_index > 1 and '< ' or ' ' - local right_arrow = start_index + max_visible_tabs - 1 < tab_count and ' >' or ' ' + -- scrolling arrows + local left_arrow = start_index > 1 and '< ' or ' ' + local right_arrow = start_index + max_visible_tabs - 1 < tab_count and ' >' or ' ' - return '%#TabLine#' .. left_arrow .. table.concat(visible_tabs, '') .. right_arrow .. '%#TabLineFill#' + return '%#TabLine#' .. left_arrow .. table.concat(visible_tabs, '') .. right_arrow .. '%#TabLineFill#' end vim.o.tabline = '%!v:lua.Tabline()' -- adjust offset if tabs are closed vim.api.nvim_create_autocmd({ 'TabClosed' }, { - callback = function() - local tab_count = vim.fn.tabpagenr '$' - if _G.tab_offset > tab_count then - _G.tab_offset = math.max(tab_count - max_visible_tabs + 1, 1) - end - end, + callback = function() + local tab_count = vim.fn.tabpagenr '$' + if _G.tab_offset > tab_count then + _G.tab_offset = math.max(tab_count - max_visible_tabs + 1, 1) + end + end, }) -- Auto-create config files for formatters (cross-platform) @@ -646,20 +646,20 @@ local appdata = os.getenv 'APPDATA' or (home .. '/AppData/Roaming') -- List of formatter configs local formatters = { - { - name = 'clang-format', - path = (os_name:match 'Windows' and home .. '\\.clang-format' or home .. '/.clang-format'), - content = [[ + { + name = 'clang-format', + path = (os_name:match 'Windows' and home .. '\\.clang-format' or home .. '/.clang-format'), + content = [[ BasedOnStyle: LLVM IndentWidth: 4 TabWidth: 4 UseTab: Always ]], - }, - { - name = 'prettier', - path = (os_name:match 'Windows' and appdata .. '\\Prettier\\.prettierrc' or home .. '/.prettierrc'), - content = [[ + }, + { + name = 'prettier', + path = (os_name:match 'Windows' and appdata .. '\\Prettier\\.prettierrc' or home .. '/.prettierrc'), + content = [[ { "tabWidth": 4, "useTabs": true, @@ -669,69 +669,69 @@ UseTab: Always "printWidth": 100 } ]], - }, - { - name = 'yapf', - path = (os_name:match 'Windows' and home .. '\\.style.yapf' or home .. '/.style.yapf'), - content = [[ + }, + { + name = 'yapf', + path = (os_name:match 'Windows' and home .. '\\.style.yapf' or home .. '/.style.yapf'), + content = [[ [style] based_on_style = pep8 indent_width = 4 use_tabs = True ]], - }, - { - name = 'isort', - path = (os_name:match 'Windows' and home .. '\\.isort.cfg' or home .. '/.isort.cfg'), - content = [[ + }, + { + name = 'isort', + path = (os_name:match 'Windows' and home .. '\\.isort.cfg' or home .. '/.isort.cfg'), + content = [[ [settings] profile = black force_single_line = true ]], - }, + }, } -- Helper to create file if it doesn't exist local function ensure_file(path, content) - if not path then - print 'Invalid path, skipping file creation' - return - end + if not path then + print 'Invalid path, skipping file creation' + return + end - local stat = uv.fs_stat(path) - if not stat then - -- Make parent directory if needed - local dir = vim.fn.fnamemodify(path, ':h') - if vim.fn.isdirectory(dir) == 0 then - vim.fn.mkdir(dir, 'p') -- recursively create directories - print('Created directory: ' .. dir) - end + local stat = uv.fs_stat(path) + if not stat then + -- Make parent directory if needed + local dir = vim.fn.fnamemodify(path, ':h') + if vim.fn.isdirectory(dir) == 0 then + vim.fn.mkdir(dir, 'p') -- recursively create directories + print('Created directory: ' .. dir) + end - -- Write the file - local fd = uv.fs_open(path, 'w', 420) -- 0644 - if fd then - uv.fs_write(fd, content, -1) - uv.fs_close(fd) - print('Created file: ' .. path) - else - print('Failed to create file: ' .. path) - end - end + -- Write the file + local fd = uv.fs_open(path, 'w', 420) -- 0644 + if fd then + uv.fs_write(fd, content, -1) + uv.fs_close(fd) + print('Created file: ' .. path) + else + print('Failed to create file: ' .. path) + end + end end -- Loop through all formatter configs for _, fmt in ipairs(formatters) do - ensure_file(fmt.path, fmt.content) + ensure_file(fmt.path, fmt.content) end -- Auto-clear messages on most user actions local clear_msg_grp = vim.api.nvim_create_augroup('AutoClearMessages', { clear = true }) vim.api.nvim_create_autocmd({ 'CursorMoved', 'CursorMovedI', 'InsertEnter', 'InsertLeave', 'TextChanged', 'TextChangedI' }, { - group = clear_msg_grp, - callback = function() - vim.cmd 'echo ""' -- Clear the message/command line - end, + group = clear_msg_grp, + callback = function() + vim.cmd 'echo ""' -- Clear the message/command line + end, }) -- Auto-clear messages on pressing ESC diff --git a/lazy-lock.json b/lazy-lock.json index b933b79..3b6d48e 100644 --- a/lazy-lock.json +++ b/lazy-lock.json @@ -1,34 +1,52 @@ { - "Comment.nvim": { "branch": "master", "commit": "e30b7f2008e52442154b66f7c519bfd2f1e32acb" }, - "LuaSnip": { "branch": "master", "commit": "73813308abc2eaeff2bc0d3f2f79270c491be9d7" }, - "cmp-nvim-lsp": { "branch": "main", "commit": "bd5a7d6db125d4654b50eeae9f5217f24bb22fd3" }, - "cmp-path": { "branch": "main", "commit": "c642487086dbd9a93160e1679a1327be111cbc25" }, - "cmp_luasnip": { "branch": "master", "commit": "98d9cb5c2c38532bd9bdb481067b20fea8f32e90" }, - "conform.nvim": { "branch": "master", "commit": "9d859cbfbde7a1bd1770e7c97aef30ec5a237a71" }, - "fidget.nvim": { "branch": "main", "commit": "3f5475949679953af6d78654db29b944fa826e6a" }, - "friendly-snippets": { "branch": "main", "commit": "572f5660cf05f8cd8834e096d7b4c921ba18e175" }, - "gitsigns.nvim": { "branch": "main", "commit": "1ee5c1fd068c81f9dd06483e639c2aa4587dc197" }, - "indent-blankline.nvim": { "branch": "master", "commit": "005b56001b2cb30bfa61b7986bc50657816ba4ba" }, - "kanagawa.nvim": { "branch": "master", "commit": "27f1e119f3a7e6d11d435a59e3262e6affda1f83" }, - "lazy.nvim": { "branch": "main", "commit": "6c3bda4aca61a13a9c63f1c1d1b16b9d3be90d7a" }, - "lualine.nvim": { "branch": "master", "commit": "b8c23159c0161f4b89196f74ee3a6d02cdc3a955" }, - "mason-conform.nvim": { "branch": "main", "commit": "48da2ebd5efbaf8a99566eadc3ece82d523f03c5" }, - "mason-lspconfig.nvim": { "branch": "main", "commit": "155eac5d8609a2f110041f8ac3491664cc126354" }, - "mason.nvim": { "branch": "main", "commit": "ad7146aa61dcaeb54fa900144d768f040090bff0" }, - "neo-tree.nvim": { "branch": "main", "commit": "9130e58424ad95bf2dd8b40afbb8cf04d648638c" }, - "neodev.nvim": { "branch": "main", "commit": "46aa467dca16cf3dfe27098042402066d2ae242d" }, - "nui.nvim": { "branch": "main", "commit": "de740991c12411b663994b2860f1a4fd0937c130" }, - "nvim-autopairs": { "branch": "master", "commit": "23320e75953ac82e559c610bec5a90d9c6dfa743" }, - "nvim-cmp": { "branch": "main", "commit": "b5311ab3ed9c846b585c0c15b7559be131ec4be9" }, - "nvim-lspconfig": { "branch": "master", "commit": "e688b486fe9291f151eae7e5c0b5a5c4ef980847" }, - "nvim-treesitter": { "branch": "master", "commit": "42fc28ba918343ebfd5565147a42a26580579482" }, - "nvim-treesitter-textobjects": { "branch": "master", "commit": "71385f191ec06ffc60e80e6b0c9a9d5daed4824c" }, - "nvim-web-devicons": { "branch": "master", "commit": "f6b0920f452bfd7595ee9a9efe5e1ae78e0e2997" }, - "plenary.nvim": { "branch": "master", "commit": "b9fd5226c2f76c951fc8ed5923d85e4de065e509" }, - "telescope-fzf-native.nvim": { "branch": "main", "commit": "1f08ed60cafc8f6168b72b80be2b2ea149813e55" }, - "telescope.nvim": { "branch": "0.1.x", "commit": "a0bbec21143c7bc5f8bb02e0005fa0b982edc026" }, - "undotree": { "branch": "master", "commit": "0f1c9816975b5d7f87d5003a19c53c6fd2ff6f7f" }, - "vim-fugitive": { "branch": "master", "commit": "61b51c09b7c9ce04e821f6cf76ea4f6f903e3cf4" }, - "vim-rhubarb": { "branch": "master", "commit": "5496d7c94581c4c9ad7430357449bb57fc59f501" }, - "which-key.nvim": { "branch": "main", "commit": "904308e6885bbb7b60714c80ab3daf0c071c1492" } + "Comment.nvim": { "branch": "master", "commit": "e30b7f2008e52442154b66f7c519bfd2f1e32acb" }, + "LuaSnip": { "branch": "master", "commit": "73813308abc2eaeff2bc0d3f2f79270c491be9d7" }, + "cmp-nvim-lsp": { "branch": "main", "commit": "bd5a7d6db125d4654b50eeae9f5217f24bb22fd3" }, + "cmp-path": { "branch": "main", "commit": "c642487086dbd9a93160e1679a1327be111cbc25" }, + "cmp_luasnip": { "branch": "master", "commit": "98d9cb5c2c38532bd9bdb481067b20fea8f32e90" }, + "conform.nvim": { "branch": "master", "commit": "9d859cbfbde7a1bd1770e7c97aef30ec5a237a71" }, + "fidget.nvim": { "branch": "main", "commit": "3f5475949679953af6d78654db29b944fa826e6a" }, + "friendly-snippets": { "branch": "main", "commit": "572f5660cf05f8cd8834e096d7b4c921ba18e175" }, + "gitsigns.nvim": { "branch": "main", "commit": "1ee5c1fd068c81f9dd06483e639c2aa4587dc197" }, + "indent-blankline.nvim": { + "branch": "master", + "commit": "005b56001b2cb30bfa61b7986bc50657816ba4ba" + }, + "kanagawa.nvim": { "branch": "master", "commit": "27f1e119f3a7e6d11d435a59e3262e6affda1f83" }, + "lazy.nvim": { "branch": "main", "commit": "59334064f8604ca073791c25dcc5c9698865406e" }, + "lualine.nvim": { "branch": "master", "commit": "b8c23159c0161f4b89196f74ee3a6d02cdc3a955" }, + "mason-conform.nvim": { + "branch": "main", + "commit": "48da2ebd5efbaf8a99566eadc3ece82d523f03c5" + }, + "mason-lspconfig.nvim": { + "branch": "main", + "commit": "6bdb14f230de0904229ec367b410fb817e59b072" + }, + "mason.nvim": { "branch": "main", "commit": "ad7146aa61dcaeb54fa900144d768f040090bff0" }, + "neo-tree.nvim": { "branch": "main", "commit": "9130e58424ad95bf2dd8b40afbb8cf04d648638c" }, + "neodev.nvim": { "branch": "main", "commit": "46aa467dca16cf3dfe27098042402066d2ae242d" }, + "nui.nvim": { "branch": "main", "commit": "de740991c12411b663994b2860f1a4fd0937c130" }, + "nvim-autopairs": { "branch": "master", "commit": "23320e75953ac82e559c610bec5a90d9c6dfa743" }, + "nvim-cmp": { "branch": "main", "commit": "b5311ab3ed9c846b585c0c15b7559be131ec4be9" }, + "nvim-lspconfig": { "branch": "master", "commit": "e688b486fe9291f151eae7e5c0b5a5c4ef980847" }, + "nvim-treesitter": { "branch": "master", "commit": "42fc28ba918343ebfd5565147a42a26580579482" }, + "nvim-treesitter-textobjects": { + "branch": "master", + "commit": "71385f191ec06ffc60e80e6b0c9a9d5daed4824c" + }, + "nvim-web-devicons": { + "branch": "master", + "commit": "b8221e42cf7287c4dcde81f232f58d7b947c210d" + }, + "plenary.nvim": { "branch": "master", "commit": "b9fd5226c2f76c951fc8ed5923d85e4de065e509" }, + "telescope-fzf-native.nvim": { + "branch": "main", + "commit": "1f08ed60cafc8f6168b72b80be2b2ea149813e55" + }, + "telescope.nvim": { "branch": "0.1.x", "commit": "a0bbec21143c7bc5f8bb02e0005fa0b982edc026" }, + "undotree": { "branch": "master", "commit": "0f1c9816975b5d7f87d5003a19c53c6fd2ff6f7f" }, + "vim-fugitive": { "branch": "master", "commit": "61b51c09b7c9ce04e821f6cf76ea4f6f903e3cf4" }, + "vim-rhubarb": { "branch": "master", "commit": "5496d7c94581c4c9ad7430357449bb57fc59f501" }, + "which-key.nvim": { "branch": "main", "commit": "904308e6885bbb7b60714c80ab3daf0c071c1492" } } diff --git a/lua/copy_to_clipboard_fix.lua b/lua/copy_to_clipboard_fix.lua index 64d4b53..4bcfa87 100644 --- a/lua/copy_to_clipboard_fix.lua +++ b/lua/copy_to_clipboard_fix.lua @@ -1,10 +1,10 @@ local M = {} function M.trim_clipboard() - local content = vim.fn.getreg '+' - -- Remove single trailing newline if present - content = content:gsub('\n$', '') - vim.fn.setreg('+', content) - vim.fn.setreg('*', content) - vim.notify('Copied selection to clipboard', vim.log.levels.INFO) + local content = vim.fn.getreg '+' + -- Remove single trailing newline if present + content = content:gsub('\n$', '') + vim.fn.setreg('+', content) + vim.fn.setreg('*', content) + vim.notify('Copied selection to clipboard', vim.log.levels.INFO) end return M diff --git a/lua/custom/plugins/filetree.lua b/lua/custom/plugins/filetree.lua index f9cb5d5..3bcff3c 100644 --- a/lua/custom/plugins/filetree.lua +++ b/lua/custom/plugins/filetree.lua @@ -2,181 +2,181 @@ vim.cmd [[ let g:neo_tree_remove_legacy_commands = 1 ]] return { - 'nvim-neo-tree/neo-tree.nvim', - version = '*', - dependencies = { - 'nvim-lua/plenary.nvim', - 'nvim-tree/nvim-web-devicons', - 'MunifTanjim/nui.nvim', - }, - config = function() - local function smart_open(state) - local node = state.tree:get_node() - if not node then - return - end - local path = node:get_id() + 'nvim-neo-tree/neo-tree.nvim', + version = '*', + dependencies = { + 'nvim-lua/plenary.nvim', + 'nvim-tree/nvim-web-devicons', + 'MunifTanjim/nui.nvim', + }, + config = function() + local function smart_open(state) + local node = state.tree:get_node() + if not node then + return + end + local path = node:get_id() - -- If the node is a directory, just toggle expand/collapse - if node.type == 'directory' then - state.commands.toggle_node(state, node) - return - end + -- If the node is a directory, just toggle expand/collapse + if node.type == 'directory' then + state.commands.toggle_node(state, node) + return + end - -- --- File handling starts here --- - -- Reuse already open buffer in any tab safely - for _, tab in ipairs(vim.api.nvim_list_tabpages()) do - if vim.api.nvim_tabpage_is_valid(tab) then - for _, win in ipairs(vim.api.nvim_tabpage_list_wins(tab)) do - if vim.api.nvim_win_is_valid(win) then - local buf = vim.api.nvim_win_get_buf(win) - if vim.api.nvim_buf_is_valid(buf) and vim.api.nvim_buf_get_name(buf) == path then - vim.api.nvim_set_current_tabpage(tab) - vim.api.nvim_set_current_win(win) - -- close Neo-tree if open - for _, w in ipairs(vim.api.nvim_list_wins()) do - if vim.api.nvim_win_is_valid(w) then - local b = vim.api.nvim_win_get_buf(w) - if vim.api.nvim_buf_is_valid(b) and vim.api.nvim_buf_get_option(b, 'filetype') == 'neo-tree' then - vim.api.nvim_win_close(w, true) - end - end - end - return - end - end - end - end - end + -- --- File handling starts here --- + -- Reuse already open buffer in any tab safely + for _, tab in ipairs(vim.api.nvim_list_tabpages()) do + if vim.api.nvim_tabpage_is_valid(tab) then + for _, win in ipairs(vim.api.nvim_tabpage_list_wins(tab)) do + if vim.api.nvim_win_is_valid(win) then + local buf = vim.api.nvim_win_get_buf(win) + if vim.api.nvim_buf_is_valid(buf) and vim.api.nvim_buf_get_name(buf) == path then + vim.api.nvim_set_current_tabpage(tab) + vim.api.nvim_set_current_win(win) + -- close Neo-tree if open + for _, w in ipairs(vim.api.nvim_list_wins()) do + if vim.api.nvim_win_is_valid(w) then + local b = vim.api.nvim_win_get_buf(w) + if vim.api.nvim_buf_is_valid(b) and vim.api.nvim_buf_get_option(b, 'filetype') == 'neo-tree' then + vim.api.nvim_win_close(w, true) + end + end + end + return + end + end + end + end + end - -- Reuse empty buffer in current tab - local wins = vim.api.nvim_tabpage_list_wins(0) - local empty_buf = nil - for _, win in ipairs(wins) do - if vim.api.nvim_win_is_valid(win) then - local buf = vim.api.nvim_win_get_buf(win) - if vim.api.nvim_buf_is_valid(buf) then - local bufname = vim.api.nvim_buf_get_name(buf) - local buftype = vim.api.nvim_buf_get_option(buf, 'buftype') - local modified = vim.api.nvim_buf_get_option(buf, 'modified') - if bufname == '' and buftype == '' and not modified then - empty_buf = buf - vim.api.nvim_set_current_win(win) - break - end - end - end - end + -- Reuse empty buffer in current tab + local wins = vim.api.nvim_tabpage_list_wins(0) + local empty_buf = nil + for _, win in ipairs(wins) do + if vim.api.nvim_win_is_valid(win) then + local buf = vim.api.nvim_win_get_buf(win) + if vim.api.nvim_buf_is_valid(buf) then + local bufname = vim.api.nvim_buf_get_name(buf) + local buftype = vim.api.nvim_buf_get_option(buf, 'buftype') + local modified = vim.api.nvim_buf_get_option(buf, 'modified') + if bufname == '' and buftype == '' and not modified then + empty_buf = buf + vim.api.nvim_set_current_win(win) + break + end + end + end + end - if empty_buf then - vim.cmd('edit ' .. vim.fn.fnameescape(path)) - else - vim.cmd('tabnew ' .. vim.fn.fnameescape(path)) - end + if empty_buf then + vim.cmd('edit ' .. vim.fn.fnameescape(path)) + else + vim.cmd('tabnew ' .. vim.fn.fnameescape(path)) + end - -- Always close Neo-tree window if open - for _, win in ipairs(vim.api.nvim_list_wins()) do - if vim.api.nvim_win_is_valid(win) then - local buf = vim.api.nvim_win_get_buf(win) - if vim.api.nvim_buf_is_valid(buf) and vim.api.nvim_buf_get_option(buf, 'filetype') == 'neo-tree' then - vim.api.nvim_win_close(win, true) - end - end - end - end + -- Always close Neo-tree window if open + for _, win in ipairs(vim.api.nvim_list_wins()) do + if vim.api.nvim_win_is_valid(win) then + local buf = vim.api.nvim_win_get_buf(win) + if vim.api.nvim_buf_is_valid(buf) and vim.api.nvim_buf_get_option(buf, 'filetype') == 'neo-tree' then + vim.api.nvim_win_close(win, true) + end + end + end + end - -- Smart_open_split for split windows - local function smart_open_split(state, direction) - local node = state.tree:get_node() - if not node then - return - end - local path = node:get_id() + -- Smart_open_split for split windows + local function smart_open_split(state, direction) + local node = state.tree:get_node() + if not node then + return + end + local path = node:get_id() - if node.type == 'directory' then - state.commands.toggle_node(state, node) - return - end + if node.type == 'directory' then + state.commands.toggle_node(state, node) + return + end - -- Check if file is open in another tab - local open_tab, open_win - for _, tab in ipairs(vim.api.nvim_list_tabpages()) do - for _, win in ipairs(vim.api.nvim_tabpage_list_wins(tab)) do - local buf = vim.api.nvim_win_get_buf(win) - if vim.api.nvim_buf_is_valid(buf) and vim.api.nvim_buf_get_name(buf) == path then - open_tab = tab - open_win = win - break - end - end - if open_tab then - break - end - end + -- Check if file is open in another tab + local open_tab, open_win + for _, tab in ipairs(vim.api.nvim_list_tabpages()) do + for _, win in ipairs(vim.api.nvim_tabpage_list_wins(tab)) do + local buf = vim.api.nvim_win_get_buf(win) + if vim.api.nvim_buf_is_valid(buf) and vim.api.nvim_buf_get_name(buf) == path then + open_tab = tab + open_win = win + break + end + end + if open_tab then + break + end + end - if open_tab then - local choice = vim.fn.confirm('File is already open in a tab. Open split here anyway?', '&Yes\n&No', 2) - if choice ~= 1 then - -- User chose No → jump to the tab where file is open - vim.api.nvim_set_current_tabpage(open_tab) - vim.api.nvim_set_current_win(open_win) - return - end - -- Else user chose Yes → continue to open split in current tab - end + if open_tab then + local choice = vim.fn.confirm('File is already open in a tab. Open split here anyway?', '&Yes\n&No', 2) + if choice ~= 1 then + -- User chose No → jump to the tab where file is open + vim.api.nvim_set_current_tabpage(open_tab) + vim.api.nvim_set_current_win(open_win) + return + end + -- Else user chose Yes → continue to open split in current tab + end - -- Open split in current tab - if direction == 'v' then - state.commands.open_vsplit(state) - vim.schedule(function() - vim.cmd 'wincmd L' - end) - else - state.commands.open_split(state) - vim.schedule(function() - vim.cmd 'wincmd J' - end) - end + -- Open split in current tab + if direction == 'v' then + state.commands.open_vsplit(state) + vim.schedule(function() + vim.cmd 'wincmd L' + end) + else + state.commands.open_split(state) + vim.schedule(function() + vim.cmd 'wincmd J' + end) + end - vim.cmd('edit ' .. vim.fn.fnameescape(path)) - end + vim.cmd('edit ' .. vim.fn.fnameescape(path)) + end - require('neo-tree').setup { - close_if_last_window = true, - popup_border_style = 'rounded', - enable_git_status = true, - enable_diagnostics = true, - default_component_configs = { - indent = { padding = 1, indent_size = 2 }, - icon = { folder_closed = '', folder_open = '', folder_empty = 'ﰊ' }, - }, - window = { - position = 'float', - width = 40, - mapping_options = { noremap = true, nowait = true }, - mappings = { - [''] = smart_open, - ['v'] = function(state) - smart_open_split(state, 'h') - end, - ['h'] = function(state) - smart_open_split(state, 'v') - end, - ['t'] = 'noop', - }, - }, - filesystem = { - follow_current_file = { - enabled = true, -- updated to table format - }, - use_libuv_file_watcher = true, - hijack_netrw_behavior = 'open_default', - filtered_items = { - visible = true, - hide_dotfiles = false, - hide_gitignored = true, - }, - }, - } - end, + require('neo-tree').setup { + close_if_last_window = true, + popup_border_style = 'rounded', + enable_git_status = true, + enable_diagnostics = true, + default_component_configs = { + indent = { padding = 1, indent_size = 2 }, + icon = { folder_closed = '', folder_open = '', folder_empty = 'ﰊ' }, + }, + window = { + position = 'float', + width = 40, + mapping_options = { noremap = true, nowait = true }, + mappings = { + [''] = smart_open, + ['v'] = function(state) + smart_open_split(state, 'h') + end, + ['h'] = function(state) + smart_open_split(state, 'v') + end, + ['t'] = 'noop', + }, + }, + filesystem = { + follow_current_file = { + enabled = true, -- updated to table format + }, + use_libuv_file_watcher = true, + hijack_netrw_behavior = 'open_default', + filtered_items = { + visible = true, + hide_dotfiles = false, + hide_gitignored = true, + }, + }, + } + end, } diff --git a/lua/custom/plugins/telescope.lua b/lua/custom/plugins/telescope.lua index 8267d4c..18f7746 100644 --- a/lua/custom/plugins/telescope.lua +++ b/lua/custom/plugins/telescope.lua @@ -1,255 +1,255 @@ return { - -- Fuzzy Finder (files, lsp, etc) - 'nvim-telescope/telescope.nvim', - branch = '0.1.x', - dependencies = { - 'nvim-lua/plenary.nvim', - -- Fuzzy Finder Algorithm which requires local dependencies to be built. - -- Only load if `make` is available. Make sure you have the system - -- requirements installed. - { - 'nvim-telescope/telescope-fzf-native.nvim', - -- NOTE: If you are having trouble with this installation, - -- refer to the README for telescope-fzf-native for more instructions. - build = 'make', - cond = function() - return vim.fn.executable 'make' == 1 - end, - }, - }, - config = function() - -- [[ Configure Telescope ]] - -- See `:help telescope` and `:help telescope.setup()` - require('telescope').setup { - defaults = { - mappings = { - i = { - [''] = false, - [''] = false, - }, - }, - }, - } + -- Fuzzy Finder (files, lsp, etc) + 'nvim-telescope/telescope.nvim', + branch = '0.1.x', + dependencies = { + 'nvim-lua/plenary.nvim', + -- Fuzzy Finder Algorithm which requires local dependencies to be built. + -- Only load if `make` is available. Make sure you have the system + -- requirements installed. + { + 'nvim-telescope/telescope-fzf-native.nvim', + -- NOTE: If you are having trouble with this installation, + -- refer to the README for telescope-fzf-native for more instructions. + build = 'make', + cond = function() + return vim.fn.executable 'make' == 1 + end, + }, + }, + config = function() + -- [[ Configure Telescope ]] + -- See `:help telescope` and `:help telescope.setup()` + require('telescope').setup { + defaults = { + mappings = { + i = { + [''] = false, + [''] = false, + }, + }, + }, + } - -- Enable telescope fzf native, if installed - pcall(require('telescope').load_extension, 'fzf') + -- Enable telescope fzf native, if installed + pcall(require('telescope').load_extension, 'fzf') - -- smart_open function for Telescope to check if the current tab has an empty "No Name" buffer. If it has, it replaces the empty buffer and open a file in the same tab - local actions = require 'telescope.actions' - local action_state = require 'telescope.actions.state' + -- smart_open function for Telescope to check if the current tab has an empty "No Name" buffer. If it has, it replaces the empty buffer and open a file in the same tab + local actions = require 'telescope.actions' + local action_state = require 'telescope.actions.state' - local function smart_open(prompt_bufnr) - local entry = action_state.get_selected_entry() - if not entry then - return - end + local function smart_open(prompt_bufnr) + local entry = action_state.get_selected_entry() + if not entry then + return + end - local path = entry.path or entry.filename - if not path then - return - end + local path = entry.path or entry.filename + if not path then + return + end - if prompt_bufnr and vim.api.nvim_buf_is_valid(prompt_bufnr) then - pcall(actions.close, prompt_bufnr) - end + if prompt_bufnr and vim.api.nvim_buf_is_valid(prompt_bufnr) then + pcall(actions.close, prompt_bufnr) + end - -- 1. If file is already open → jump to it - local tabpages = vim.api.nvim_list_tabpages() - for _, tab in ipairs(tabpages) do - for _, win in ipairs(vim.api.nvim_tabpage_list_wins(tab)) do - local buf = vim.api.nvim_win_get_buf(win) - if vim.api.nvim_buf_get_name(buf) == path then - vim.api.nvim_set_current_tabpage(tab) -- jump to tab - vim.api.nvim_set_current_win(win) -- jump to window - return - end - end - end + -- 1. If file is already open → jump to it + local tabpages = vim.api.nvim_list_tabpages() + for _, tab in ipairs(tabpages) do + for _, win in ipairs(vim.api.nvim_tabpage_list_wins(tab)) do + local buf = vim.api.nvim_win_get_buf(win) + if vim.api.nvim_buf_get_name(buf) == path then + vim.api.nvim_set_current_tabpage(tab) -- jump to tab + vim.api.nvim_set_current_win(win) -- jump to window + return + end + end + end - -- 2. If current tab has an empty "No Name" buffer → reuse it - local wins = vim.api.nvim_tabpage_list_wins(0) - for _, win in ipairs(wins) do - local buf = vim.api.nvim_win_get_buf(win) - local name = vim.api.nvim_buf_get_name(buf) - local buftype = vim.api.nvim_buf_get_option(buf, 'buftype') - local modified = vim.api.nvim_buf_get_option(buf, 'modified') - if name == '' and buftype == '' and not modified then - vim.api.nvim_set_current_win(win) - vim.cmd('edit ' .. vim.fn.fnameescape(path)) - return - end - end + -- 2. If current tab has an empty "No Name" buffer → reuse it + local wins = vim.api.nvim_tabpage_list_wins(0) + for _, win in ipairs(wins) do + local buf = vim.api.nvim_win_get_buf(win) + local name = vim.api.nvim_buf_get_name(buf) + local buftype = vim.api.nvim_buf_get_option(buf, 'buftype') + local modified = vim.api.nvim_buf_get_option(buf, 'modified') + if name == '' and buftype == '' and not modified then + vim.api.nvim_set_current_win(win) + vim.cmd('edit ' .. vim.fn.fnameescape(path)) + return + end + end - -- 3. Otherwise → open in a new tab - vim.cmd('tabnew ' .. vim.fn.fnameescape(path)) - end + -- 3. Otherwise → open in a new tab + vim.cmd('tabnew ' .. vim.fn.fnameescape(path)) + end - -- Split option in Telescope file picker with smart_open - local actions = require 'telescope.actions' - local action_state = require 'telescope.actions.state' + -- Split option in Telescope file picker with smart_open + local actions = require 'telescope.actions' + local action_state = require 'telescope.actions.state' - local function smart_open_split(prompt_bufnr, split_type) - local entry = action_state.get_selected_entry() - if not entry then - return - end + local function smart_open_split(prompt_bufnr, split_type) + local entry = action_state.get_selected_entry() + if not entry then + return + end - local path = entry.path or entry.filename - if not path then - return - end + local path = entry.path or entry.filename + if not path then + return + end - if prompt_bufnr and vim.api.nvim_buf_is_valid(prompt_bufnr) then - pcall(actions.close, prompt_bufnr) - end + if prompt_bufnr and vim.api.nvim_buf_is_valid(prompt_bufnr) then + pcall(actions.close, prompt_bufnr) + end - -- Check if file is already open - local open_tab, open_win - for _, tab in ipairs(vim.api.nvim_list_tabpages()) do - for _, win in ipairs(vim.api.nvim_tabpage_list_wins(tab)) do - local buf = vim.api.nvim_win_get_buf(win) - if vim.api.nvim_buf_get_name(buf) == path then - open_tab = tab - open_win = win - break - end - end - if open_tab then - break - end - end + -- Check if file is already open + local open_tab, open_win + for _, tab in ipairs(vim.api.nvim_list_tabpages()) do + for _, win in ipairs(vim.api.nvim_tabpage_list_wins(tab)) do + local buf = vim.api.nvim_win_get_buf(win) + if vim.api.nvim_buf_get_name(buf) == path then + open_tab = tab + open_win = win + break + end + end + if open_tab then + break + end + end - if open_tab then - local choice = vim.fn.confirm('File is already open in a tab. Open split here anyway?', '&Yes\n&No', 2) - if choice ~= 1 then - -- User chose No → jump to the tab where file is open - vim.api.nvim_set_current_tabpage(open_tab) - vim.api.nvim_set_current_win(open_win) - return - end - -- Else user chose Yes → continue to open split in current tab - end + if open_tab then + local choice = vim.fn.confirm('File is already open in a tab. Open split here anyway?', '&Yes\n&No', 2) + if choice ~= 1 then + -- User chose No → jump to the tab where file is open + vim.api.nvim_set_current_tabpage(open_tab) + vim.api.nvim_set_current_win(open_win) + return + end + -- Else user chose Yes → continue to open split in current tab + end - -- Open in split - if split_type == 'v' then - -- horizontal → always below - vim.cmd('belowright split ' .. vim.fn.fnameescape(path)) - elseif split_type == 'h' then - -- vertical → always right - vim.cmd('vertical rightbelow split ' .. vim.fn.fnameescape(path)) - end - end + -- Open in split + if split_type == 'v' then + -- horizontal → always below + vim.cmd('belowright split ' .. vim.fn.fnameescape(path)) + elseif split_type == 'h' then + -- vertical → always right + vim.cmd('vertical rightbelow split ' .. vim.fn.fnameescape(path)) + end + end - -- Telescope keymap using Smart Open - vim.keymap.set('n', 'sf', function() - require('telescope.builtin').find_files { - attach_mappings = function(_, map) - map('i', '', function(prompt_bufnr) - smart_open(prompt_bufnr) - end) - map('n', '', function(prompt_bufnr) - smart_open(prompt_bufnr) - end) - -- Horizontal split with 'h' - map('n', 'h', function(prompt_bufnr) - smart_open_split(prompt_bufnr, 'h') - end) - -- Vertical split with 'v' - map('n', 'v', function(prompt_bufnr) - smart_open_split(prompt_bufnr, 'v') - end) - return true - end, - } - end, { desc = '[S]earch [F]iles (Smart Open)' }) + -- Telescope keymap using Smart Open + vim.keymap.set('n', 'sf', function() + require('telescope.builtin').find_files { + attach_mappings = function(_, map) + map('i', '', function(prompt_bufnr) + smart_open(prompt_bufnr) + end) + map('n', '', function(prompt_bufnr) + smart_open(prompt_bufnr) + end) + -- Horizontal split with 'h' + map('n', 'h', function(prompt_bufnr) + smart_open_split(prompt_bufnr, 'h') + end) + -- Vertical split with 'v' + map('n', 'v', function(prompt_bufnr) + smart_open_split(prompt_bufnr, 'v') + end) + return true + end, + } + end, { desc = '[S]earch [F]iles (Smart Open)' }) - -- Telescope live_grep in git root - -- Function to find the git root directory based on the current buffer's path - local function find_git_root() - -- Use the current buffer's path as the starting point for the git search - local current_file = vim.api.nvim_buf_get_name(0) - local current_dir - local cwd = vim.fn.getcwd() - -- If the buffer is not associated with a file, return nil - if current_file == '' then - current_dir = cwd - else - -- Extract the directory from the current file's path - current_dir = vim.fn.fnamemodify(current_file, ':h') - end + -- Telescope live_grep in git root + -- Function to find the git root directory based on the current buffer's path + local function find_git_root() + -- Use the current buffer's path as the starting point for the git search + local current_file = vim.api.nvim_buf_get_name(0) + local current_dir + local cwd = vim.fn.getcwd() + -- If the buffer is not associated with a file, return nil + if current_file == '' then + current_dir = cwd + else + -- Extract the directory from the current file's path + current_dir = vim.fn.fnamemodify(current_file, ':h') + end - -- Find the Git root directory from the current file's path - local git_root = vim.fn.systemlist('git -C ' .. vim.fn.escape(current_dir, ' ') .. ' rev-parse --show-toplevel')[1] - if vim.v.shell_error ~= 0 then - print 'Not a git repository. Searching on current working directory' - return cwd - end - return git_root - end + -- Find the Git root directory from the current file's path + local git_root = vim.fn.systemlist('git -C ' .. vim.fn.escape(current_dir, ' ') .. ' rev-parse --show-toplevel')[1] + if vim.v.shell_error ~= 0 then + print 'Not a git repository. Searching on current working directory' + return cwd + end + return git_root + end - -- Custom live_grep function to search in git root - local function live_grep_git_root() - local git_root = find_git_root() - if git_root then - require('telescope.builtin').live_grep { - search_dirs = { git_root }, - } - end - end + -- Custom live_grep function to search in git root + local function live_grep_git_root() + local git_root = find_git_root() + if git_root then + require('telescope.builtin').live_grep { + search_dirs = { git_root }, + } + end + end - vim.api.nvim_create_user_command('LiveGrepGitRoot', live_grep_git_root, {}) + vim.api.nvim_create_user_command('LiveGrepGitRoot', live_grep_git_root, {}) - -- See `:help telescope.builtin` - vim.keymap.set('n', '?', require('telescope.builtin').oldfiles, { desc = '[?] Find recently opened files' }) - vim.keymap.set('n', '', require('telescope.builtin').buffers, { desc = '[ ] Find existing buffers' }) - vim.keymap.set('n', '/', function() - -- You can pass additional configuration to telescope to change theme, layout, etc. - require('telescope.builtin').current_buffer_fuzzy_find(require('telescope.themes').get_dropdown { - winblend = 10, - previewer = false, - }) - end, { desc = '[/] Fuzzily search in current buffer' }) + -- See `:help telescope.builtin` + vim.keymap.set('n', '?', require('telescope.builtin').oldfiles, { desc = '[?] Find recently opened files' }) + vim.keymap.set('n', '', require('telescope.builtin').buffers, { desc = '[ ] Find existing buffers' }) + vim.keymap.set('n', '/', function() + -- You can pass additional configuration to telescope to change theme, layout, etc. + require('telescope.builtin').current_buffer_fuzzy_find(require('telescope.themes').get_dropdown { + winblend = 10, + previewer = false, + }) + end, { desc = '[/] Fuzzily search in current buffer' }) - local function telescope_live_grep_open_files() - require('telescope.builtin').live_grep { - grep_open_files = true, - prompt_title = 'Live Grep in Open Files', - } - end - vim.keymap.set('n', 's/', telescope_live_grep_open_files, { desc = '[S]earch [/] in Open Files' }) - vim.keymap.set('n', 'ss', require('telescope.builtin').builtin, { desc = '[S]earch [S]elect Telescope' }) - vim.keymap.set('n', 'gf', function() - local is_git_dir = vim.fn.system('git rev-parse --is-inside-work-tree'):gsub('%s+', '') == 'true' - if not is_git_dir then - vim.notify('Not a git repository', vim.log.levels.WARN, { title = 'Telescope Git Files' }) - return - end + local function telescope_live_grep_open_files() + require('telescope.builtin').live_grep { + grep_open_files = true, + prompt_title = 'Live Grep in Open Files', + } + end + vim.keymap.set('n', 's/', telescope_live_grep_open_files, { desc = '[S]earch [/] in Open Files' }) + vim.keymap.set('n', 'ss', require('telescope.builtin').builtin, { desc = '[S]earch [S]elect Telescope' }) + vim.keymap.set('n', 'gf', function() + local is_git_dir = vim.fn.system('git rev-parse --is-inside-work-tree'):gsub('%s+', '') == 'true' + if not is_git_dir then + vim.notify('Not a git repository', vim.log.levels.WARN, { title = 'Telescope Git Files' }) + return + end - require('telescope.builtin').git_files { - attach_mappings = function(_, map) - local actions = require 'telescope.actions' - local action_state = require 'telescope.actions.state' + require('telescope.builtin').git_files { + attach_mappings = function(_, map) + local actions = require 'telescope.actions' + local action_state = require 'telescope.actions.state' - local function open_smart(prompt_bufnr) - local entry = action_state.get_selected_entry() - if not entry then - return - end - pcall(actions.close, prompt_bufnr) - smart_open(prompt_bufnr) - end + local function open_smart(prompt_bufnr) + local entry = action_state.get_selected_entry() + if not entry then + return + end + pcall(actions.close, prompt_bufnr) + smart_open(prompt_bufnr) + end - map('i', '', open_smart) - map('n', '', open_smart) - return true - end, - } - end, { desc = 'Search [G]it [F]iles (Smart Open)' }) - vim.keymap.set('n', 'si', require('telescope.builtin').help_tags, { desc = '[S]earch [I]nfo' }) - vim.keymap.set('n', 'sw', require('telescope.builtin').grep_string, { desc = '[S]earch current [W]ord' }) - vim.keymap.set('n', 'sg', require('telescope.builtin').live_grep, { desc = '[S]earch by [G]rep' }) - vim.keymap.set('n', 'sG', ':LiveGrepGitRoot', { desc = '[S]earch by [G]rep on Git Root' }) - vim.keymap.set('n', 'sd', require('telescope.builtin').diagnostics, { desc = '[S]earch [D]iagnostics' }) - vim.keymap.set('n', 'sr', require('telescope.builtin').resume, { desc = '[S]earch [R]esume' }) - end, + map('i', '', open_smart) + map('n', '', open_smart) + return true + end, + } + end, { desc = 'Search [G]it [F]iles (Smart Open)' }) + vim.keymap.set('n', 'si', require('telescope.builtin').help_tags, { desc = '[S]earch [I]nfo' }) + vim.keymap.set('n', 'sw', require('telescope.builtin').grep_string, { desc = '[S]earch current [W]ord' }) + vim.keymap.set('n', 'sg', require('telescope.builtin').live_grep, { desc = '[S]earch by [G]rep' }) + vim.keymap.set('n', 'sG', ':LiveGrepGitRoot', { desc = '[S]earch by [G]rep on Git Root' }) + vim.keymap.set('n', 'sd', require('telescope.builtin').diagnostics, { desc = '[S]earch [D]iagnostics' }) + vim.keymap.set('n', 'sr', require('telescope.builtin').resume, { desc = '[S]earch [R]esume' }) + end, } diff --git a/lua/custom/plugins/undotree.lua b/lua/custom/plugins/undotree.lua index 2b0efe2..23c3735 100644 --- a/lua/custom/plugins/undotree.lua +++ b/lua/custom/plugins/undotree.lua @@ -1,14 +1,14 @@ -- lua/custom/plugins/undotree.lua return { - 'mbbill/undotree', - keys = { - { 'u', vim.cmd.UndotreeToggle, desc = 'Toggle UndoTree' }, - }, - config = function() - -- Optional settings - vim.g.undotree_WindowLayout = 2 -- vertical split - vim.g.undotree_SplitWidth = 30 -- width of undo tree window - vim.g.undotree_SetFocusWhenToggle = 1 - vim.g.undotree_EnableDiff = 1 - end, + 'mbbill/undotree', + keys = { + { 'u', vim.cmd.UndotreeToggle, desc = 'Toggle UndoTree' }, + }, + config = function() + -- Optional settings + vim.g.undotree_WindowLayout = 2 -- vertical split + vim.g.undotree_SplitWidth = 30 -- width of undo tree window + vim.g.undotree_SetFocusWhenToggle = 1 + vim.g.undotree_EnableDiff = 1 + end, } diff --git a/lua/keymaps.lua b/lua/keymaps.lua index fe936a0..eaf75c2 100644 --- a/lua/keymaps.lua +++ b/lua/keymaps.lua @@ -9,19 +9,19 @@ vim.keymap.set('n', 'N', 'Nzzzv') -- [[ Replace all occurrences of the word under cursor ]] vim.keymap.set('n', 'F', function() - -- Save current cursor position - local pos = vim.api.nvim_win_get_cursor(0) - -- Get the word under the cursor - local word = vim.fn.expand '' - -- Ask user for the replacement - local replacement = vim.fn.input("Replace '" .. word .. "' with: ") - -- If user typed something, do the substitution - if replacement ~= '' then - -- %%s/.../.../gI = substitute globally, case-insensitive - vim.cmd(string.format('%%s/\\<%s\\>/%s/gI', word, replacement)) - end - -- Restore cursor position - vim.api.nvim_win_set_cursor(0, pos) + -- Save current cursor position + local pos = vim.api.nvim_win_get_cursor(0) + -- Get the word under the cursor + local word = vim.fn.expand '' + -- Ask user for the replacement + local replacement = vim.fn.input("Replace '" .. word .. "' with: ") + -- If user typed something, do the substitution + if replacement ~= '' then + -- %%s/.../.../gI = substitute globally, case-insensitive + vim.cmd(string.format('%%s/\\<%s\\>/%s/gI', word, replacement)) + end + -- Restore cursor position + vim.api.nvim_win_set_cursor(0, pos) end, { desc = 'Replace all occurrences of word under cursor' }) -- [[ Basic Keymaps ]] @@ -48,79 +48,79 @@ vim.keymap.set('n', 't', 'tabnew +termi') -- [[ Create an empty buffer in a new tab ]] vim.keymap.set('n', 'e', function() - vim.cmd 'tabnew' -- create a new tab - vim.cmd 'enew' -- create a new empty buffer in it + vim.cmd 'tabnew' -- create a new tab + vim.cmd 'enew' -- create a new empty buffer in it end, { noremap = true, silent = true }) -- [[ Horizontal split with new empty buffer below ]] vim.keymap.set('n', 'sv', function() - vim.cmd 'split' -- create horizontal split (above by default) - vim.cmd 'wincmd j' -- move to the new split below - vim.cmd 'enew' -- open new empty buffer + vim.cmd 'split' -- create horizontal split (above by default) + vim.cmd 'wincmd j' -- move to the new split below + vim.cmd 'enew' -- open new empty buffer end, { desc = 'New buffer in horizontal split (below)' }) -- [[ Vertical split with new empty buffer to the right ]] vim.keymap.set('n', 'sh', function() - vim.cmd 'vsplit' -- create vertical split (left by default) - vim.cmd 'wincmd l' -- move to the new split to the right - vim.cmd 'enew' -- open new empty buffer + vim.cmd 'vsplit' -- create vertical split (left by default) + vim.cmd 'wincmd l' -- move to the new split to the right + vim.cmd 'enew' -- open new empty buffer end, { desc = 'New buffer in vertical split (right)' }) -- [[ Save current buffer (asks for filename if new/unsaved) ]] vim.keymap.set('n', 'w', function() - if vim.api.nvim_buf_get_name(0) == '' then - -- Ask user for a filename - local filename = vim.fn.input('Save as: ', '', 'file') - if filename ~= '' then - vim.cmd('saveas ' .. vim.fn.fnameescape(filename)) - else - print 'Save cancelled' - end - else - vim.cmd 'w' - end + if vim.api.nvim_buf_get_name(0) == '' then + -- Ask user for a filename + local filename = vim.fn.input('Save as: ', '', 'file') + if filename ~= '' then + vim.cmd('saveas ' .. vim.fn.fnameescape(filename)) + else + print 'Save cancelled' + end + else + vim.cmd 'w' + end end, { desc = 'Save buffer (prompt if new file)' }) -- [[ Close current window (asks if buffer is unsaved) ]] vim.keymap.set('n', 'q', function() - if vim.bo.modified then - local choice = vim.fn.input 'Buffer modified! Save (y), Discard (n), Cancel (any other key)? ' - if choice:lower() == 'y' then - if vim.api.nvim_buf_get_name(0) == '' then - local filename = vim.fn.input('Save as: ', '', 'file') - if filename ~= '' then - vim.cmd('saveas ' .. vim.fn.fnameescape(filename)) - vim.cmd 'q' - else - print 'Save cancelled' - end - else - vim.cmd 'wq' - end - elseif choice:lower() == 'n' then - vim.cmd 'q!' - else - print 'Quit cancelled' - end - else - vim.cmd 'q' - end + if vim.bo.modified then + local choice = vim.fn.input 'Buffer modified! Save (y), Discard (n), Cancel (any other key)? ' + if choice:lower() == 'y' then + if vim.api.nvim_buf_get_name(0) == '' then + local filename = vim.fn.input('Save as: ', '', 'file') + if filename ~= '' then + vim.cmd('saveas ' .. vim.fn.fnameescape(filename)) + vim.cmd 'q' + else + print 'Save cancelled' + end + else + vim.cmd 'wq' + end + elseif choice:lower() == 'n' then + vim.cmd 'q!' + else + print 'Quit cancelled' + end + else + vim.cmd 'q' + end end, { desc = 'Close buffer (prompt if modified)' }) -- [[ Save changes and close current window (asks for filename if new/unsaved) ]] vim.keymap.set('n', 'qy', function() - if vim.api.nvim_buf_get_name(0) == '' then - -- Ask user for a filename - local filename = vim.fn.input('Save as: ', '', 'file') - if filename ~= '' then - vim.cmd('saveas ' .. vim.fn.fnameescape(filename)) - vim.cmd 'q' - else - print 'Save cancelled' - end - else - vim.cmd 'wq' - end + if vim.api.nvim_buf_get_name(0) == '' then + -- Ask user for a filename + local filename = vim.fn.input('Save as: ', '', 'file') + if filename ~= '' then + vim.cmd('saveas ' .. vim.fn.fnameescape(filename)) + vim.cmd 'q' + else + print 'Save cancelled' + end + else + vim.cmd 'wq' + end end, { desc = 'Save & quit (prompt if new file)' }) -- [[ Discard changes and Close current window ]] @@ -137,77 +137,77 @@ vim.keymap.set('n', 'll', 'ggVG', { desc = 'Select all' }) -- [[ Select all and copy to clipboard ]] vim.keymap.set('n', 'lY', function() - -- Get all lines from the buffer - local lines = vim.api.nvim_buf_get_lines(0, 0, -1, false) - -- Join them without adding an extra newline - local content = table.concat(lines, '\n') - -- Set to system clipboard - vim.fn.setreg('+', content) - vim.fn.setreg('*', content) - -- Notify - vim.schedule(function() - vim.notify('Copied all to clipboard', vim.log.levels.INFO) - end) + -- Get all lines from the buffer + local lines = vim.api.nvim_buf_get_lines(0, 0, -1, false) + -- Join them without adding an extra newline + local content = table.concat(lines, '\n') + -- Set to system clipboard + vim.fn.setreg('+', content) + vim.fn.setreg('*', content) + -- Notify + vim.schedule(function() + vim.notify('Copied all to clipboard', vim.log.levels.INFO) + end) end, { desc = 'Copy all to clipboard' }) -- [[ Copy to clipboard ]] -- Normal mode: copy current line vim.keymap.set('n', 'Y', function() - local line = vim.api.nvim_get_current_line() - vim.fn.setreg('+', line) - vim.fn.setreg('*', line) - vim.schedule(function() - vim.notify('Copied line to clipboard', vim.log.levels.INFO) - end) + local line = vim.api.nvim_get_current_line() + vim.fn.setreg('+', line) + vim.fn.setreg('*', line) + vim.schedule(function() + vim.notify('Copied line to clipboard', vim.log.levels.INFO) + end) end) -- Visual mode: copy selection, trim trailing newline if needed vim.keymap.set('x', 'Y', [["+y:lua require("copy_to_clipboard_fix").trim_clipboard()]]) -- [[ Paste from clipboard with line count ]] local function paste_from_clipboard() - local lines = vim.fn.getreg('+', 1, true) - local line_count = #lines - local mode = vim.fn.mode() - if mode:match '[vV\22]' then - -- Visual mode: get selection range reliably - local start_line = math.min(vim.fn.getpos('v')[2], vim.fn.getpos('.')[2]) - 1 - local end_line = math.max(vim.fn.getpos('v')[2], vim.fn.getpos('.')[2]) - -- Replace selection - vim.api.nvim_buf_set_lines(0, start_line, end_line, false, lines) - -- Exit visual mode - vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes('', true, false, true), 'n', true) - -- Notify after visual mode exit - vim.schedule(function() - vim.notify(line_count .. ' line' .. (line_count > 1 and 's' or '') .. ' pasted from clipboard', vim.log.levels.INFO) - end) - else - -- Normal mode: paste at cursor, characterwise - vim.api.nvim_put(lines, 'c', true, true) - -- Notify - vim.schedule(function() - vim.notify(line_count .. ' line' .. (line_count > 1 and 's' or '') .. ' pasted from clipboard', vim.log.levels.INFO) - end) - end + local lines = vim.fn.getreg('+', 1, true) + local line_count = #lines + local mode = vim.fn.mode() + if mode:match '[vV\22]' then + -- Visual mode: get selection range reliably + local start_line = math.min(vim.fn.getpos('v')[2], vim.fn.getpos('.')[2]) - 1 + local end_line = math.max(vim.fn.getpos('v')[2], vim.fn.getpos('.')[2]) + -- Replace selection + vim.api.nvim_buf_set_lines(0, start_line, end_line, false, lines) + -- Exit visual mode + vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes('', true, false, true), 'n', true) + -- Notify after visual mode exit + vim.schedule(function() + vim.notify(line_count .. ' line' .. (line_count > 1 and 's' or '') .. ' pasted from clipboard', vim.log.levels.INFO) + end) + else + -- Normal mode: paste at cursor, characterwise + vim.api.nvim_put(lines, 'c', true, true) + -- Notify + vim.schedule(function() + vim.notify(line_count .. ' line' .. (line_count > 1 and 's' or '') .. ' pasted from clipboard', vim.log.levels.INFO) + end) + end end vim.keymap.set('n', 'P', paste_from_clipboard, { desc = 'Paste from clipboard' }) vim.keymap.set('x', 'P', paste_from_clipboard, { desc = 'Paste from clipboard' }) -- [[ Paste at cursor inline ]] vim.keymap.set('n', 'p', function() - -- Get unnamed register - local content = vim.fn.getreg '"' - if content == '' then - return - end - -- Flatten multi-line content into a single string - content = content:gsub('\n', '') -- remove all newlines - -- Insert inline at cursor - local row, col = unpack(vim.api.nvim_win_get_cursor(0)) - local line = vim.api.nvim_get_current_line() - local new_line = line:sub(1, col) .. content .. line:sub(col + 1) - vim.api.nvim_set_current_line(new_line) - -- Move cursor to end of pasted text - vim.api.nvim_win_set_cursor(0, { row, col + #content }) + -- Get unnamed register + local content = vim.fn.getreg '"' + if content == '' then + return + end + -- Flatten multi-line content into a single string + content = content:gsub('\n', '') -- remove all newlines + -- Insert inline at cursor + local row, col = unpack(vim.api.nvim_win_get_cursor(0)) + local line = vim.api.nvim_get_current_line() + local new_line = line:sub(1, col) .. content .. line:sub(col + 1) + vim.api.nvim_set_current_line(new_line) + -- Move cursor to end of pasted text + vim.api.nvim_win_set_cursor(0, { row, col + #content }) end, { desc = 'Paste at cursor inline' }) -- [ In Visual Mode, paste over selection without yanking ] @@ -221,92 +221,92 @@ local actions = require 'telescope.actions' local action_state = require 'telescope.actions.state' local builtin = require 'telescope.builtin' local function smart_open_buffer() - builtin.buffers { - attach_mappings = function(_, map) - local function open_selected(prompt_bufnr) - local entry = action_state.get_selected_entry() - if not entry then - return - end - actions.close(prompt_bufnr) - local bufname = vim.api.nvim_buf_get_name(entry.bufnr) - if bufname == '' then - return - end - -- Check all windows in current tab - local current_tab = vim.api.nvim_get_current_tabpage() - for _, win in ipairs(vim.api.nvim_tabpage_list_wins(current_tab)) do - local buf = vim.api.nvim_win_get_buf(win) - if vim.api.nvim_buf_get_name(buf) == bufname then - vim.api.nvim_set_current_win(win) - return - end - end - -- Check other tabs - for _, tab in ipairs(vim.api.nvim_list_tabpages()) do - if tab ~= current_tab then - for _, win in ipairs(vim.api.nvim_tabpage_list_wins(tab)) do - local buf = vim.api.nvim_win_get_buf(win) - if vim.api.nvim_buf_get_name(buf) == bufname then - -- Switch tab first, then window - vim.api.nvim_set_current_tabpage(tab) - vim.api.nvim_set_current_win(win) - return - end - end - end - end - -- Not open anywhere → open in current window - vim.cmd('buffer ' .. entry.bufnr) - end - map('i', '', open_selected) - map('n', '', open_selected) - return true - end, - } + builtin.buffers { + attach_mappings = function(_, map) + local function open_selected(prompt_bufnr) + local entry = action_state.get_selected_entry() + if not entry then + return + end + actions.close(prompt_bufnr) + local bufname = vim.api.nvim_buf_get_name(entry.bufnr) + if bufname == '' then + return + end + -- Check all windows in current tab + local current_tab = vim.api.nvim_get_current_tabpage() + for _, win in ipairs(vim.api.nvim_tabpage_list_wins(current_tab)) do + local buf = vim.api.nvim_win_get_buf(win) + if vim.api.nvim_buf_get_name(buf) == bufname then + vim.api.nvim_set_current_win(win) + return + end + end + -- Check other tabs + for _, tab in ipairs(vim.api.nvim_list_tabpages()) do + if tab ~= current_tab then + for _, win in ipairs(vim.api.nvim_tabpage_list_wins(tab)) do + local buf = vim.api.nvim_win_get_buf(win) + if vim.api.nvim_buf_get_name(buf) == bufname then + -- Switch tab first, then window + vim.api.nvim_set_current_tabpage(tab) + vim.api.nvim_set_current_win(win) + return + end + end + end + end + -- Not open anywhere → open in current window + vim.cmd('buffer ' .. entry.bufnr) + end + map('i', '', open_selected) + map('n', '', open_selected) + return true + end, + } end -- Map it to vim.keymap.set('n', '', smart_open_buffer, { desc = 'Switch to Open Buffers' }) -- which-key, register it to show a description require('which-key').register { - [''] = { smart_open_buffer, 'Switch to Open Buffers' }, + [''] = { smart_open_buffer, 'Switch to Open Buffers' }, } -- [[ Smart open a file path, reusing empty buffers or tabs if possible ]] local function smart_open_file(path) - if not path or path == '' then - return - end - path = vim.fn.fnamemodify(path, ':p') -- make absolute - -- 1. If file is already open → jump to it - for _, tab in ipairs(vim.api.nvim_list_tabpages()) do - for _, win in ipairs(vim.api.nvim_tabpage_list_wins(tab)) do - local buf = vim.api.nvim_win_get_buf(win) - if vim.api.nvim_buf_get_name(buf) == path then - vim.api.nvim_set_current_tabpage(tab) - vim.api.nvim_set_current_win(win) - return - end - end - end - -- 2. If current tab has an empty "No Name" buffer → reuse it - for _, win in ipairs(vim.api.nvim_tabpage_list_wins(0)) do - local buf = vim.api.nvim_win_get_buf(win) - local name = vim.api.nvim_buf_get_name(buf) - local buftype = vim.api.nvim_buf_get_option(buf, 'buftype') - local modified = vim.api.nvim_buf_get_option(buf, 'modified') - if name == '' and buftype == '' and not modified then - vim.api.nvim_set_current_win(win) - vim.cmd('edit ' .. vim.fn.fnameescape(path)) - return - end - end - -- 3. Otherwise → open in a new tab - vim.cmd('tabedit ' .. vim.fn.fnameescape(path)) + if not path or path == '' then + return + end + path = vim.fn.fnamemodify(path, ':p') -- make absolute + -- 1. If file is already open → jump to it + for _, tab in ipairs(vim.api.nvim_list_tabpages()) do + for _, win in ipairs(vim.api.nvim_tabpage_list_wins(tab)) do + local buf = vim.api.nvim_win_get_buf(win) + if vim.api.nvim_buf_get_name(buf) == path then + vim.api.nvim_set_current_tabpage(tab) + vim.api.nvim_set_current_win(win) + return + end + end + end + -- 2. If current tab has an empty "No Name" buffer → reuse it + for _, win in ipairs(vim.api.nvim_tabpage_list_wins(0)) do + local buf = vim.api.nvim_win_get_buf(win) + local name = vim.api.nvim_buf_get_name(buf) + local buftype = vim.api.nvim_buf_get_option(buf, 'buftype') + local modified = vim.api.nvim_buf_get_option(buf, 'modified') + if name == '' and buftype == '' and not modified then + vim.api.nvim_set_current_win(win) + vim.cmd('edit ' .. vim.fn.fnameescape(path)) + return + end + end + -- 3. Otherwise → open in a new tab + vim.cmd('tabedit ' .. vim.fn.fnameescape(path)) end -- [[ Remap gf to use smart_open_file ]] vim.keymap.set('n', 'gf', function() - local path = vim.fn.expand '' -- get file under cursor - smart_open_file(path) + local path = vim.fn.expand '' -- get file under cursor + smart_open_file(path) end, { desc = 'Smart gf: open file under cursor in new tab or reuse buffer' }) diff --git a/lua/kickstart/plugins/autoformat.lua b/lua/kickstart/plugins/autoformat.lua index e11f1cf..87f6401 100644 --- a/lua/kickstart/plugins/autoformat.lua +++ b/lua/kickstart/plugins/autoformat.lua @@ -4,76 +4,76 @@ -- Adds additional commands as well to manage the behavior return { - 'neovim/nvim-lspconfig', - config = function() - -- Skip setting up LSP autoformatting if conform.nvim is being used - if package.loaded['conform'] then - return - end + 'neovim/nvim-lspconfig', + config = function() + -- Skip setting up LSP autoformatting if conform.nvim is being used + if package.loaded['conform'] then + return + end - -- Switch for controlling whether you want autoformatting. - -- Use :KickstartFormatToggle to toggle autoformatting on or off - local format_is_enabled = true - vim.api.nvim_create_user_command('KickstartFormatToggle', function() - format_is_enabled = not format_is_enabled - print('Setting autoformatting to: ' .. tostring(format_is_enabled)) - end, {}) + -- Switch for controlling whether you want autoformatting. + -- Use :KickstartFormatToggle to toggle autoformatting on or off + local format_is_enabled = true + vim.api.nvim_create_user_command('KickstartFormatToggle', function() + format_is_enabled = not format_is_enabled + print('Setting autoformatting to: ' .. tostring(format_is_enabled)) + end, {}) - -- Create an augroup that is used for managing our formatting autocmds. - -- We need one augroup per client to make sure that multiple clients - -- can attach to the same buffer without interfering with each other. - local _augroups = {} - local get_augroup = function(client) - if not _augroups[client.id] then - local group_name = 'kickstart-lsp-format-' .. client.name - local id = vim.api.nvim_create_augroup(group_name, { clear = true }) - _augroups[client.id] = id - end + -- Create an augroup that is used for managing our formatting autocmds. + -- We need one augroup per client to make sure that multiple clients + -- can attach to the same buffer without interfering with each other. + local _augroups = {} + local get_augroup = function(client) + if not _augroups[client.id] then + local group_name = 'kickstart-lsp-format-' .. client.name + local id = vim.api.nvim_create_augroup(group_name, { clear = true }) + _augroups[client.id] = id + end - return _augroups[client.id] - end + return _augroups[client.id] + end - -- Whenever an LSP attaches to a buffer, we will run this function. - -- - -- See `:help LspAttach` for more information about this autocmd event. - vim.api.nvim_create_autocmd('LspAttach', { - group = vim.api.nvim_create_augroup('kickstart-lsp-attach-format', { clear = true }), - -- This is where we attach the autoformatting for reasonable clients - callback = function(args) - local client_id = args.data.client_id - local client = vim.lsp.get_client_by_id(client_id) - local bufnr = args.buf + -- Whenever an LSP attaches to a buffer, we will run this function. + -- + -- See `:help LspAttach` for more information about this autocmd event. + vim.api.nvim_create_autocmd('LspAttach', { + group = vim.api.nvim_create_augroup('kickstart-lsp-attach-format', { clear = true }), + -- This is where we attach the autoformatting for reasonable clients + callback = function(args) + local client_id = args.data.client_id + local client = vim.lsp.get_client_by_id(client_id) + local bufnr = args.buf - -- Only attach to clients that support document formatting - if not client.server_capabilities.documentFormattingProvider then - return - end + -- Only attach to clients that support document formatting + if not client.server_capabilities.documentFormattingProvider then + return + end - -- Tsserver usually works poorly. Sorry you work with bad languages - -- You can remove this line if you know what you're doing :) - if client.name == 'tsserver' then - return - end + -- Tsserver usually works poorly. Sorry you work with bad languages + -- You can remove this line if you know what you're doing :) + if client.name == 'tsserver' then + return + end - -- Create an autocmd that will run *before* we save the buffer. - -- Run the formatting command for the LSP that has just attached. - vim.api.nvim_create_autocmd('BufWritePre', { - group = get_augroup(client), - buffer = bufnr, - callback = function() - if not format_is_enabled then - return - end + -- Create an autocmd that will run *before* we save the buffer. + -- Run the formatting command for the LSP that has just attached. + vim.api.nvim_create_autocmd('BufWritePre', { + group = get_augroup(client), + buffer = bufnr, + callback = function() + if not format_is_enabled then + return + end - vim.lsp.buf.format { - async = false, - filter = function(c) - return c.id == client.id - end, - } - end, - }) - end, - }) - end, + vim.lsp.buf.format { + async = false, + filter = function(c) + return c.id == client.id + end, + } + end, + }) + end, + }) + end, } diff --git a/lua/kickstart/plugins/debug.lua b/lua/kickstart/plugins/debug.lua index 7fc783f..da2980e 100644 --- a/lua/kickstart/plugins/debug.lua +++ b/lua/kickstart/plugins/debug.lua @@ -7,81 +7,81 @@ -- kickstart.nvim and not kitchen-sink.nvim ;) return { - -- NOTE: Yes, you can install new plugins here! - 'mfussenegger/nvim-dap', - -- NOTE: And you can specify dependencies as well - dependencies = { - -- Creates a beautiful debugger UI - 'rcarriga/nvim-dap-ui', + -- NOTE: Yes, you can install new plugins here! + 'mfussenegger/nvim-dap', + -- NOTE: And you can specify dependencies as well + dependencies = { + -- Creates a beautiful debugger UI + 'rcarriga/nvim-dap-ui', - -- Installs the debug adapters for you - 'williamboman/mason.nvim', - 'jay-babu/mason-nvim-dap.nvim', + -- Installs the debug adapters for you + 'williamboman/mason.nvim', + 'jay-babu/mason-nvim-dap.nvim', - -- Add your own debuggers here - 'leoluz/nvim-dap-go', - }, - config = function() - local dap = require 'dap' - local dapui = require 'dapui' + -- Add your own debuggers here + 'leoluz/nvim-dap-go', + }, + config = function() + local dap = require 'dap' + local dapui = require 'dapui' - require('mason-nvim-dap').setup { - -- Makes a best effort to setup the various debuggers with - -- reasonable debug configurations - automatic_setup = true, + require('mason-nvim-dap').setup { + -- Makes a best effort to setup the various debuggers with + -- reasonable debug configurations + automatic_setup = true, - -- You can provide additional configuration to the handlers, - -- see mason-nvim-dap README for more information - handlers = {}, + -- You can provide additional configuration to the handlers, + -- see mason-nvim-dap README for more information + handlers = {}, - -- You'll need to check that you have the required things installed - -- online, please don't ask me how to install them :) - ensure_installed = { - -- Update this to ensure that you have the debuggers for the langs you want - 'delve', - }, - } + -- You'll need to check that you have the required things installed + -- online, please don't ask me how to install them :) + ensure_installed = { + -- Update this to ensure that you have the debuggers for the langs you want + 'delve', + }, + } - -- Basic debugging keymaps, feel free to change to your liking! - vim.keymap.set('n', '', dap.continue, { desc = 'Debug: Start/Continue' }) - vim.keymap.set('n', '', dap.step_into, { desc = 'Debug: Step Into' }) - vim.keymap.set('n', '', dap.step_over, { desc = 'Debug: Step Over' }) - vim.keymap.set('n', '', dap.step_out, { desc = 'Debug: Step Out' }) - vim.keymap.set('n', 'b', dap.toggle_breakpoint, { desc = 'Debug: Toggle Breakpoint' }) - vim.keymap.set('n', 'B', function() - dap.set_breakpoint(vim.fn.input 'Breakpoint condition: ') - end, { desc = 'Debug: Set Breakpoint' }) + -- Basic debugging keymaps, feel free to change to your liking! + vim.keymap.set('n', '', dap.continue, { desc = 'Debug: Start/Continue' }) + vim.keymap.set('n', '', dap.step_into, { desc = 'Debug: Step Into' }) + vim.keymap.set('n', '', dap.step_over, { desc = 'Debug: Step Over' }) + vim.keymap.set('n', '', dap.step_out, { desc = 'Debug: Step Out' }) + vim.keymap.set('n', 'b', dap.toggle_breakpoint, { desc = 'Debug: Toggle Breakpoint' }) + vim.keymap.set('n', 'B', function() + dap.set_breakpoint(vim.fn.input 'Breakpoint condition: ') + end, { desc = 'Debug: Set Breakpoint' }) - -- Dap UI setup - -- For more information, see |:help nvim-dap-ui| - dapui.setup { - -- Set icons to characters that are more likely to work in every terminal. - -- Feel free to remove or use ones that you like more! :) - -- Don't feel like these are good choices. - icons = { expanded = '▾', collapsed = '▸', current_frame = '*' }, - controls = { - icons = { - pause = '⏸', - play = '▶', - step_into = '⏎', - step_over = '⏭', - step_out = '⏮', - step_back = 'b', - run_last = '▶▶', - terminate = '⏹', - disconnect = '⏏', - }, - }, - } + -- Dap UI setup + -- For more information, see |:help nvim-dap-ui| + dapui.setup { + -- Set icons to characters that are more likely to work in every terminal. + -- Feel free to remove or use ones that you like more! :) + -- Don't feel like these are good choices. + icons = { expanded = '▾', collapsed = '▸', current_frame = '*' }, + controls = { + icons = { + pause = '⏸', + play = '▶', + step_into = '⏎', + step_over = '⏭', + step_out = '⏮', + step_back = 'b', + run_last = '▶▶', + terminate = '⏹', + disconnect = '⏏', + }, + }, + } - -- Toggle to see last session result. Without this, you can't see session output in case of unhandled exception. - vim.keymap.set('n', '', dapui.toggle, { desc = 'Debug: See last session result.' }) + -- Toggle to see last session result. Without this, you can't see session output in case of unhandled exception. + vim.keymap.set('n', '', dapui.toggle, { desc = 'Debug: See last session result.' }) - dap.listeners.after.event_initialized['dapui_config'] = dapui.open - dap.listeners.before.event_terminated['dapui_config'] = dapui.close - dap.listeners.before.event_exited['dapui_config'] = dapui.close + dap.listeners.after.event_initialized['dapui_config'] = dapui.open + dap.listeners.before.event_terminated['dapui_config'] = dapui.close + dap.listeners.before.event_exited['dapui_config'] = dapui.close - -- Install golang specific config - require('dap-go').setup() - end, + -- Install golang specific config + require('dap-go').setup() + end, }