diff --git a/init.lua b/init.lua index 495fdb55..d3365cf6 100644 --- a/init.lua +++ b/init.lua @@ -1058,6 +1058,7 @@ require('lazy').setup({ -- -- Uncomment the following line and add your plugins to `lua/custom/plugins/*.lua` to get going. { import = 'custom.plugins' }, + -- -- For additional information with loading, sourcing and examples see `:help lazy.nvim-🔌-plugin-spec` -- Or use telescope! @@ -1085,5 +1086,8 @@ require('lazy').setup({ }, }) +-- Custom configuration +require 'custom.commands' + -- The line beneath this is called `modeline`. See `:help modeline` -- vim: ts=2 sts=2 sw=2 et diff --git a/lua/custom/commands/files.lua b/lua/custom/commands/files.lua new file mode 100644 index 00000000..e6e34928 --- /dev/null +++ b/lua/custom/commands/files.lua @@ -0,0 +1,2 @@ +-- Update file on focus if it was changed +vim.api.nvim_create_autocmd({ 'FocusGained', 'BufEnter' }, { command = 'checktime' }) diff --git a/lua/custom/commands/init.lua b/lua/custom/commands/init.lua new file mode 100644 index 00000000..9325da04 --- /dev/null +++ b/lua/custom/commands/init.lua @@ -0,0 +1,3 @@ +require 'custom.commands.files' +require 'custom.commands.quickfix' +require 'custom.commands.shadafile' diff --git a/lua/custom/commands/quickfix.lua b/lua/custom/commands/quickfix.lua new file mode 100644 index 00000000..5eb66245 --- /dev/null +++ b/lua/custom/commands/quickfix.lua @@ -0,0 +1,51 @@ +-- Shortcuts for quickfix + +local function clamp(target, a, b) + if target <= a then + return a + end + if target >= b then + return b + end + return target +end + +local function clamp_linecount(target) + local count = vim.api.nvim_buf_line_count(0) + return clamp(target, 1, count) +end + +vim.api.nvim_create_autocmd('BufWinEnter', { + callback = function(ev) + if vim.bo[ev.buf].buftype ~= 'quickfix' then + return + end + + vim.keymap.set('n', 'dd', function() + local cursor = vim.api.nvim_win_get_cursor(0) + + local entries = vim.fn.getqflist() + local rm_index = cursor[1] + table.remove(entries, rm_index) + vim.fn.setqflist(entries) + + vim.api.nvim_win_set_cursor(0, { clamp_linecount(cursor[1]), cursor[2] }) + end, { buffer = ev.buf }) + + vim.keymap.set('v', 'd', function() + local cursor = vim.api.nvim_win_get_cursor(0) + + local from, to = vim.fn.line 'v', vim.fn.line '.' + local qf = {} + for i, v in ipairs(vim.fn.getqflist()) do + if i < from or i > to then + table.insert(qf, v) + end + end + vim.fn.setqflist(qf) + vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes('', true, true, true), 'nv', false) + + vim.api.nvim_win_set_cursor(0, { clamp_linecount(from), cursor[2] }) + end, { buffer = ev.buf }) + end, +}) diff --git a/lua/custom/commands/shadafile.lua b/lua/custom/commands/shadafile.lua new file mode 100644 index 00000000..c1abfa11 --- /dev/null +++ b/lua/custom/commands/shadafile.lua @@ -0,0 +1,26 @@ +-- This code configures Neovim's ShaDa file (short for Shared data) to be stored separately for each project. +-- The benefit of this approach is that each project gets its own independent ShaDa file, which means: +-- - Project-specific histories don't mix +-- - Marks and registers are isolated per project +-- - Buffer lists are maintained separately +-- - Less chance of conflicts between different projects +-- +-- For example, if you're working on two different projects: +-- - Project A: `/home/user/projectA` -> Gets its own ShaDa file +-- - Project B: `/home/user/projectB` -> Gets its own ShaDa file +-- +-- This keeps the project-specific data cleanly separated instead of having all projects share the same ShaDa file. + +vim.opt.shadafile = (function() + local data = vim.fn.stdpath 'data' + + local cwd = vim.fn.getcwd() + cwd = vim.fs.root(cwd, '.git') or cwd + + local cwd_b64 = vim.base64.encode(cwd) + + local file = vim.fs.joinpath(data, 'project_shada', cwd_b64) + vim.fn.mkdir(vim.fs.dirname(file), 'p') + + return file +end)() diff --git a/lua/custom/plugins/init.lua b/lua/custom/plugins/init.lua index 3a8340db..067a7715 100644 --- a/lua/custom/plugins/init.lua +++ b/lua/custom/plugins/init.lua @@ -2,11 +2,6 @@ -- I promise not to create any merge conflicts in this directory :) -- -- See the kickstart.nvim README for more information -vim.api.nvim_create_autocmd({ 'FocusGained', 'BufEnter' }, { command = 'checktime' }) - -vim.api.nvim_create_user_command('DeleteOtherBuffers', function() - require('snacks').bufdelete.other() -end, { desc = 'Delete Other Buffers' }) -- Resizing windows vim.keymap.set('n', '', '5<', { desc = 'Decrease window width' }) diff --git a/lua/custom/plugins/oil.lua b/lua/custom/plugins/oil.lua index 6092ff5a..af08a275 100644 --- a/lua/custom/plugins/oil.lua +++ b/lua/custom/plugins/oil.lua @@ -16,7 +16,6 @@ return { } end, keys = { - -- { '=', 'Oil', mode = 'n', desc = 'Open Filesystem' }, { '-', 'Oil --float', mode = 'n', desc = 'Open Floating Filesystem' }, }, } diff --git a/lua/custom/plugins/other.lua b/lua/custom/plugins/other.lua new file mode 100644 index 00000000..5ba28db2 --- /dev/null +++ b/lua/custom/plugins/other.lua @@ -0,0 +1,29 @@ +return { + 'rgroli/other.nvim', + lazy = false, + config = function() + require('other-nvim').setup { + mappings = { + 'golang', + { pattern = '/app/(.*)/(.*).rb', target = { { context = 'test', target = '/spec/%1/%2_spec.rb' } } }, + { pattern = '(.+)/spec/(.*)/(.*)_spec.rb', target = { { target = '%1/app/%2/%3.rb' } } }, + }, + } + end, + keys = { + { + 'to', + function() + require('other-nvim').open() + end, + mode = 'n', + }, + { + 'tO', + function() + require('other-nvim').openVSplit() + end, + mode = 'n', + }, + }, +} diff --git a/lua/custom/plugins/lazygit.lua b/lua/custom/plugins/snacks.lua similarity index 71% rename from lua/custom/plugins/lazygit.lua rename to lua/custom/plugins/snacks.lua index d4ba711d..111ddb02 100644 --- a/lua/custom/plugins/lazygit.lua +++ b/lua/custom/plugins/snacks.lua @@ -1,13 +1,14 @@ +vim.api.nvim_create_user_command('DeleteOtherBuffers', function() + require('snacks').bufdelete.other() +end, { desc = 'Delete Other Buffers' }) + return { 'folke/snacks.nvim', ---@diagnostic disable-next-line: undefined-doc-name ---@type snacks.Config opts = { - lazygit = { - -- your lazygit configuration comes here - -- or leave it empty to use the default settings - -- refer to the configuration section below - }, + lazygit = {}, + gitbrowse = {}, }, keys = { { @@ -33,5 +34,12 @@ return { }, { 'gb', 'Gitsigns blame', desc = 'Git blame' }, { 'gs', 'Telescope git_status', desc = 'Git Status' }, + { + 'go', + function() + Snacks.gitbrowse() + end, + desc = 'Git Browse', + }, }, }