-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.lua
More file actions
230 lines (197 loc) · 7.25 KB
/
init.lua
File metadata and controls
230 lines (197 loc) · 7.25 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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
-- NOTE: Throughout this config, some plugins are
-- disabled by default. This is because I don't use
-- them on a daily basis, but I still want to keep
-- them around as examples.
-- You can enable them by changing `enabled = false`
-- to `enabled = true` in the respective plugin spec.
-- Some of these also have the
-- PERF: (performance) comment, which
-- indicates that I found them to slow down the config.
-- (may be outdated with newer versions of the plugins,
-- check for yourself if you're interested in using them)
require 'config.global'
require 'config.lazy'
require 'config.autocommands'
require 'utils.anki'
require 'utils.autocap'
require 'utils.spell'
require 'utils.wordcount'
require('telescope').setup {
extensions = {
zotero = {
zotero_db_path = '/Users/user/Zotero/zotero.sqlite',
better_bibtex_db_path = '/Users/user/Zotero/better-bibtex.sqlite',
zotero_storage_path = '/Users/user/Zotero/storage',
},
},
}
require('obsidian.yaml').quote_style = 'single'
vim.api.nvim_set_hl(0, 'TermCursor', { fg = '#A6E3A1', bg = '#A6E3A1' })
vim.api.nvim_set_hl(0, 'WinSeparator', { fg = 'dimgray', bg = '' })
-- Silence "Is treesitter enabled?" errors
local original_notify = vim.notify
vim.notify = function(msg, ...)
if msg == 'Error: Is treesitter enabled?' then
return
end
return original_notify(msg, ...)
end
require('leap').create_default_mappings()
vim.api.nvim_create_autocmd('FileType', {
pattern = 'oil',
callback = function()
vim.bo.syntax = 'oil'
end,
})
local notify = vim.notify
vim.notify = function(msg, ...)
if msg:match "no parser for 'oil'" then
return
end
notify(msg, ...)
end
-- Helper function to apply prefix, respecting indent, and potentially recalculate list
local function apply_list_prefix(prefix)
-- Check we are actually in a visual mode (v, V, or CTRL-V block mode)
local current_mode = vim.fn.mode()
if current_mode ~= 'v' and current_mode ~= 'V' and current_mode ~= '\x16' then -- '\x16' is CTRL-V visual block
vim.api.nvim_echo({ { 'Error: This keymap requires a visual selection.', 'ErrorMsg' } }, true, {})
return
end
-- Get visual selection line numbers using marks '< and '>
-- These work reliably for line ranges in v, V, and block modes
local _, ls, _ = unpack(vim.fn.getpos "'<")
local _, le, _ = unpack(vim.fn.getpos "'>")
-- Basic validation for the line numbers
if ls == 0 or le == 0 or le < ls then
vim.api.nvim_echo({ { 'Error: Could not determine visual selection range.', 'ErrorMsg' } }, true, {})
return
end
-- Escape only '/' and '\' for the replacement part of the substitute command
local escaped_prefix = vim.fn.escape(prefix, '/\\')
-- Construct the substitute command to respect existing indentation:
-- :s/^\s*/&PREFIX/
-- ^\s* : Match start of line (^) followed by any amount of whitespace (\s*)
-- & : In the replacement, insert the matched whitespace back
-- PREFIX: Append the desired list prefix after the original indentation
-- Lua requires escaping the backslash in the pattern: /^\\s*/
local cmd = string.format('%d,%ds/^\\s*/&%s/', ls, le, escaped_prefix)
-- Execute the substitution command
vim.api.nvim_exec(cmd, false)
-- Clear search highlighting that might be activated by the substitute command
-- This helps prevent highlighting the start of the line afterwards
vim.api.nvim_command 'nohlsearch'
-- Recalculate list using Autolist plugin, only if the command exists
if vim.fn.exists ':AutolistRecalculate' == 2 then -- 2 means Ex command exists
vim.cmd 'AutolistRecalculate'
-- You might optionally add another 'nohlsearch' here if AutolistRecalculate triggers highlighting
-- vim.api.nvim_command('nohlsearch')
end
end
-- Keybind for adding '- ' prefix (respects indent) - Works in Visual Line mode too
-- Binds to <leader>al for the primary dash version now.
-- Important: Visually select ONLY the lines you want to turn into list items.
-- Avoid selecting frontmatter (like --- sections) if you don't want bullets added there.
vim.keymap.set('x', '<leader>all', function()
apply_list_prefix '- '
end, {
noremap = true,
silent = true, -- Keeps the command itself quiet
desc = "Add '- ' list prefix (respect indent)",
})
-- Keybind for adding '1. ' prefix (respects indent) - Works in Visual Line mode too
-- Note: Your Autolist plugin likely handles the actual re-numbering.
vim.keymap.set('x', '<leader>al1', function()
apply_list_prefix '1. '
end, {
noremap = true,
silent = true,
desc = "Add '1. ' list prefix (respect indent)",
})
-- Keybind for adding task list '- [ ] ' prefix (respects indent) - Works in Visual Line mode too
vim.keymap.set('x', '<leader>alt', function()
apply_list_prefix '- [ ] '
end, {
noremap = true,
silent = true,
desc = 'Add task list prefix (respect indent)',
})
vim.keymap.del('x', 'S')
require('diagram').setup {
integrations = {
require 'diagram.integrations.markdown',
require 'diagram.integrations.neorg',
},
renderer_options = {
mermaid = {
theme = 'forest',
},
plantuml = {
charset = 'utf-8',
},
d2 = {
theme_id = 1,
},
gnuplot = {
theme = 'dark',
size = '800,600',
},
},
}
require 'utils.meetings'
require 'utils.tasks'
-- Create a global table for custom mappings
_G.my_custom_mappings = {}
-- Define text objects using surround-style operations for math delimiters
_G.my_custom_mappings.inside_math = function()
vim.cmd 'normal! T$vt$'
end
_G.my_custom_mappings.around_math = function()
vim.cmd 'normal! F$vf$'
end
-- Define the mappings in operator-pending mode 'o' and visual mode 'x'
vim.keymap.set('o', 'im', '<cmd>lua _G.my_custom_mappings.inside_math()<CR>', { noremap = true, silent = true })
vim.keymap.set('x', 'im', '<cmd>lua _G.my_custom_mappings.inside_math()<CR>', { noremap = true, silent = true })
vim.keymap.set('o', 'am', '<cmd>lua _G.my_custom_mappings.around_math()<CR>', { noremap = true, silent = true })
vim.keymap.set('x', 'am', '<cmd>lua _G.my_custom_mappings.around_math()<CR>', { noremap = true, silent = true })
require('nvim-surround').setup {
surrounds = {
['['] = {
add = function()
return { { '[[' }, { ']]' } }
end,
find = '%[%[.-%]%]',
delete = '^(%[%[)().-(%]%])()$',
},
},
}
require('do-stata').setup{}
-- Add to init.lua
local function maintain_center_padding()
local line = vim.api.nvim_win_get_cursor(0)[1]
local total_lines = vim.api.nvim_buf_line_count(0)
local win_height = vim.api.nvim_win_get_height(0)
local needed_padding = win_height -- Full window height of padding
local current_padding = total_lines - line
if current_padding < needed_padding then
local lines_to_add = needed_padding - current_padding
local padding = {}
for i = 1, lines_to_add do
table.insert(padding, "")
end
vim.api.nvim_buf_set_lines(0, -1, -1, false, padding)
end
end
vim.api.nvim_create_autocmd({"InsertEnter", "InsertLeave", "CursorMovedI"}, {
pattern = "*.md",
callback = maintain_center_padding,
})
-- Also set scrolloff for markdown
vim.api.nvim_create_autocmd("FileType", {
pattern = "markdown",
callback = function()
vim.opt_local.scrolloff = 999
end,
})
-- Prevent x-mode paste from overwriting the yank register
vim.keymap.set("x", "p", '"_dP', { noremap = true, silent = true })