-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.lua
More file actions
378 lines (327 loc) · 12.7 KB
/
init.lua
File metadata and controls
378 lines (327 loc) · 12.7 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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
require 'globals'
require 'custom.my.ctrl_s_shell'
require 'custom.my.opencode'
--[[
--
o====================================================================
=====================================================================
=====================================================================
======== .-----. ========
======== .----------------------. | === | ========
======== |.-""""""""""""""""""-.| |-----| ========
======== || || | === | ========
======== || KICKSTART.NVIM || |-----| ========
======== || || | === | ========
======== || || |-----| ========
======== ||:Tutor || |:::::| ========
======== |'-..................-'| |____o| ========
======== `"")----------------(""` ___________ ========
======== /::::::::::| |::::::::::\ \ no mouse \ ========
======== /:::========| |==hjkl==:::\ \ required \ ========
======== '""""""""""""' '""""""""""""' '""""""""""' ========
======== ========
=====================================================================
=====================================================================
--
--]]
-- Set <space> as the leader key
-- See `:help mapleader`
-- NOTE: Must happen before plugins are loaded (otherwise wrong leader will be used)
vim.g.mapleader = ' '
vim.g.maplocalleader = ' '
-- Disable treesitter highlighting for markdown files
-- This prevents the conceal_line / range nil value errors
-- Use FileType event with high priority to run BEFORE treesitter attaches
vim.api.nvim_create_autocmd('FileType', {
pattern = 'markdown',
callback = function(args)
-- Stop treesitter immediately
vim.treesitter.stop(args.buf)
-- Disable treesitter highlight for this buffer
vim.b[args.buf].ts_highlight = false
-- Ensure syntax is set to use regex highlighting
vim.bo[args.buf].syntax = 'markdown'
end,
})
-- GLOBAL PATCH: Wrap the highlighter's on_start to catch errors
-- This prevents the crash from propagating
local ok, highlighter = pcall(require, 'vim.treesitter.highlighter')
if ok and highlighter then
local orig_on_start = highlighter._on_start
highlighter._on_start = function(...)
local ok2, err = pcall(orig_on_start, ...)
if not ok2 then
-- Silently ignore treesitter errors
return
end
end
end
vim.o.winborder = 'rounded'
-- Set to true if you have a Nerd Font installed and selected in the terminal
vim.g.have_nerd_font = true
-- sql omnicomplet nonsense
vim.cmd [[
let g:omni_sql_no_default_maps = 1
]]
-- get file??
-- puts current file into clipboard
vim.keymap.set('n', 'gl', function()
vim.fn.setreg('+', vim.fn.expand '%')
end)
-- Enable ui2 Avoids "Press ENTER" interruptions.
require('vim._core.ui2').enable({})
-- [[ Setting options ]]
-- See `:help vim.opt`
-- NOTE: You can change these options as you wish!
-- For more options, you can see `:help option-list`
-- Relative but normal number for current line
vim.wo.relativenumber = true
vim.opt.number = true
-- You can also add relative line numbers, to help with jumping.
-- Experiment for yourself to see if you like it!
-- Enable mouse mode, can be useful for resizing splits for example!
vim.opt.mouse = 'a'
-- Don't show the mode, since it's already in the status line
vim.opt.showmode = false
-- Disbale swap files, they are annoying
vim.opt.swapfile = false
-- Enable break indent
vim.opt.breakindent = true
-- Wrap
vim.opt.wrap = false
vim.api.nvim_create_autocmd('BufEnter', {
desc = 'Turn on linewrap for markdown files',
pattern = { '*.md' },
group = vim.api.nvim_create_augroup('MarkdownWrapOn', { clear = true }),
callback = function()
vim.opt.wrap = true
end,
})
--
-- Nicer tabs
vim.opt.expandtab = true
vim.opt.shiftwidth = 2
vim.opt.tabstop = 2
vim.opt.softtabstop = 2
vim.opt.autoindent = true
-- Format options. Done with Autocmd due to another plugin overriding just setting these once here.
-- This option should work regardless of loading order
vim.api.nvim_create_autocmd('BufEnter', {
desc = 'Override buffer format options',
group = vim.api.nvim_create_augroup('override-formatoptions', { clear = true }),
callback = function()
vim.opt.formatoptions = 'jcrql'
end,
})
-- Save undo history
vim.opt.undofile = true
-- Disable command history q:
-- this makes macros and quiting slow
-- vim.keymap.set('n', 'q:', '<NOP>', { noremap = true, silent = true })
--
-- Case-insensitive searching UNLESS \C or one or more capital letters in the search term
vim.opt.ignorecase = true
vim.opt.smartcase = true
-- Keep signcolumn on by default
vim.opt.signcolumn = 'yes'
-- Decrease update time
vim.opt.updatetime = 250
-- Sets how neovim will display certain whitespace characters in the editor.
-- See `:help 'list'`
-- and `:help 'listchars'`
vim.opt.list = false
-- Preview substitutions live, as you type!
vim.opt.inccommand = 'split'
-- Show which line your cursor is on
vim.opt.cursorline = false
-- Minimal number of screen lines to keep above and below the cursor.
vim.opt.scrolloff = 10
-- if performing an operation that would fail due to unsaved changes in the buffer (like `:q`),
-- instead raise a dialog asking if you wish to save the current file(s)
-- See `:help 'confirm'`
vim.opt.confirm = false
-- Diagnostic keymaps
vim.keymap.set('n', '<leader>q', vim.diagnostic.setloclist, { desc = 'Open diagnostic [Q]uickfix list' })
-- Disable CR keybinding, strange things were happening ngl
vim.keymap.set('n', '<CR>', '<NOP>', { noremap = true, silent = true })
-- Quickfix list <CR> selection
vim.api.nvim_create_autocmd('FileType', {
pattern = 'qf',
callback = function()
vim.keymap.set('n', '<CR>', '<CR>', { buffer = true, silent = true })
end,
})
-- Quickfix will go to the first quickfix entry automatically. This may not always be a valid quickfix entry.
-- Autocmd goes over all qf entries and goes to the first valid one.
vim.api.nvim_create_autocmd('QuickFixCmdPost', {
callback = function()
local qf = vim.fn.getqflist()
for i, e in ipairs(qf) do
if e.valid ~= nil and e.valid == 1 then
local cmd = string.format('cc %d', i)
vim.cmd(cmd)
return
end
end
-- Otherwise just open quickfix list
-- vim.schedule(function() vim.cmd('copen') end)
end,
})
-- Exit terminal mode in the builtin terminal with a shortcut that is a bit easier
-- for people to discover. Otherwise, you normally need to press <C-\><C-n>, which
-- is not what someone will guess without a bit more experience.
-- NOTE: This won't work in all terminal emulators/tmux/etc. Try your own mapping
-- or just use <C-\><C-n> to exit terminal mode
vim.keymap.set('t', '<Esc><Esc>', '<C-\\><C-n>', { desc = 'Exit terminal mode' })
vim.keymap.set('t', '<C-]><C-n>', '<C-\\><C-n>', { desc = 'Exit terminal mode' })
vim.keymap.set('t', '<C-]>', '<C-\\><C-n>', { desc = 'Exit terminal mode' })
local last_buffer_cwd = nil
vim.api.nvim_create_autocmd({ "BufLeave" }, {
callback = function()
if vim.bo.buftype ~= "terminal" then
last_buffer_cwd = vim.uv.cwd()
end
end
})
vim.api.nvim_create_autocmd({ "BufEnter", "TermEnter", "TermLeave" }, {
desc = "cd to buffer cwd on enter",
callback = function()
if vim.bo.buftype == "terminal" then
-- Terminal buffer: use /proc/<pid>/cwd
if vim.b.terminal_job_pid == nil then
return
end
local cwd = vim.fn.resolve("/proc/" .. vim.b.terminal_job_pid .. "/cwd")
if vim.fn.isdirectory(cwd) == 0 then
return
end
vim.fn.chdir(cwd)
else
vim.fn.chdir(last_buffer_cwd)
end
end,
})
-- Primagen keymaps
-- Tmux sessionizer
vim.keymap.set('n', '<C-f>', '<cmd>silent !tmux neww tmux-sessionizer.sh<CR>')
vim.keymap.set('n', "<leader>x", ToggleScratch)
-- Yank to system clipboard
vim.keymap.set({ 'n', 'v' }, '<leader>y', [["+y]])
vim.keymap.set('n', '<leader>Y', 'ggVG"+y<C-O>')
-- vim.keymap.set("n", "<leader>Y", [["+Y]])
vim.keymap.set('n', '<leader>e', ':Oil<CR>')
vim.keymap.set('n', '<C-d>', '<C-d>zz')
vim.keymap.set('n', '<C-u>', '<C-u>zz')
-- Not sure I like these
-- vim.keymap.set("v", "J", ":m '>+1<CR>gv=gv")
-- vim.keymap.set("v", "K", ":m '<-2<CR>gv=gv")
-- vim.keymap.set("n", "[q", "[qzz")
-- vim.keymap.set("n", "]q", "]qzz")
vim.keymap.set('n', 'n', 'nzzzv')
vim.keymap.set('n', 'N', 'Nzzzv')
-- Paste from buffer but do not overwrite buffer with what we paste over
vim.keymap.set('x', '<leader>p', [["_dP]])
-- Diagnostic errors
-- vim.keymap.set("n", "[dzz", function() vim.diagnostic.jump({ count = 1 }) end)
-- vim.keymap.set("n", "]dzz", function() vim.diagnostic.jump({ count = -1 }) end)
-- Alternate between bufffers
-- vim.keymap.set('n', '<leader><leader>', '<C-^>', { noremap = false, silent = true })
vim.keymap.set('n', '<C-p>', '<C-^>', { noremap = false, silent = true })
-- Resizing buffers keymaps
local r = 10
vim.keymap.set('n', '<C-W>>', function()
vim.api.nvim_win_set_width(0, vim.api.nvim_win_get_width(0) + r)
end)
vim.keymap.set('n', '<C-W><', function()
vim.api.nvim_win_set_width(0, vim.api.nvim_win_get_width(0) - r)
end)
vim.api.nvim_set_keymap('c', '<C-j>', '<C-n>', { noremap = false })
vim.api.nvim_set_keymap('c', '<C-k>', '<C-p>', { noremap = false })
-- Map gf to open URLs if it's a link
vim.keymap.set('n', 'gf', OpenLink, { noremap = true, silent = true })
vim.opt.termguicolors = true
-- Highlight when yanking (copying) text
-- Try it with `yap` in normal mode
-- See `:help vim.highlight.on_yank()`
vim.api.nvim_create_autocmd('TextYankPost', {
desc = 'Highlight when yanking (copying) text',
group = vim.api.nvim_create_augroup('kickstart-highlight-yank', { clear = true }),
callback = function()
vim.highlight.on_yank()
end,
})
local oil_ex = require 'oil_filexplorer'
local ex = oil_ex:new()
-- Try to make editor more VSCodey, for ease of co-workers
-- this function can be used as a toggle using a global variable vscode
local function vs_code()
local vs_code_on = vim.g.vscode or false
if vs_code_on then
ex:kill()
ex = oil_ex:new()
vim.cmd 'se relativenumber'
-- ColourMyPencils()
vim.g.vscode = false
else
ex:up()
-- ColourMyPencils("tokionight")
vim.cmd 'se norelativenumber'
vim.g.vscode = true
end
ColourMyLines()
end
vim.api.nvim_create_user_command('VSCode', vs_code, {})
vim.keymap.set('n', '<leader>vs', vs_code, { desc = 'Toggle VSCode display with vs_code function.' })
-- [[ Install `lazy.nvim` plugin manager ]]
-- See `:help lazy.nvim.txt` or https://github.com/folke/lazy.nvim for more info
local lazypath = vim.fn.stdpath 'data' .. '/lazy/lazy.nvim'
if not (vim.uv or vim.loop).fs_stat(lazypath) then
local lazyrepo = 'https://github.com/folke/lazy.nvim.git'
local out = vim.fn.system { 'git', 'clone', '--filter=blob:none', '--branch=stable', lazyrepo, lazypath }
if vim.v.shell_error ~= 0 then
error('Error cloning lazy.nvim:\n' .. out)
end
end ---@diagnostic disable-next-line: undefined-field
vim.opt.rtp:prepend(lazypath)
-- NOTE: Here is where you install your plugins.
require('lazy').setup(
{
-- NOTE: Plugins can be added with a link (or for a github repo: 'owner/repo' link).
-- 'tpope/vim-sleuth', -- Detect tabstop and /hiftwidth automatically
-- NOTE: Plugins can also be added by using a table,
-- with the first argument being the link and the following
-- keys can be used to configure plugin behavior/loading/etc.
--
-- Use `opts = {}` to automatically pass options to a plugin's `setup()` function, forcing the plugin to be loaded.
--
-- Alternatively, use `config = function() ... end` for full control over the configuration.
-- If you prefer to call `setup` explicitly, use:
--
{
import = 'custom/plugins',
},
-- NOTE: Plugins can also be configured to run Lua code when they are loaded.
--
-- This is often very useful to both group configuration, as well as handle
-- lazy loading plugins that don't need to be loaded immediately at startup.
--
-- For example, in the following configuration, we use:
-- event = 'VimEnter'
--
-- Then, because we use the `opts` key (recommended), the configuration runs
-- after the plugin has been loaded as `require(MODULE).setup(opts)`.
-- NOTE: Plugins can specify dependencies.
--
-- The dependencies are proper plugin specifications as well - anything
-- you do for a plugin at the top level, you can do for a dependency.
--
-- Use the `dependencies` key to specify the dependencies of a particular plugin
},
-- Additional opts
{
change_detection = {
enabled = true,
notify = false,
},
}
)