diff --git a/init.lua b/init.lua index 921c5fa..44df3e4 100644 --- a/init.lua +++ b/init.lua @@ -15,5 +15,3 @@ _G.Config = { vim.api.nvim_create_autocmd(event, { group = gr, pattern = pattern, callback = callback, desc = desc, once = once }) end } - -Config.now_if_args = vim.fn.argc(-1) > 0 and Config.now or Config.later diff --git a/lua/git.lua b/lua/git.lua index 217cde1..601fc54 100644 --- a/lua/git.lua +++ b/lua/git.lua @@ -11,6 +11,13 @@ local function show(buf_id, items, query) end end +-- Diff current file against the index (staged version) +local function diff() + vim.cmd.diffthis() + vim.cmd('vert Git show :./%') + vim.cmd.diffthis() +end + -- Deleted files can't be opened, so choosing one stages the deletion instead local function choose(item) if vim.uv.fs_stat(item.path) then return MiniPick.default_choose(item) end @@ -18,6 +25,7 @@ local function choose(item) end return { + diff = diff, status = function() local lines = vim.fn.systemlist('git -c core.quotepath=false status -s -u') if vim.v.shell_error ~= 0 then diff --git a/lua/terminal.lua b/lua/terminal.lua deleted file mode 100644 index af1c193..0000000 --- a/lua/terminal.lua +++ /dev/null @@ -1,18 +0,0 @@ -local function open(cmd) - local lines = vim.o.lines - vim.o.cmdheight - (vim.o.laststatus > 0 and 1 or 0) - local w, h = math.floor(vim.o.columns * 0.95), math.floor(lines * 0.95) - local buf = vim.api.nvim_create_buf(false, true) - vim.bo[buf].bufhidden = 'wipe' - - local win = vim.api.nvim_open_win(buf, true, { - relative = 'editor', - width = w, - height = h, - row = math.floor((lines - h) / 2), - col = math.floor((vim.o.columns - w) / 2), - }) - - vim.fn.jobstart(cmd, { term = true, on_exit = function() pcall(vim.api.nvim_win_close, win, true) end }) -end - -return { open = open } diff --git a/plugin/10_options.lua b/plugin/10_options.lua index f523a78..2bde9e1 100644 --- a/plugin/10_options.lua +++ b/plugin/10_options.lua @@ -1,45 +1,41 @@ -- General -vim.g.mapleader = ' ' -- Use `` as key -vim.o.undofile = true -- Enable persistent undo -vim.o.shada = "'50,<20,s10,:100,/50,@50,h" -- Limit ShaDa file (for startup) +vim.g.mapleader = ' ' -- Use as key +vim.o.undofile = true -- Keep undo history after closing files +vim.o.shada = "'50,<20,s10,:100,/50,@50,h,r/tmp/" -- Fewer saved items (faster startup), skip /tmp files -- UI -vim.o.breakindent = true -- Indent wrapped lines to match line start -vim.o.breakindentopt = 'list:-1' -- Add padding for lists (if 'wrap' is set) -vim.o.cursorline = true -- Enable current line highlighting -vim.o.linebreak = true -- Wrap lines at 'breakat' (if 'wrap' is set) -vim.o.list = true -- Show helpful text indicators -vim.o.listchars = 'tab:→ ,trail:·,nbsp:␣' -- Characters for list mode -vim.o.number = true -- Show line numbers -vim.o.pumheight = 10 -- Make popup menu smaller -vim.o.pummaxwidth = 80 -- Make popup menu not too wide -vim.o.shortmess = 'CFOSWacou' -- Disable some built-in completion messages -vim.o.signcolumn = 'yes' -- Always show signcolumn (less flicker) -vim.o.splitbelow = true -- Horizontal splits will be below -vim.o.splitkeep = 'screen' -- Reduce scroll during window split -vim.o.splitright = true -- Vertical splits will be to the right -vim.o.wrap = false -- Don't visually wrap lines -vim.o.winborder = 'rounded' -- Use border in floating windows -vim.o.pumborder = 'rounded' -- Use border in popup menu -vim.o.cmdheight = 0 -- Hide the command line when not in use -vim.cmd('syntax off') -- Disable legacy syntax highlighting -require('vim._core.ui2').enable({ -- Enable new ui (requires nightly) +vim.o.number = true -- Show line numbers +vim.o.cursorline = true -- Highlight the line the cursor is on +vim.o.signcolumn = 'yes' -- Always show sign column (no text shifting) +vim.o.wrap = false -- Don't wrap long lines +vim.o.list = true -- Show tabs, trailing spaces and nbsp +vim.o.listchars = 'tab:→ ,trail:·,nbsp:␣' -- Symbols used for those characters +vim.o.fillchars = 'eob: ' -- Hide `~` on lines after end of buffer +vim.o.splitbelow = true -- Open horizontal splits below +vim.o.splitright = true -- Open vertical splits to the right +vim.o.splitkeep = 'screen' -- Keep text in place when opening splits +vim.o.cmdheight = 0 -- Hide command line when not typing a command +vim.o.shortmess = 'CFOSWacou' -- Hide completion, search count, undo and write messages +vim.cmd.syntax('off') -- Disable legacy syntax (treesitter handles highlighting) +require('vim._core.ui2').enable({ -- New message/cmdline UI, messages in float (nightly) msg = { targets = 'msg' } }) -- Editing -vim.o.expandtab = true -- Convert tabs to spaces -vim.o.formatoptions = 'rqnl1j' -- Improve comment editing -vim.o.ignorecase = true -- Ignore case during search -vim.o.infercase = true -- Infer case in built-in completion -vim.o.shiftwidth = 2 -- Use this number of spaces for indentation -vim.o.smartcase = true -- Respect case if search pattern has upper case -vim.o.spelloptions = 'camel' -- Treat camelCase word parts as separate words -vim.o.tabstop = 2 -- Show tab as this number of spaces -vim.o.virtualedit = 'block' -- Allow going past end of line in blockwise mode +vim.o.expandtab = true -- Insert spaces when pressing +vim.o.shiftwidth = 2 -- Spaces per indent level (>>, <<, autoindent) +vim.o.tabstop = 2 -- Display width of a tab character +vim.o.ignorecase = true -- Ignore case when searching +vim.o.smartcase = true -- ...unless the pattern contains uppercase +vim.o.virtualedit = 'block' -- Allow cursor past end of line in visual block +vim.o.spelloptions = 'camel' -- Spell-check camelCase words per part -vim.o.complete = '.,w,b,kspell' -- Use less sources -vim.o.completeopt = 'menuone,noselect,fuzzy' -- Use custom behavior +-- Completion +vim.o.autocomplete = true -- Show completion popup while typing +vim.o.complete = '.,w,b,kspell' -- Complete from buffer, windows, buffers, spell +vim.o.completeopt = 'menuone,noselect,fuzzy,popup' -- Show menu for one match, don't preselect, fuzzy match, description popup +vim.o.pumheight = 10 -- Max items visible in completion popup +vim.o.pummaxwidth = 120 -- Max width of completion popup -- Autocommands Config.autocmd('TextYankPost', '*', function() vim.hl.hl_op() end, 'Highlight yanked text') @@ -59,6 +55,5 @@ Config.later(function() [vim.diagnostic.severity.INFO] = '', }, }, - virtual_text = false, }) end) diff --git a/plugin/20_keymaps.lua b/plugin/20_keymaps.lua index 3e75873..ba10409 100644 --- a/plugin/20_keymaps.lua +++ b/plugin/20_keymaps.lua @@ -1,14 +1,9 @@ -- Clues Config.leader_group_clues = { - { mode = 'n', keys = 'b', desc = '+Buffer' }, { mode = 'n', keys = 'd', desc = '+Debug' }, { mode = 'n', keys = 'e', desc = '+Explore' }, { mode = 'n', keys = 'f', desc = '+Find' }, { mode = { 'n', 'x' }, keys = 'g', desc = '+Git' }, - { mode = { 'n', 'x' }, keys = 'l', desc = '+Language' }, - { mode = 'n', keys = 'r', desc = '+Request' }, - { mode = 'n', keys = 't', desc = '+Terminal' }, - { mode = 'n', keys = '', desc = '+Tab' }, } -- Keymap Helpers @@ -16,30 +11,11 @@ local leader = function(suffix, rhs, desc, mode) vim.keymap.set(mode or 'n', '' .. suffix, rhs, { desc = desc, silent = true }) end --- Buffers -local new_scratch_buffer = function() - vim.api.nvim_win_set_buf(0, vim.api.nvim_create_buf(true, true)) -end - -local close_invisible_buffers = function() - local visible = vim.iter(vim.api.nvim_list_wins()):map(vim.api.nvim_win_get_buf):totable() - vim.iter(vim.api.nvim_list_bufs()) - :filter(function(buf) return not vim.list_contains(visible, buf) end) - :each(function(buf) pcall(vim.api.nvim_buf_delete, buf, { force = false }) end) -end - -leader('bd', vim.cmd.bdelete, 'Delete') -leader('bs', new_scratch_buffer, 'Scratch') -leader('bw', vim.cmd.bwipeout, 'Wipeout') -leader('bo', close_invisible_buffers, 'Close invisible buffers') - -- Debug leader('db', function() require('dap').toggle_breakpoint() end, 'Toggle Breakpoint') -leader('dl', function() require('dap').set_breakpoint(nil, nil, vim.fn.input('Log point: ')) end, 'Log point') leader('dc', function() require('dap').continue() end, 'Run/Continue') leader('dC', function() require('dap').run_to_cursor() end, 'Run to Cursor') -leader('de', function() require('dap.ui.widgets').hover() end, 'Inspect') -leader('dr', function() require('dap').repl.open() end, 'Open REPL') +leader('di', function() require('dap.ui.widgets').hover() end, 'Inspect') leader('dt', function() require('dap').terminate() end, 'Terminate') -- Explore @@ -48,11 +24,13 @@ local explore_at_file = function() MiniFiles.open(vim.uv.fs_stat(file) and file or nil) end -leader('ed', function() MiniFiles.open() end, 'Directory') +local yank_path = function(modifier) + return function() vim.fn.setreg('+', vim.fn.fnamemodify(vim.api.nvim_buf_get_name(0), modifier)) end +end + leader('ef', explore_at_file, 'File directory') -leader('ey', function() vim.fn.setreg('+', vim.fn.fnamemodify(vim.api.nvim_buf_get_name(0), ':.')) end, 'Yank relative path') -leader('eY', function() vim.fn.setreg('+', vim.api.nvim_buf_get_name(0)) end, 'Yank absolute path') -leader('en', vim.cmd.messages, 'Notifications') +leader('ey', yank_path(':.'), 'Yank relative path') +leader('eY', yank_path(':p'), 'Yank absolute path') -- Find leader('fb', function() MiniPick.builtin.buffers() end, 'Buffers') @@ -63,7 +41,6 @@ leader('fD', function() MiniExtra.pickers.diagnostic({ scope = 'current' }) end, leader('ff', function() MiniPick.builtin.files() end, 'Files') leader('fg', function() MiniPick.builtin.grep_live() end, 'Grep live') leader('fG', function() MiniPick.builtin.grep({ pattern = vim.fn.expand('') }) end, 'Grep word') -leader('fh', function() MiniPick.builtin.help() end, 'Help tags') leader('fl', function() MiniExtra.pickers.buf_lines({ scope = 'all' }) end, 'Lines (all)') leader('fL', function() MiniExtra.pickers.buf_lines({ scope = 'current' }) end, 'Lines (buf)') leader('fm', function() require('git').status() end, 'Modified / changed files') @@ -74,47 +51,5 @@ leader('fS', function() MiniExtra.pickers.lsp({ scope = 'document_symbol' }) end leader('f:', function() MiniExtra.pickers.history({ scope = ':' }) end, 'Command history') -- Git -local diff_unstaged = function() - vim.cmd.diffthis() - vim.cmd('vert Git show :./%') - vim.cmd.diffthis() -end - -leader('ga', function() vim.cmd('Git add %') end, 'Add current file') -leader('gd', diff_unstaged, 'Diff unstaged') +leader('gd', function() require('git').diff() end, 'Diff unstaged') leader('gs', function() MiniGit.show_at_cursor() end, 'Show at cursor', { 'n', 'x' }) - --- Language -leader('la', function() vim.lsp.buf.code_action() end, 'Actions') -leader('lf', function() require('conform').format({ async = true }) end, 'Format', { 'n', 'x' }) -leader('li', function() vim.lsp.buf.implementation() end, 'Implementation') -leader('ll', function() vim.lsp.codelens.run() end, 'Lens') -leader('lr', function() vim.lsp.buf.rename() end, 'Rename') -leader('lR', function() vim.lsp.buf.references() end, 'References') -leader('ls', function() vim.lsp.buf.definition() end, 'Source definition') -leader('lt', function() vim.lsp.buf.type_definition() end, 'Type definition') - --- Request -leader('rs', function() require('kulala').run() end, 'Send HTTP request') - --- Terminal -local open_ai = function() - vim.cmd('vertical term ' .. (vim.fn.executable('pi') == 1 and 'pi' or 'claude')) -end - -leader('tT', function() vim.cmd('horizontal term') end, 'Terminal (horizontal)') -leader('tt', function() vim.cmd('vertical term') end, 'Terminal (vertical)') -leader('ta', open_ai, 'AI') -leader('tf', function() require('terminal').open(vim.o.shell) end, 'Terminal (popup)') -leader('tg', function() require('terminal').open('lazygit') end, 'LazyGit') -leader('ts', function() require('terminal').open('lazysql') end, 'LazySQL') - --- Tabs -leader('', vim.cmd.tabnew, 'New tab') -leader('d', vim.cmd.tabclose, 'Close tab') -leader(']', vim.cmd.tabnext, 'Next tab') -leader('[', vim.cmd.tabprevious, 'Previous tab') - --- Overwrites -vim.keymap.set('n', '', vim.cmd.nohlsearch, { desc = 'Clear highlights', silent = true }) -vim.keymap.set('t', '', '', { desc = 'Terminal window navigation', silent = true }) diff --git a/plugin/30_mini.lua b/plugin/30_mini.lua index 05c8c25..b9c727f 100644 --- a/plugin/30_mini.lua +++ b/plugin/30_mini.lua @@ -64,7 +64,7 @@ Config.later(function() end) -- File Explorer & auto root -Config.now_if_args(function() +Config.now(function() require('mini.files').setup() Config.autocmd('User', 'MiniFilesExplorerOpen', function() MiniFiles.set_bookmark('c', vim.fn.stdpath('config'), { desc = 'Config' }) diff --git a/plugin/40_plugins.lua b/plugin/40_plugins.lua index 21505e5..e3b1b55 100644 --- a/plugin/40_plugins.lua +++ b/plugin/40_plugins.lua @@ -11,7 +11,7 @@ Config.now(function() end) -- Treesitter -Config.now_if_args(function() +Config.now(function() vim.pack.add({ 'https://github.com/nvim-treesitter/nvim-treesitter' }) local filetypes = { @@ -63,10 +63,10 @@ Config.later(function() local dap_signs = { DapBreakpoint = { text = '', texthl = 'DapBreakpoint' }, DapBreakpointCondition = { text = '', texthl = 'DapBreakpointCondition' }, - DapLogPoint = { text = '', texthl = 'DapLogPoint' }, DapStopped = { text = '', texthl = 'DapStopped', linehl = 'DapStoppedLine' }, DapBreakpointRejected = { text = '', texthl = 'DapBreakpointRejected' }, } + for name, sign in pairs(dap_signs) do vim.fn.sign_define(name, sign) end @@ -74,12 +74,6 @@ Config.later(function() require('dap').adapters.go = { type = 'server', host = '127.0.0.1', port = '${port}' } end) --- Kulala -Config.autocmd('FileType', 'http', function() - vim.pack.add({ 'https://github.com/mistweaverco/kulala.nvim' }) - require('kulala').setup({ default_env = 'dev' }) -end, 'Setup Kulala', true) - -- Flutter Config.autocmd('FileType', 'dart', function() vim.pack.add({