Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
206 changes: 175 additions & 31 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ do
-- Enable faster startup by caching compiled Lua modules
vim.loader.enable()

-- Use zsh interactively so aliases and functions from .zshrc are available
vim.o.shell = 'zsh'
vim.o.shellcmdflag = '-ic'

-- Set <space> as the leader key
-- See `:help mapleader`
-- NOTE: Must happen before plugins are loaded (otherwise wrong leader will be used)
Expand All @@ -110,7 +114,7 @@ do
vim.o.number = true
-- You can also add relative line numbers, to help with jumping.
-- Experiment for yourself to see if you like it!
-- vim.o.relativenumber = true
vim.o.relativenumber = true

-- Enable mouse mode, can be useful for resizing splits for example!
vim.o.mouse = 'a'
Expand Down Expand Up @@ -205,6 +209,11 @@ do

vim.keymap.set('n', '<leader>q', vim.diagnostic.setloclist, { desc = 'Open diagnostic [Q]uickfix list' })

-- Buffer navigation
vim.keymap.set('n', '<S-h>', '<cmd>bprevious<CR>', { desc = 'Previous buffer' })
vim.keymap.set('n', '<S-l>', '<cmd>bnext<CR>', { desc = 'Next buffer' })
vim.keymap.set('n', '<leader>bd', function() require('mini.bufremove').delete() end, { desc = '[B]uffer [D]elete' })

-- Exit terminal mode in the builtin terminal with a shortcut that is a bit easier
-- for people to discover. Otherwise, you normally need to press <C-\><C-n>, which
-- is not what someone will guess without a bit more experience.
Expand Down Expand Up @@ -347,21 +356,6 @@ do
-- since otherwise the icons won't display properly.
if vim.g.have_nerd_font then vim.pack.add { gh 'nvim-tree/nvim-web-devicons' } end

-- Here is a more advanced configuration example that passes options to `gitsigns.nvim`
--
-- See `:help gitsigns` to understand what each configuration key does.
-- Adds git related signs to the gutter, as well as utilities for managing changes
vim.pack.add { gh 'lewis6991/gitsigns.nvim' }
require('gitsigns').setup {
signs = {
add = { text = '+' }, ---@diagnostic disable-line: missing-fields
change = { text = '~' }, ---@diagnostic disable-line: missing-fields
delete = { text = '_' }, ---@diagnostic disable-line: missing-fields
topdelete = { text = '‾' }, ---@diagnostic disable-line: missing-fields
changedelete = { text = '~' }, ---@diagnostic disable-line: missing-fields
},
}

-- Useful plugin to show you pending keybinds.
vim.pack.add { gh 'folke/which-key.nvim' }
require('which-key').setup {
Expand Down Expand Up @@ -417,6 +411,10 @@ do
inside_next = 'ii',
},
n_lines = 500,
custom_textobjects = {
-- `a` = argument: dia, daa, cia, caa, via, vaa
a = require('mini.ai').gen_spec.argument(),
},
}

-- Add/delete/replace surroundings (brackets, quotes, etc.)
Expand All @@ -430,19 +428,160 @@ do
-- You could remove this setup call if you don't like it,
-- and try some other statusline plugin
local statusline = require 'mini.statusline'
-- Set `use_icons` to true if you have a Nerd Font
statusline.setup { use_icons = vim.g.have_nerd_font }

-- You can configure sections in the statusline by overriding their
-- default behavior. For example, here we set the section for
-- cursor location to LINE:COLUMN
---@diagnostic disable-next-line: duplicate-set-field
statusline.section_location = function() return '%2l:%-2v' end
local function section_mode()
local mode, hl = statusline.section_mode { trunc_width = 120 }
return mode, hl
end

local function section_git()
local head = vim.b.gitsigns_head
if not head or head == '' then return '' end
local signs = vim.b.gitsigns_status_dict or {}
local added = signs.added or 0
local changed = signs.changed or 0
local removed = signs.removed or 0
local result = ' ' .. head
if added > 0 then result = result .. ' %#GitSignsAdd#+' .. added .. '%*' end
if changed > 0 then result = result .. ' %#GitSignsChange#~' .. changed .. '%*' end
if removed > 0 then result = result .. ' %#GitSignsDelete#-' .. removed .. '%*' end
return result
end

local function section_diagnostics()
local errors = #vim.diagnostic.get(0, { severity = vim.diagnostic.severity.ERROR })
local warnings = #vim.diagnostic.get(0, { severity = vim.diagnostic.severity.WARN })
if errors == 0 and warnings == 0 then return '' end
local result = ''
if errors > 0 then result = result .. '%#DiagnosticError#E:' .. errors .. '%* ' end
if warnings > 0 then result = result .. '%#DiagnosticWarn#W:' .. warnings .. '%*' end
return result
end

local function section_debug()
local ok, dap = pcall(require, 'dap')
if ok and dap.session() then return ' [DEBUG] ' end
return ''
end

statusline.setup {
use_icons = vim.g.have_nerd_font,
content = {
active = function()
local mode, mode_hl = section_mode()
local git = section_git()
local diag = section_diagnostics()
local dbg = section_debug()
local location = '%2l:%-2v'
return statusline.combine_groups {
{ hl = mode_hl, strings = { mode } },
{ hl = 'MiniStatuslineDevinfo', strings = { git } },
'%<', -- truncate point
{ hl = 'MiniStatuslineFilename', strings = { dbg } },
'%=', -- right align
{ hl = 'MiniStatuslineDevinfo', strings = { diag } },
{ hl = 'MiniStatuslineFileinfo', strings = {} },
{ hl = mode_hl, strings = { location } },
}
end,
},
}

require('mini.pairs').setup {
mappings = {
-- Brackets: só fecha automaticamente quando seguido de espaço, newline ou fechamento
['('] = { action = 'open', pair = '()', neigh_pattern = '[^\\][%s%)\n]' },
['['] = { action = 'open', pair = '[]', neigh_pattern = '[^\\][%s%]\n]' },
['{'] = { action = 'open', pair = '{}', neigh_pattern = '[^\\][%s%}\n]' },
[')'] = { action = 'close', pair = '()', neigh_pattern = '[^\\].' },
[']'] = { action = 'close', pair = '[]', neigh_pattern = '[^\\].' },
['}'] = { action = 'close', pair = '{}', neigh_pattern = '[^\\].' },
-- Aspas: pula o fechamento se já estiver antes dele
['"'] = { action = 'closeopen', pair = '""', neigh_pattern = '[^\\].' },
["'"] = { action = 'closeopen', pair = "''", neigh_pattern = '[^%a\\].' },
['`'] = { action = 'closeopen', pair = '``', neigh_pattern = '[^\\].' },
},
}

-- Pular qualquer fechamento com <C-l> no modo insert
vim.keymap.set('i', '<C-l>', function()
local col = vim.api.nvim_win_get_cursor(0)[2]
local next_char = vim.api.nvim_get_current_line():sub(col + 1, col + 1)
if next_char:match('[%)%]%}\'"`]') then
vim.api.nvim_win_set_cursor(0, { vim.api.nvim_win_get_cursor(0)[1], col + 1 })
end
end, { desc = 'Jump past closing pair' })
require('mini.comment').setup()
require('mini.bufremove').setup()

-- ... and there is more!
-- Check out: https://github.com/nvim-mini/mini.nvim
end

-- ============================================================
-- SECTION 3.0: SMOOTH SCROLLING
-- ============================================================
do
vim.pack.add { gh 'karb94/neoscroll.nvim' }
require('neoscroll').setup {
mappings = { '<C-u>', '<C-d>', '<C-b>', '<C-f>', 'zt', 'zz', 'zb' },
hide_cursor = false,
stop_eof = true,
easing = 'sine',
}
end

-- ============================================================
-- SECTION 3.1: BUFFERLINE
-- Visual tab bar for open buffers
-- ============================================================
do
vim.pack.add { gh 'akinsho/bufferline.nvim' }
require('bufferline').setup {
options = {
separator_style = 'slant',
show_buffer_close_icons = false,
show_close_icon = false,
},
}
end

-- ============================================================
-- SECTION 3.2: WINDOW PICKER
-- Quickly jump to any open window with a letter label
-- ============================================================
do
vim.pack.add { gh 's1n7ax/nvim-window-picker' }
require('window-picker').setup {
hint = 'floating-big-letter',
filter_rules = {
include_current_win = false,
autoselect_one = true,
bo = {
filetype = { 'neo-tree', 'neo-tree-popup', 'notify' },
buftype = { 'terminal', 'quickfix' },
},
},
}

vim.keymap.set('n', '<leader>w', function()
local win = require('window-picker').pick_window()
if win then vim.api.nvim_set_current_win(win) end
end, { desc = 'Pick [W]indow' })
end

-- ============================================================
-- SECTION 3.5: NAVIGATION / JUMP
-- flash.nvim for fast cursor jumping
-- ============================================================
do
vim.pack.add { gh 'folke/flash.nvim' }
require('flash').setup {}

vim.keymap.set({ 'n', 'x', 'o' }, 's', function() require('flash').jump() end, { desc = 'Flash Jump' })
vim.keymap.set({ 'n', 'x', 'o' }, 'S', function() require('flash').treesitter() end, { desc = 'Flash Treesitter' })
end

-- ============================================================
-- SECTION 4: SEARCH & NAVIGATION
-- Telescope setup, keymaps, LSP picker mappings
Expand Down Expand Up @@ -526,6 +665,7 @@ do

-- Find references for the word under your cursor.
vim.keymap.set('n', 'grr', builtin.lsp_references, { buffer = buf, desc = '[G]oto [R]eferences' })
vim.keymap.set('n', '<leader>gr', builtin.lsp_references, { buffer = buf, desc = '[G]oto [R]eferences' })

-- Jump to the implementation of the word under your cursor.
-- Useful when your language has ways of declaring types without an actual implementation.
Expand All @@ -535,6 +675,7 @@ do
-- This is where a variable was first declared, or where a function is defined, etc.
-- To jump back, press <C-t>.
vim.keymap.set('n', 'grd', builtin.lsp_definitions, { buffer = buf, desc = '[G]oto [D]efinition' })
vim.keymap.set('n', '<F12>', builtin.lsp_definitions, { buffer = buf, desc = '[G]oto [D]efinition' })

-- Fuzzy find all the symbols in your current document.
-- Symbols are things like variables, functions, types, etc.
Expand Down Expand Up @@ -688,7 +829,7 @@ do
local servers = {
-- clangd = {},
-- gopls = {},
-- pyright = {},
pyright = {},
-- rust_analyzer = {},
--
-- Some languages (like typescript) have entire language plugins that can be useful:
Expand Down Expand Up @@ -753,7 +894,10 @@ do
-- You can press `g?` for help in this menu.
local ensure_installed = vim.tbl_keys(servers or {})
vim.list_extend(ensure_installed, {
-- You can add other tools here that you want Mason to install
'black',
'isort',
'debugpy',
'ruff',
})

require('mason-tool-installer').setup { ensure_installed = ensure_installed }
Expand Down Expand Up @@ -792,7 +936,7 @@ do
formatters_by_ft = {
-- rust = { 'rustfmt' },
-- Conform can also run multiple formatters sequentially
-- python = { "isort", "black" },
python = { 'isort', 'black' },
--
-- You can use 'stop_after_first' to run the first available formatter from the list
-- javascript = { "prettierd", "prettier", stop_after_first = true },
Expand Down Expand Up @@ -846,7 +990,7 @@ do
-- <c-k>: Toggle signature help
--
-- See `:help blink-cmp-config-keymap` for defining your own keymap
preset = 'default',
preset = 'enter',

-- For more advanced Luasnip keymaps (e.g. selecting choice nodes, expansion) see:
-- https://github.com/L3MON4D3/LuaSnip?tab=readme-ov-file#keymaps
Expand Down Expand Up @@ -960,12 +1104,12 @@ do
-- Here are some example plugins that I've included in the Kickstart repository.
-- Uncomment any of the lines below to enable them (you will need to restart nvim).
--
-- require 'kickstart.plugins.debug'
require 'kickstart.plugins.debug'
-- require 'kickstart.plugins.indent_line'
-- require 'kickstart.plugins.lint'
require 'kickstart.plugins.lint'
-- require 'kickstart.plugins.autopairs'
-- require 'kickstart.plugins.neo-tree'
-- require 'kickstart.plugins.gitsigns' -- adds gitsigns recommended keymaps
require 'kickstart.plugins.neo-tree'
require 'kickstart.plugins.gitsigns' -- adds gitsigns recommended keymaps

-- NOTE: You can add your own plugins, configuration, etc from `lua/custom/plugins/*.lua`
--
Expand Down
59 changes: 33 additions & 26 deletions lua/kickstart/plugins/debug.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ vim.pack.add {
'https://github.com/nvim-neotest/nvim-nio',
'https://github.com/mason-org/mason.nvim',
'https://github.com/jay-babu/mason-nvim-dap.nvim',
'https://github.com/leoluz/nvim-dap-go',
'https://github.com/mfussenegger/nvim-dap-python',
}

-- Basic debugging keymaps, feel free to change to your liking!
vim.keymap.set('n', '<F5>', function() require('dap').continue() end, { desc = 'Debug: Start/Continue' })
vim.keymap.set('n', '<F1>', function() require('dap').step_into() end, { desc = 'Debug: Step Into' })
vim.keymap.set('n', '<F2>', function() require('dap').step_over() end, { desc = 'Debug: Step Over' })
vim.keymap.set('n', '<F3>', function() require('dap').step_out() end, { desc = 'Debug: Step Out' })
vim.keymap.set('n', '<leader>b', function() require('dap').toggle_breakpoint() end, { desc = 'Debug: Toggle Breakpoint' })
vim.keymap.set('n', '<leader>B', function() require('dap').set_breakpoint(vim.fn.input 'Breakpoint condition: ') end, { desc = 'Debug: Set Breakpoint' })
-- Toggle to see last session result. Without this, you can't see session output in case of unhandled exception.
vim.keymap.set('n', '<F7>', function() require('dapui').toggle() end, { desc = 'Debug: See last session result.' })
vim.keymap.set('n', '<leader>db', function() require('dap').toggle_breakpoint() end, { desc = '[D]ebug: Toggle [B]reakpoint' })
vim.keymap.set('n', '<leader>dB', function() require('dap').set_breakpoint(vim.fn.input 'Breakpoint condition: ') end, { desc = '[D]ebug: Set Conditional [B]reakpoint' })
vim.keymap.set('n', '<leader>dc', function() require('dap').continue() end, { desc = '[D]ebug: [C]ontinue' })
vim.keymap.set('n', '<leader>du', function() require('dapui').toggle() end, { desc = '[D]ebug: Toggle [U]I' })

local dap = require 'dap'
local dapui = require 'dapui'
Expand All @@ -40,8 +40,7 @@ require('mason-nvim-dap').setup {
-- 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',
'debugpy',
},
}

Expand Down Expand Up @@ -69,27 +68,35 @@ dapui.setup {
},
}

-- Change breakpoint icons
-- vim.api.nvim_set_hl(0, 'DapBreak', { fg = '#e51400' })
-- vim.api.nvim_set_hl(0, 'DapStop', { fg = '#ffcc00' })
-- local breakpoint_icons = vim.g.have_nerd_font
-- and { Breakpoint = '', BreakpointCondition = '', BreakpointRejected = '', LogPoint = '', Stopped = '' }
-- or { Breakpoint = '●', BreakpointCondition = '⊜', BreakpointRejected = '⊘', LogPoint = '◆', Stopped = '⭔' }
-- for type, icon in pairs(breakpoint_icons) do
-- local tp = 'Dap' .. type
-- local hl = (type == 'Stopped') and 'DapStop' or 'DapBreak'
-- vim.fn.sign_define(tp, { text = icon, texthl = hl, numhl = hl })
-- end
-- Highlight da linha atual em execução (fundo amarelo escuro)
vim.api.nvim_set_hl(0, 'DapStoppedLine', { bg = '#3d3400' })
vim.fn.sign_define('DapStopped', { text = '▶', texthl = 'DiagnosticWarn', linehl = 'DapStoppedLine', numhl = 'DiagnosticWarn' })
vim.fn.sign_define('DapBreakpoint', { text = '●', texthl = 'DiagnosticError', numhl = 'DiagnosticError' })
vim.fn.sign_define('DapBreakpointCondition', { text = '◉', texthl = 'DiagnosticWarn', numhl = 'DiagnosticWarn' })

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 {
delve = {
-- On Windows delve must be run attached or it crashes.
-- See https://github.com/leoluz/nvim-dap-go/blob/main/README.md#configuring
detached = vim.fn.has 'win32' == 0,
},
}
-- Install Python specific config
-- O adapter sempre usa o python do Mason (que tem debugpy instalado).
-- O python do projeto (venv) é usado apenas para rodar o script debugado.
local mason_python = vim.fn.stdpath 'data' .. '/mason/packages/debugpy/venv/bin/python'

local function get_project_python()
local venv = os.getenv 'VIRTUAL_ENV' or os.getenv 'CONDA_PREFIX'
if venv then return venv .. '/bin/python' end
local cwd_venv = vim.fn.getcwd() .. '/.venv/bin/python'
if vim.fn.executable(cwd_venv) == 1 then return cwd_venv end
return mason_python
end

require('dap-python').setup(mason_python)
require('dap-python').test_runner = 'pytest'

-- Patch all Python configurations to use project venv and integrated terminal
for _, config in ipairs(dap.configurations.python or {}) do
config.pythonPath = get_project_python
config.justMyCode = true
config.console = 'integratedTerminal'
end
Loading
Loading