Repository navigation
Expand file tree
/
Copy pathsnacks.lua
More file actions
183 lines (171 loc) · 5.65 KB
/
Copy pathsnacks.lua
File metadata and controls
183 lines (171 loc) · 5.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
-- Collection of QoL plugins: picker settings, terminal, toggles
if require('rafi.config').disabled('snacks') then
return
end
-- Derived from LazyVim (Apache-2.0), modified for this config:
-- https://github.com/LazyVim/LazyVim/blob/main/lua/lazyvim/plugins/extras/editor/snacks_picker.lua
-- https://github.com/LazyVim/LazyVim/blob/main/lua/lazyvim/plugins/util.lua
-- https://github.com/LazyVim/LazyVim/blob/main/lua/lazyvim/util/news.lua
-- Required: rafi.config.keymaps, rafi.util.* and many plugin files call the
-- `Snacks` global, so rafi.config ignores 'snacks' in rafi.json
-- `disabled` (see M.required). The explorer and the picker keys (with
-- vim.ui.select) are the editor.snacks-explorer and editor.snacks-picker
-- extras. Disable them to use another explorer or picker.
local root = require('rafi.util.root')
-- The ui.illuminate extra replaces Snacks.words (LSP document highlight of
-- the word under the cursor), so both don't highlight at once.
local illuminate = require('rafi.config').enabled('ui.illuminate')
-- Eager: bigfile/quickfile hook the first buffer read, and LazyVim's
-- keymaps, rafi.util.* and other plugin files use `Snacks` global.
vim.pack.add({ 'https://github.com/folke/snacks.nvim' })
-- Terminal window navigation, unless floating.
---@param dir string
local function term_nav(dir)
---@param self snacks.terminal
return function(self)
return self:is_floating() and '<c-' .. dir .. '>'
or vim.schedule(function()
vim.cmd.wincmd(dir)
end)
end
end
-- Dashboard, explorer, scroll and statuscolumn are left disabled (snacks'
-- default).
require('snacks').setup({
bigfile = { enabled = true },
image = {},
indent = { enabled = true },
input = { enabled = true },
notifier = { enabled = true },
quickfile = { enabled = true },
scope = { enabled = true },
words = { enabled = not illuminate },
toggle = {
map = function(mode, lhs, rhs, opts)
opts = opts or {}
opts.silent = opts.silent ~= false
Snacks.keymap.set(mode, lhs, rhs, opts)
end,
},
terminal = {
win = {
style = 'terminal',
wo = { winbar = '' },
-- stylua: ignore
keys = {
nav_h = { '<C-h>', term_nav('h'), desc = 'Go to Left Window', expr = true, mode = 't' },
nav_j = { '<C-j>', term_nav('j'), desc = 'Go to Lower Window', expr = true, mode = 't' },
nav_k = { '<C-k>', term_nav('k'), desc = 'Go to Upper Window', expr = true, mode = 't' },
nav_l = { '<C-l>', term_nav('l'), desc = 'Go to Right Window', expr = true, mode = 't' },
hide_slash = { '<C-/>', 'hide', desc = 'Hide Terminal', mode = 't' },
hide_underscore = { '<c-_>', 'hide', desc = 'which_key_ignore', mode = 't' },
},
},
},
zen = {
toggles = { git_signs = true },
zoom = {
show = { tabline = false },
win = { backdrop = true },
},
},
-- Settings for every snacks picker, also those other files open.
-- editor.snacks-picker turns it on, which hooks vim.ui.select.
picker = {
enabled = false,
actions = {
---@param p snacks.Picker
toggle_cwd = function(p)
local buf = p.input.filter.current_buf
local root_dir = root({ buf = buf, normalize = true })
local cwd = vim.fs.normalize(vim.uv.cwd() or '.')
p:set_cwd(p:cwd() == root_dir and cwd or root_dir)
p:find()
end,
trouble_open = function(...)
if not require('rafi.pack').has('trouble.nvim') then
vim.notify('trouble.nvim is not installed')
return false
end
vim.cmd.packadd('trouble.nvim')
local src = require('trouble.sources.snacks')
return src.actions.trouble_open.action(...)
end,
},
sources = {
files = {
hidden = true,
ignored = true,
exclude = { '.git', '.cache', '.tests', '.helm' },
},
grep = {
hidden = true,
ignored = true,
exclude = { '.git', '.cache', '.tests', '.helm' },
},
},
win = {
input = {
keys = {
['<a-c>'] = { 'toggle_cwd', mode = { 'n', 'i' } },
['<a-t>'] = { 'trouble_open', mode = { 'n', 'i' } },
['jj'] = { '<esc>', expr = true, mode = 'i' },
['s'] = false,
['sv'] = 'edit_split',
['sg'] = 'edit_vsplit',
['st'] = 'edit_tab',
['.'] = 'toggle_hidden',
[','] = 'toggle_ignored',
['e'] = 'qflist',
['E'] = 'loclist',
['K'] = 'select_and_prev',
['J'] = 'select_and_next',
['*'] = 'select_all',
['<c-l>'] = { 'preview_scroll_right', mode = { 'i', 'n' } },
['<c-h>'] = { 'preview_scroll_left', mode = { 'i', 'n' } },
},
},
list = {
keys = {
['<c-l>'] = 'preview_scroll_right',
['<c-h>'] = 'preview_scroll_left',
},
},
preview = {
keys = {
['<c-h>'] = 'focus_input',
['<c-l>'] = 'cycle_win',
},
},
},
},
})
local function news()
---@diagnostic disable-next-line: missing-fields
Snacks.win({
file = vim.api.nvim_get_runtime_file('doc/news.txt', false)[1],
border = vim.o.winborder,
width = 0.6,
height = 0.6,
wo = {
spell = false,
wrap = false,
statuscolumn = ' ',
conceallevel = 3,
},
})
end
local function map(mode, lhs, rhs, desc, opts)
opts = vim.tbl_extend('force', { desc = desc }, opts or {})
vim.keymap.set(mode, lhs, rhs, opts)
end
-- stylua: ignore start
-- Utils
map('n', '<leader>.', function() Snacks.scratch() end, 'Toggle Scratch Buffer')
map('n', '<leader>S', function() Snacks.scratch.select() end, 'Select Scratch Buffer')
map('n', '<leader>dps', function() Snacks.profiler.scratch() end, 'Profiler Scratch Buffer')
-- map('n', '<leader>n', '<cmd>messages<cr>', 'Messages (ui2 pager)')
map('n', '<leader>n', function() Snacks.picker.notifications() end, 'Notification History')
map('n', '<leader>un', function() Snacks.notifier.hide() end, 'Dismiss All Notifications')
map('n', '<leader>N', news, 'Neovim News')
-- stylua: ignore end