Skip to content

Commit 9678e43

Browse files
Update config
1 parent de76eef commit 9678e43

File tree

9 files changed

+128
-11
lines changed

9 files changed

+128
-11
lines changed

init.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,6 +1058,7 @@ require('lazy').setup({
10581058
--
10591059
-- Uncomment the following line and add your plugins to `lua/custom/plugins/*.lua` to get going.
10601060
{ import = 'custom.plugins' },
1061+
10611062
--
10621063
-- For additional information with loading, sourcing and examples see `:help lazy.nvim-🔌-plugin-spec`
10631064
-- Or use telescope!
@@ -1085,5 +1086,8 @@ require('lazy').setup({
10851086
},
10861087
})
10871088

1089+
-- Custom configuration
1090+
require 'custom.commands'
1091+
10881092
-- The line beneath this is called `modeline`. See `:help modeline`
10891093
-- vim: ts=2 sts=2 sw=2 et

lua/custom/commands/files.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- Update file on focus if it was changed
2+
vim.api.nvim_create_autocmd({ 'FocusGained', 'BufEnter' }, { command = 'checktime' })

lua/custom/commands/init.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
require 'custom.commands.files'
2+
require 'custom.commands.quickfix'
3+
require 'custom.commands.shadafile'

lua/custom/commands/quickfix.lua

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
-- Shortcuts for quickfix
2+
3+
local function clamp(target, a, b)
4+
if target <= a then
5+
return a
6+
end
7+
if target >= b then
8+
return b
9+
end
10+
return target
11+
end
12+
13+
local function clamp_linecount(target)
14+
local count = vim.api.nvim_buf_line_count(0)
15+
return clamp(target, 1, count)
16+
end
17+
18+
vim.api.nvim_create_autocmd('BufWinEnter', {
19+
callback = function(ev)
20+
if vim.bo[ev.buf].buftype ~= 'quickfix' then
21+
return
22+
end
23+
24+
vim.keymap.set('n', 'dd', function()
25+
local cursor = vim.api.nvim_win_get_cursor(0)
26+
27+
local entries = vim.fn.getqflist()
28+
local rm_index = cursor[1]
29+
table.remove(entries, rm_index)
30+
vim.fn.setqflist(entries)
31+
32+
vim.api.nvim_win_set_cursor(0, { clamp_linecount(cursor[1]), cursor[2] })
33+
end, { buffer = ev.buf })
34+
35+
vim.keymap.set('v', 'd', function()
36+
local cursor = vim.api.nvim_win_get_cursor(0)
37+
38+
local from, to = vim.fn.line 'v', vim.fn.line '.'
39+
local qf = {}
40+
for i, v in ipairs(vim.fn.getqflist()) do
41+
if i < from or i > to then
42+
table.insert(qf, v)
43+
end
44+
end
45+
vim.fn.setqflist(qf)
46+
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes('<esc>', true, true, true), 'nv', false)
47+
48+
vim.api.nvim_win_set_cursor(0, { clamp_linecount(from), cursor[2] })
49+
end, { buffer = ev.buf })
50+
end,
51+
})

lua/custom/commands/shadafile.lua

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
-- This code configures Neovim's ShaDa file (short for Shared data) to be stored separately for each project.
2+
-- The benefit of this approach is that each project gets its own independent ShaDa file, which means:
3+
-- - Project-specific histories don't mix
4+
-- - Marks and registers are isolated per project
5+
-- - Buffer lists are maintained separately
6+
-- - Less chance of conflicts between different projects
7+
--
8+
-- For example, if you're working on two different projects:
9+
-- - Project A: `/home/user/projectA` -> Gets its own ShaDa file
10+
-- - Project B: `/home/user/projectB` -> Gets its own ShaDa file
11+
--
12+
-- This keeps the project-specific data cleanly separated instead of having all projects share the same ShaDa file.
13+
14+
vim.opt.shadafile = (function()
15+
local data = vim.fn.stdpath 'data'
16+
17+
local cwd = vim.fn.getcwd()
18+
cwd = vim.fs.root(cwd, '.git') or cwd
19+
20+
local cwd_b64 = vim.base64.encode(cwd)
21+
22+
local file = vim.fs.joinpath(data, 'project_shada', cwd_b64)
23+
vim.fn.mkdir(vim.fs.dirname(file), 'p')
24+
25+
return file
26+
end)()

lua/custom/plugins/init.lua

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@
22
-- I promise not to create any merge conflicts in this directory :)
33
--
44
-- See the kickstart.nvim README for more information
5-
vim.api.nvim_create_autocmd({ 'FocusGained', 'BufEnter' }, { command = 'checktime' })
6-
7-
vim.api.nvim_create_user_command('DeleteOtherBuffers', function()
8-
require('snacks').bufdelete.other()
9-
end, { desc = 'Delete Other Buffers' })
105

116
-- Resizing windows
127
vim.keymap.set('n', '<A-h>', '<C-w>5<', { desc = 'Decrease window width' })

lua/custom/plugins/oil.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ return {
1616
}
1717
end,
1818
keys = {
19-
-- { '=', '<cmd>Oil<cr>', mode = 'n', desc = 'Open Filesystem' },
2019
{ '-', '<cmd>Oil --float<cr>', mode = 'n', desc = 'Open Floating Filesystem' },
2120
},
2221
}

lua/custom/plugins/other.lua

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
return {
2+
'rgroli/other.nvim',
3+
lazy = false,
4+
config = function()
5+
require('other-nvim').setup {
6+
mappings = {
7+
'golang',
8+
{ pattern = '/app/(.*)/(.*).rb', target = { { context = 'test', target = '/spec/%1/%2_spec.rb' } } },
9+
{ pattern = '(.+)/spec/(.*)/(.*)_spec.rb', target = { { target = '%1/app/%2/%3.rb' } } },
10+
},
11+
}
12+
end,
13+
keys = {
14+
{
15+
'<leader>to',
16+
function()
17+
require('other-nvim').open()
18+
end,
19+
mode = 'n',
20+
},
21+
{
22+
'<leader>tO',
23+
function()
24+
require('other-nvim').openVSplit()
25+
end,
26+
mode = 'n',
27+
},
28+
},
29+
}
Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1+
vim.api.nvim_create_user_command('DeleteOtherBuffers', function()
2+
require('snacks').bufdelete.other()
3+
end, { desc = 'Delete Other Buffers' })
4+
15
return {
26
'folke/snacks.nvim',
37
---@diagnostic disable-next-line: undefined-doc-name
48
---@type snacks.Config
59
opts = {
6-
lazygit = {
7-
-- your lazygit configuration comes here
8-
-- or leave it empty to use the default settings
9-
-- refer to the configuration section below
10-
},
10+
lazygit = {},
11+
gitbrowse = {},
1112
},
1213
keys = {
1314
{
@@ -33,5 +34,12 @@ return {
3334
},
3435
{ '<leader>gb', '<cmd>Gitsigns blame<cr>', desc = 'Git blame' },
3536
{ '<leader>gs', '<cmd>Telescope git_status<CR>', desc = 'Git Status' },
37+
{
38+
'<leader>go',
39+
function()
40+
Snacks.gitbrowse()
41+
end,
42+
desc = 'Git Browse',
43+
},
3644
},
3745
}

0 commit comments

Comments
 (0)