summaryrefslogtreecommitdiff
path: root/.config/nvim/init.lua
blob: 5a922e31c6da99b7958b03564a5a3eb39076007f (plain) (blame)
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
vim.g.have_nerd_font = false
vim.g.mapleader = ' '
vim.g.maplocalleader = ','
vim.g.netrw_banner = 0
vim.g.netrw_bufsettings = 'noma nomod nu nobl nowrap ro'
vim.g.netrw_list_hide = [[^\(\.\|\.\.\)/\?$,^__pycache__/\?,.*\.\(a\|o\|so\|pyc\)$]]

-- NOTE: :help option-list
vim.opt.backup = false
vim.opt.breakindent = true
vim.opt.conceallevel = 2
vim.opt.cursorline = true
vim.opt.expandtab = false
vim.opt.exrc = true
vim.opt.grepprg = 'rg --vimgrep'
vim.opt.hlsearch = true
vim.opt.ignorecase = true
vim.opt.inccommand = 'split'
vim.opt.listchars = { tab = '» ', trail = '․', nbsp = '␣' }
vim.opt.list = false
vim.opt.matchpairs:append('<:>')
vim.opt.matchpairs:append('»:«')
vim.opt.matchpairs:append('‘:’')
vim.opt.matchpairs:append('“:”')
vim.opt.matchpairs:append('›:‹')
vim.opt.mouse = 'a'
vim.opt.number = true
vim.opt.relativenumber = true
vim.opt.runtimepath:append("/usr/share/vim/vimfiles")
vim.opt.runtimepath:append("/usr/share/vim/vimfiles/after")
vim.opt.scrolloff = 8
vim.opt.secure = true
vim.opt.shiftwidth = 4
vim.opt.showmode = false
vim.opt.signcolumn = 'no'
vim.opt.smartcase = true
vim.opt.smartindent = true
vim.opt.softtabstop = 4
vim.opt.splitbelow = true
vim.opt.splitright = true
vim.opt.swapfile = false
vim.opt.tabstop = 4
vim.opt.undodir = os.getenv('XDG_STATE_HOME') .. '/nvim/undo'
vim.opt.undofile = true

vim.keymap.set('n', '<C-j>', '<C-w><C-j>',
	{ desc = 'Move focus to the lower window' })
vim.keymap.set('n', '<C-k>', '<C-w><C-k>',
	{ desc = 'Move focus to the upper window' })
vim.keymap.set('n', '<C-h>', ':WinMovePrev<CR>',
	{ desc = 'Move focus to the left window', silent = true })
vim.keymap.set('n', '<C-l>', ':WinMoveNext<CR>',
	{ desc = 'Move focus to the right window', silent = true })
vim.keymap.set('n', '<Leader>h', function() vim.cmd 'split' end,
	{ desc = 'Open a [H]orizontal split' })
vim.keymap.set('n', '<Leader>v', function() vim.cmd 'vsplit' end,
	{ desc = 'Open a [V]ertical split' })
vim.keymap.set('n', 'M', ':w! | make<CR>',
	{ desc = 'Run the configured compiler', silent = true })
vim.keymap.set('x', '<C-j>', ":m '>+1<CR>gv=gv",
	{ desc = 'Move a selection down a line', silent = true })
vim.keymap.set('x', '<C-k>', ":m '<-2<CR>gv=gv",
	{ desc = 'Move a selection up a line', silent = true })
vim.keymap.set({ 'n', 'o', 'x' }, '€', '$',
	{ desc = 'Go to end of the line' })
vim.keymap.set('n', '<Esc>', ':nohlsearch<CR>',
	{ desc = 'Disable highlighting of currently highlighted search matches',
	  silent = true })
vim.keymap.set('n', '<Leader>t', function() vim.cmd.normal('"zx"zph') end,
	{ desc = '[T]ranspose the current and next characters' })
vim.keymap.set('n', '<Leader>T', function() vim.cmd.normal('"zX"zp') end,
	{ desc = '[T]ranspose the current and previous characters' })
vim.keymap.set('n', '-', ':Ex<CR>',
	{ desc = 'Open Netrw', silent = true })
vim.keymap.set('n', 'gJ', function()
	vim.cmd [[
		let save = winsaveview()
		normal! gJ
		if matchstr(getline('.'), '\%' . col('.') . 'c.') =~ '\s'
			normal! "_dw
		endif
		call winrestview(save)
	]]
end, { desc = '[J]oin lines without whitespace' })

vim.keymap.set('n', '<Leader>s', ':VScratch<CR>',
	{ desc = 'Open the scratch buffer in a vertical split' })
vim.keymap.set('n', '<Leader>S', ':Scratch<CR>',
	{ desc = 'Open the scratch buffer in a horizontal split' })

if vim.loop.os_uname().sysname ~= 'Darwin' then
	vim.keymap.set({'n', 'x'}, '<C-v>', 'V',
		{ desc = 'Enter visual-line mode' })
	vim.keymap.set({'n', 'x'}, 'V', '<C-v>',
		{ desc = 'Enter visual-block mode' })
end

-- Don’t move the cursor with various commands
vim.keymap.set('n', 'J', 'mzJ`z')
vim.keymap.set('n', '<C-d>', '<C-d>zz')
vim.keymap.set('n', '<C-u>', '<C-u>zz')
vim.keymap.set('n', 'n', 'nzzzv')
vim.keymap.set('n', 'N', 'Nzzzv')

vim.api.nvim_create_autocmd('BufEnter', {
	desc = 'Disable auto-commenting',
	group = vim.api.nvim_create_augroup('mango-no-autocomment',
		{ clear = true }),
	callback = function()
		vim.opt.formatoptions:remove({ 'c', 'r', 'o' })
	end,
})

vim.api.nvim_create_autocmd('TextYankPost', {
	desc = 'Momentarily highlight yanked text',
	group = vim.api.nvim_create_augroup('mango-highlight-yank',
		{ clear = true }),
	callback = function()
		vim.highlight.on_yank()
	end,
})

vim.api.nvim_create_autocmd('VimEnter', {
	desc = 'Remove the Vim background color',
	group = vim.api.nvim_create_augroup('mango-highlight-config',
		{ clear = true }),
	callback = function()
		vim.cmd [[
			highlight Comment               cterm=NONE gui=NONE
			highlight CursorColumn          guibg=#1D2635
			highlight CursorLine            guibg=#1D2635
			highlight EndOfBuffer           guibg=NONE
			highlight Normal                guibg=NONE
			highlight NormalNC              guibg=NONE
			highlight StatusLine            guibg=#19212E
			highlight TabLineFill           guibg=#19212E
			highlight TabLine               guibg=#131A25
			highlight TelescopeBorder       guibg=NONE
			highlight TelescopeNormal       guibg=NONE
			highlight TelescopePromptBorder guibg=NONE
			highlight TelescopePromptTitle  guibg=NONE
		]]
	end,
})

-- Weird way to make buffer auto-reverting work?
vim.cmd [[
	if !exists('g:CheckUpdateStarted')
		let g:CheckUpdatedStarted = 1
		call timer_start(1000, 'CheckUpdate', {'repeat': -1})
	endif

	function! CheckUpdate(_)
		silent! checktime
	endfunction
]]

-- Bootstrap Paq
local paqpath = vim.fn.stdpath('data') .. '/site/pack/paqs/start/paq-nvim'
if not vim.uv.fs_stat(paqpath) then
	vim.fn.system({
		'git', 'clone', '--depth=1',
		'https://github.com/savq/paq-nvim.git',
		paqpath
	})
end

require 'paq' {
	'folke/todo-comments.nvim',
	'folke/tokyonight.nvim',
	'kylechui/nvim-surround',
	'luckasRanarison/tree-sitter-hypr',
	'Mango0x45/tree-sitter-gsp',
	'ngalaiko/tree-sitter-go-template',
	'nvim-lua/plenary.nvim',
	{
		'nvim-treesitter/nvim-treesitter',
		branch = 'master',
		build = ':TSUpdate',
	},
	'nvim-treesitter/nvim-treesitter-textobjects',
	'savq/paq-nvim',
	'wellle/targets.vim',
}

-- tokyonight.nvim
vim.cmd.colorscheme 'tokyonight-night'

-- todo-comments.nvim
require('todo-comments').setup {
	signs = false,
	keywords = {
		TODO = { color = 'info' },
		NOTE = { color = 'hint' },
	},
	highlight = {
		before = '',
		keyword = 'fg',
		after = '',
	},
}

-- nvim-treesitter
local treeconfs = require('nvim-treesitter.parsers').get_parser_configs()
treeconfs.gsp = {
	install_info = {
		url = 'https://github.com/Mango0x45/tree-sitter-gsp',
		files = { 'src/parser.c' },
	},
	filetype = 'gsp',
}
treeconfs.gotmpl = {
	install_info = {
		url = 'https://github.com/ngalaiko/tree-sitter-go-template',
		files = { 'src/parser.c' },
	},
	filetype = 'gotmpl',
}

require('nvim-treesitter.install').prefer_git = true
require('nvim-treesitter.configs').setup {
	auto_install = true,
	sync_install = true,

	highlight = {
		enable = true,
		additional_vim_regex_highlighting = false,
	},

	incremental_selection = {
		enable = true,
		keymaps = {
			init_selection   = '<C-Space>',
			node_incremental = '<C-Space>',
			node_decremental = '<C-s>',
		},
	},

	textobjects = {
		select = {
			enable = true,
			lookahead = true,
			keymaps = {
				['ab'] = '@block.outer',
				['ib'] = '@block.inner',
				['ac'] = '@comment.outer',
				['ic'] = '@comment.inner',
				['af'] = '@function.outer',
				['if'] = '@function.inner',
				['an'] = '@node.outer',
				['in'] = '@node.inner',
				['at'] = '@text.outer',
				['it'] = '@text.outer',
			},
		},
		move = {
			enable = true,
			set_jumps = true,
			goto_next_start = {
				[']c'] = '@comment.outer',
				[']f'] = '@function.outer',
				[']b'] = '@block.outer',
				[']n'] = '@node.outer',
				[']t'] = '@text.outer',
			},
			goto_next_end = {
				[']C'] = '@comment.outer',
				[']F'] = '@function.outer',
				[']B'] = '@block.outer',
				[']N'] = '@node.outer',
				[']T'] = '@text.outer',
			},
			goto_previous_start = {
				['[c'] = '@comment.outer',
				['[f'] = '@function.outer',
				['[b'] = '@block.outer',
				['[n'] = '@node.outer',
				['[t'] = '@text.outer',
			},
			goto_previous_end = {
				['[C'] = '@comment.outer',
				['[F'] = '@function.outer',
				['[B'] = '@block.outer',
				['[N'] = '@node.outer',
				['[T'] = '@text.outer',
			},
		},
	},
}

-- nvim-surround
local surround_conf = require('nvim-surround.config')
require('nvim-surround').setup {
	surrounds = {
		['’'] = {
			add = { '‘', '’' },
			find = '‘[^‘’]*’',
			delete = '^(‘)().-(’)()$',
		},

		['‘'] = {
			add = { '‘ ', ' ’' },
			find = '‘[^‘’]*’',
			delete = '^(‘ *)().-( *’)()$',
		},

		['”'] = {
			add = { '“', '”' },
			find = '“[^“”]*”',
			delete = '^(“)().-(”)()$',
		},

		['“'] = {
			add = { '“ ', ' ”' },
			find = '“[^“”]*”',
			delete = '^(“ *)().-( *”)()$',
		},

		['l'] = {
			add = function()
				local result = surround_conf.get_input('Array name: ')
				if result then
					return { { result .. '[' }, { ']' } }
				end
			end,
			find = function()
				return surround_conf.get_selection({
					pattern = '[^=%s%(%){}]+%b[]'
				})
			end,
			delete = '^(.-%[)().-(%])()$',
			change = {
				target = '^.-([%w_]+)()%[.-%]()()$',
				replacement = function()
					local result = surround_conf.get_input('Array name: ')
					if result then
						return { { result }, { '' } }
					end
				end,
			},
		},
	}
}

-- Pipe
require('pipe')