diff --git a/init.lua b/init.lua index ebf83752..4d766b54 100644 --- a/init.lua +++ b/init.lua @@ -121,18 +121,6 @@ require('lazy').setup({ BS = ' ', Space = ' ', Tab = ' ', - F1 = '', - F2 = '', - F3 = '', - F4 = '', - F5 = '', - F6 = '', - F7 = '', - F8 = '', - F9 = '', - F10 = '', - F11 = '', - F12 = '', }, }, @@ -197,6 +185,12 @@ require('lazy').setup({ vim.keymap.set('n', 'w=', '=', { desc = '[W]indow Equalize' }) vim.keymap.set('n', 'e', ':Neotree toggle', { desc = 'Toggle Neotree' }) + -- Комментирование строки на + / + vim.keymap.set('n', '/', 'gcc', { remap = true, desc = 'Toggle comment line' }) + + -- Комментирование выделения на + / + vim.keymap.set('v', '/', 'gc', { remap = true, desc = 'Toggle comment selection' }) + vim.keymap.set('n', '/', function() builtin.current_buffer_fuzzy_find(require('telescope.themes').get_dropdown { winblend = 10, @@ -254,9 +248,9 @@ require('lazy').setup({ map('gri', require('telescope.builtin').lsp_implementations, '[G]oto [I]mplementation') - map('grd', require('telescope.builtin').lsp_definitions, '[G]oto [D]efinition') + map('gd', require('telescope.builtin').lsp_definitions, '[G]oto [D]efinition') - map('grD', vim.lsp.buf.declaration, '[G]oto [D]eclaration') + map('gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration') map('gO', require('telescope.builtin').lsp_document_symbols, 'Open Document Symbols') @@ -264,6 +258,32 @@ require('lazy').setup({ map('grt', require('telescope.builtin').lsp_type_definitions, '[G]oto [T]ype Definition') + -- -- Переменная для хранения ID окна (чтобы знать, что закрывать) + -- local diagnostic_float = nil + -- + -- -- 1. Логика кнопки gl (Открыть/Закрыть) + -- map('gl', function() + -- if diagnostic_float and vim.api.nvim_win_is_valid(diagnostic_float) then + -- -- Если открыто — закрываем + -- vim.api.nvim_win_close(diagnostic_float, true) + -- diagnostic_float = nil + -- else + -- -- Если закрыто — открываем и запоминаем ID + -- diagnostic_float = vim.diagnostic.open_float(nil, { focusable = false }) + -- end + -- end, 'Toggle [L]ine Diagnostic') + + -- 2. Автоматическая чистка при переключении файла + vim.api.nvim_create_autocmd('BufLeave', { + buffer = event.buf, -- Работает только для этого буфера + callback = function() + if diagnostic_float and vim.api.nvim_win_is_valid(diagnostic_float) then + vim.api.nvim_win_close(diagnostic_float, true) + diagnostic_float = nil + end + end, + }) + ---@param client vim.lsp.Client ---@param method vim.lsp.protocol.Method ---@param bufnr? integer some lsp support methods only in specific files @@ -297,11 +317,11 @@ require('lazy').setup({ callback = vim.lsp.buf.clear_references, }) - vim.api.nvim_create_autocmd('CursorHold', { - callback = function() - vim.diagnostic.open_float(nil, { focusable = false }) - end, - }) + -- vim.api.nvim_create_autocmd('CursorHold', { + -- callback = function() + -- vim.diagnostic.open_float(nil, { focusable = false }) + -- end, + -- }) vim.api.nvim_create_autocmd('LspDetach', { group = vim.api.nvim_create_augroup('kickstart-lsp-detach', { clear = true }), @@ -313,6 +333,10 @@ require('lazy').setup({ end if client and client_supports_method(client, vim.lsp.protocol.Methods.textDocument_inlayHint, event.buf) then + -- 1. Явно выключаем подсказки при старте + vim.lsp.inlay_hint.enable(false, { bufnr = event.buf }) + + -- 2. Оставляем твой переключатель (Toggle) map('th', function() vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled { bufnr = event.buf }) end, '[T]oggle Inlay [H]ints') @@ -409,6 +433,10 @@ require('lazy').setup({ end end, formatters_by_ft = { + javascript = { 'prettier', stop_after_first = true }, + typescript = { 'prettier', stop_after_first = true }, + javascriptreact = { 'prettier', stop_after_first = true }, + typescriptreact = { 'prettier', stop_after_first = true }, lua = { 'stylua' }, }, }, @@ -439,6 +467,11 @@ require('lazy').setup({ opts = { keymap = { preset = 'default', + -- Tab принимает выбранную подсказку + [''] = { 'accept', 'fallback' }, + + -- Enter работает как обычно (новая строка), даже если меню открыто + [''] = { 'fallback' }, }, appearance = { diff --git a/lua/custom/plugins/copilot.lua b/lua/custom/plugins/copilot.lua new file mode 100644 index 00000000..1eb0a846 --- /dev/null +++ b/lua/custom/plugins/copilot.lua @@ -0,0 +1,19 @@ +return { + 'zbirenbaum/copilot.lua', + event = 'InsertEnter', + config = function() + require('copilot').setup { + suggestion = { + enabled = true, + auto_trigger = true, + keymap = { + accept = '', + next = '', + prev = '', + dismiss = '', + }, + }, + panel = { enabled = false }, + } + end, +} diff --git a/lua/custom/plugins/debug.lua b/lua/custom/plugins/debug.lua new file mode 100644 index 00000000..4b52160a --- /dev/null +++ b/lua/custom/plugins/debug.lua @@ -0,0 +1,67 @@ +return { + 'mfussenegger/nvim-dap', + dependencies = { + -- Красивый UI + 'rcarriga/nvim-dap-ui', + -- Обязательная зависимость для UI + 'nvim-neotest/nvim-nio', + -- Настройка для Go + 'leoluz/nvim-dap-go', + }, + config = function() + local dap = require 'dap' + local dapui = require 'dapui' + + -- Настраиваем UI + dapui.setup() + + -- Настраиваем Go (автоматически подхватит dlv) + require('dap-go').setup() + + -- Автоматическое открытие/закрытие окна отладки + dap.listeners.before.attach.dapui_config = function() + dapui.open() + end + dap.listeners.before.launch.dapui_config = function() + dapui.open() + end + -- dap.listeners.before.event_terminated.dapui_config = function() + -- dapui.close() + -- end + -- dap.listeners.before.event_exited.dapui_config = function() + -- dapui.close() + -- end + + -- КЛАВИШИ (Keymaps) + + -- Ставит точку остановки (Breakpoint) на текущей строке + vim.keymap.set('n', 'db', dap.toggle_breakpoint, { desc = 'Debug: Toggle Breakpoint' }) + + -- Запуск / Продолжить (F5 - как везде) + vim.keymap.set('n', '', dap.continue, { desc = 'Debug: Start/Continue' }) + + -- Шаг внутрь (Step Into - F11) + vim.keymap.set('n', '', dap.step_into, { desc = 'Debug: Step Into' }) + + -- Шаг через (Step Over - F10) + vim.keymap.set('n', '', dap.step_over, { desc = 'Debug: Step Over' }) + + -- Шаг назад (Step Out - Shift+F11) + vim.keymap.set('n', '', dap.step_out, { desc = 'Debug: Step Out' }) + + -- Открыть UI вручную (если вдруг закрылся) + vim.keymap.set('n', 'du', dapui.toggle, { desc = 'Debug: Toggle UI' }) + vim.keymap.set('n', 'dt', function() + require('dap-go').debug_test() + end, { desc = 'Debug: Run Nearest Test' }) + + vim.keymap.set('n', 'dq', function() + require('dapui').close() + end, { desc = 'Debug: [Q]uit/Close UI' }) + + vim.keymap.set('n', 'dx', function() + require('dap').terminate() -- Убить процесс + require('dapui').close() -- Закрыть окна + end, { desc = 'Debug: e[X]it and close' }) + end, +} diff --git a/lua/custom/plugins/diffview.lua b/lua/custom/plugins/diffview.lua new file mode 100644 index 00000000..8ea2428d --- /dev/null +++ b/lua/custom/plugins/diffview.lua @@ -0,0 +1,8 @@ +return { + 'sindrets/diffview.nvim', + cmd = { 'DiffviewOpen', 'DiffviewFileHistory' }, + keys = { + { 'gd', 'DiffviewOpen', desc = 'DiffView: Open' }, + { 'gh', 'DiffviewFileHistory %', desc = 'DiffView: File History' }, + }, +} diff --git a/lua/custom/plugins/editing.lua b/lua/custom/plugins/editing.lua new file mode 100644 index 00000000..d7fddaf8 --- /dev/null +++ b/lua/custom/plugins/editing.lua @@ -0,0 +1,3 @@ +return { + { 'windwp/nvim-autopairs', event = 'InsertEnter', config = true }, +} diff --git a/lua/custom/plugins/git-conflict.lua b/lua/custom/plugins/git-conflict.lua new file mode 100644 index 00000000..4454d3b2 --- /dev/null +++ b/lua/custom/plugins/git-conflict.lua @@ -0,0 +1,13 @@ +return { + 'akinsho/git-conflict.nvim', + version = '*', + config = function() + require('git-conflict').setup { + default_mappings = true, + -- co - выбрать Ours (свое) + -- ct - выбрать Theirs (чужое) + -- cb - оба + disable_diagnostics = true, + } + end, +} diff --git a/lua/custom/plugins/git.lua b/lua/custom/plugins/git.lua new file mode 100644 index 00000000..ea710700 --- /dev/null +++ b/lua/custom/plugins/git.lua @@ -0,0 +1,89 @@ +return { + { + 'lewis6991/gitsigns.nvim', + event = { 'BufReadPre', 'BufNewFile' }, + dependencies = { 'nvim-lua/plenary.nvim' }, + config = function() + local util = require 'gitsigns.util' + require('gitsigns').setup { + -- --- ТВОИ НАСТРОЙКИ ВИЗУАЛА (оставляем как было) --- + watch_gitdir = { interval = 1000, follow_files = true }, + attach_to_untracked = true, + current_line_blame = true, -- Блейм включен по умолчанию + current_line_blame_opts = { + virt_text = true, + virt_text_pos = 'right_align', + delay = 500, + }, + -- Твой кастомный форматтер блейма + current_line_blame_formatter = function(_, info) + return { + { '|| ', '@lsp.type.variable' }, + { info.author, '@lsp.type.comment' }, + { ' • ', '@lsp.type.variable' }, + { util.expand_format('', info), '@lsp.type.operator' }, + { ' • ', '@lsp.type.variable' }, + { info.summary or '', '@lsp.type.string' }, + } + end, + preview_config = { + border = 'rounded', + style = 'minimal', + relative = 'cursor', + row = 0, + col = 1, + }, + + -- --- ВОТ ЧЕГО НЕ ХВАТАЛО: КЛАВИШИ УПРАВЛЕНИЯ --- + 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 + + -- Навигация (переход к следующему изменению) + map('n', ']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', '[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) + map('n', 'hs', gs.stage_hunk, { desc = 'Git: [S]tage Hunk' }) -- Добавить кусок в индекс + map('n', 'hr', gs.reset_hunk, { desc = 'Git: [R]eset Hunk' }) -- Откатить кусок + map('v', 'hs', function() + gs.stage_hunk { vim.fn.line '.', vim.fn.line 'v' } + end, { desc = 'Git: Stage selection' }) + map('v', 'hr', function() + gs.reset_hunk { vim.fn.line '.', vim.fn.line 'v' } + end, { desc = 'Git: Reset selection' }) + + map('n', 'hS', gs.stage_buffer, { desc = 'Git: [S]tage Buffer' }) -- Добавить весь файл + map('n', 'hu', gs.undo_stage_hunk, { desc = 'Git: [U]ndo Stage Hunk' }) -- Убрать из индекса последний кусок + + map('n', 'hp', gs.preview_hunk, { desc = 'Git: [P]review Hunk' }) -- Показать превью изменений + + map('n', 'tb', gs.toggle_current_line_blame, { desc = 'Git: [T]oggle [B]lame line' }) -- Вкл/Выкл блейм + map('n', 'hd', gs.diffthis, { desc = 'Git: [D]iff against index' }) -- Показать diff + end, + } + end, + }, +} diff --git a/lua/custom/plugins/go.lua b/lua/custom/plugins/go.lua new file mode 100644 index 00000000..01e6c7b7 --- /dev/null +++ b/lua/custom/plugins/go.lua @@ -0,0 +1,27 @@ +return { + { + 'ray-x/go.nvim', + ft = { 'go', 'gomod' }, + dependencies = { + 'ray-x/guihua.lua', + 'nvim-treesitter/nvim-treesitter', + 'neovim/nvim-lspconfig', + }, + config = function() + require('go').setup { + lsp_cfg = true, + lsp_on_attach = function(client, bufnr) + if client.server_capabilities.documentFormattingProvider then + vim.api.nvim_create_autocmd('BufWritePre', { + group = vim.api.nvim_create_augroup('GoFormat', { clear = true }), + buffer = bufnr, + callback = function() + vim.lsp.buf.format { async = false } + end, + }) + end + end, + } + end, + }, +} diff --git a/lua/custom/plugins/init.lua b/lua/custom/plugins/init.lua deleted file mode 100644 index 00bd8a22..00000000 --- a/lua/custom/plugins/init.lua +++ /dev/null @@ -1,109 +0,0 @@ --- You can add your own plugins here or in other files in this directory! --- I promise not to create any merge conflicts in this directory :) --- --- See the kickstart.nvim README for more information --- Bootstrap lazy.nvim - -return { - { 'folke/snacks.nvim', opts = { image = { enabled = true } } }, - { - 'nvim-neo-tree/neo-tree.nvim', - branch = 'v3.x', - dependencies = { - 'nvim-lua/plenary.nvim', - 'MunifTanjim/nui.nvim', - 'nvim-tree/nvim-web-devicons', -- optional, but recommended - }, - opts = { - window = { - mappings = { - ['P'] = { -- toggle preview window - 'toggle_preview', - config = { use_float = true, use_snacks_image = true, use_image_nvim = true }, - }, - }, - }, - }, - lazy = false, -- neo-tree will lazily load itself - }, - - { - 'ray-x/go.nvim', - dependencies = { - 'ray-x/guihua.lua', -- required UI library - 'nvim-treesitter/nvim-treesitter', - 'neovim/nvim-lspconfig', - }, - ft = { 'go', 'gomod' }, - config = function() - require('go').setup { - lsp_cfg = true, -- auto-setup gopls - lsp_on_attach = function(client, bufnr) - -- Auto format on save - if client.server_capabilities.documentFormattingProvider then - vim.api.nvim_create_autocmd('BufWritePre', { - group = vim.api.nvim_create_augroup('GoFormat', { clear = true }), - buffer = bufnr, - callback = function() - vim.lsp.buf.format { async = false } - end, - }) - end - end, - } - end, - }, - - { - 'windwp/nvim-autopairs', - event = 'InsertEnter', - config = true, - }, - - -- ⬇️ Your gitsigns with blame-on-cursor - { - 'lewis6991/gitsigns.nvim', - event = { 'BufReadPre', 'BufNewFile' }, - dependencies = { 'nvim-lua/plenary.nvim' }, - config = function() - local util = require 'gitsigns.util' - require('gitsigns').setup { - watch_gitdir = { interval = 1000, follow_files = true }, - numhl = true, - linehl = false, - word_diff = false, - attach_to_untracked = true, - - current_line_blame = true, - current_line_blame_opts = { - virt_text = true, - virt_text_pos = 'right_align', -- 'eol' | 'overlay' | 'right_align' - delay = 500, - ignore_whitespace = false, - virt_text_priority = 100, - use_focus = true, - }, - current_line_blame_formatter = function(_, info) - return { - { '|| ', '@lsp.type.variable' }, - { info.author, '@lsp.type.comment' }, - { ' • ', '@lsp.type.variable' }, - { util.expand_format('', info), '@lsp.type.operator' }, - { ' • ', '@lsp.type.variable' }, - { info.summary or '', '@lsp.type.string' }, -- commit message - } - end, - - update_debounce = 200, - max_file_length = 40000, - preview_config = { - border = 'rounded', - style = 'minimal', - relative = 'cursor', - row = 0, - col = 1, - }, - } - end, - }, -} diff --git a/lua/custom/plugins/ui.lua b/lua/custom/plugins/ui.lua new file mode 100644 index 00000000..1319db75 --- /dev/null +++ b/lua/custom/plugins/ui.lua @@ -0,0 +1,26 @@ +return { + { 'folke/snacks.nvim', opts = { image = { enabled = true } } }, + { + 'nvim-neo-tree/neo-tree.nvim', + branch = 'v3.x', + dependencies = { + 'nvim-lua/plenary.nvim', + 'MunifTanjim/nui.nvim', + 'nvim-tree/nvim-web-devicons', + }, + git_status = { + enabled = false, -- <--- вот это + }, + opts = { + window = { + mappings = { + ['P'] = { + 'toggle_preview', + config = { use_float = true, use_snacks_image = true, use_image_nvim = true }, + }, + }, + }, + }, + lazy = false, + }, +}