-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.lua
More file actions
623 lines (533 loc) · 20.3 KB
/
init.lua
File metadata and controls
623 lines (533 loc) · 20.3 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
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
-- ▗▄▄▖ ▗▄▖ ▗▄▄▖▗▖ ▗▖▗▄▄▄▖▗▄▄▄▖ ▗▖ ▗▖▗▖ ▗▖▗▄▄▄▖▗▖ ▗▖
-- ▐▌ ▐▌▐▌ ▐▌▐▌ ▐▌▗▞▘▐▌ █ ▐▛▚▖▐▌▐▌ ▐▌ █ ▐▛▚▞▜▌
-- ▐▛▀▘ ▐▌ ▐▌▐▌ ▐▛▚▖ ▐▛▀▀▘ █ ▐▌ ▝▜▌▐▌ ▐▌ █ ▐▌ ▐▌
-- ▐▌ ▝▚▄▞▘▝▚▄▄▖▐▌ ▐▌▐▙▄▄▖ █ ▐▌ ▐▌ ▐▌ ▝▚▞▘ ▗▄█▄▖▐▌ ▐▌
--
-- github.com/ch1ebak
local o = vim.o
local opt = vim.opt
local cmd = vim.cmd
local api = vim.api
local g = vim.g
-- OPTIONS
-- Basic settings
require('vim._core.ui2').enable()
api.nvim_command('filetype plugin indent on')
o.fileencoding = "utf-8"
-- Editor settings
o.number = true -- Line numbers
o.relativenumber = true -- Relative line numbers
o.cursorline = false -- Highlight current line
o.wrap = true -- Line wrapping
o.scrolloff = 4 -- Keep n lines above/below cursor
o.sidescrolloff = 4 -- Keep n columns left/right of cursor
g.editorconfig = false
o.signcolumn = 'yes:1'
o.confirm = true
-- Completion
o.autocomplete = true
opt.wildoptions = "pum"
o.pumborder = 'rounded'
o.pummaxwidth = 40
o.completeopt = 'menu,menuone,noselect'
-- Indentation
o.tabstop = 2 -- Tab width
o.softtabstop = 2 -- Indent width
o.shiftwidth = 2 -- Soft tab stop
o.expandtab = true -- Spaces instead of tabs
o.smartindent = true -- Smart auto-indenting
o.autoindent = true -- Copy indent from current line
-- Search settings
o.ignorecase = true -- Case insensitive search
o.smartcase = true -- Case sensitive if uppercase in search
o.hlsearch = false -- Search results highlighting
o.incsearch = true -- Show matches as you type
-- Visual settings
opt.termguicolors = true -- Enable 24-bit colors
opt.showmode = false -- Mode in command line
opt.conceallevel = 0 -- Hide markup
opt.concealcursor = "nc" -- Don't hide cursor line markup
opt.guicursor = "n-v-c-sm:block,i-ci-ve:ver25,r-cr-o:hor20,a:blinkwait700-blinkoff400-blinkon250-Cursor/lCursor"
opt.winborder = "rounded"
-- File handling
opt.backup = false -- Creating backup files
opt.swapfile = false -- Creating swap files
opt.undofile = true -- Persistent undo
opt.undodir = vim.fn.expand("~/.local/share/nvim/undodir") -- Undo directory
opt.updatetime = 250 -- Faster completion
opt.timeoutlen = 500 -- Key timeout duration
opt.autoread = true -- Auto reload files changed outside vim
opt.autowrite = false -- Don't auto save
-- Behavior settings
o.hidden = true -- Hidden buffers
opt.errorbells = false -- No error bells
opt.backspace = "indent,eol,start" -- Better backspace behavior
opt.mouse = "a" -- Mouse support
opt.clipboard:append("unnamedplus") -- System clipboard
-- Splits
opt.splitright = true
opt.splitbelow = true
opt.inccommand = "split"
o.linebreak = true
opt.breakindent = true
opt.list = true
opt.listchars = { tab = "» ", trail = "·", nbsp = "␣" }
-- Spelling
-- opt.spelllang = "en,pl" -- Spellcheck languages
-- opt.spell = true -- Enable spellcheck
-- Netrw
g.netrw_keepdir = 0
g.netrw_banner = 1 -- Netrw banner
g.netrw_altv = 0 -- change from left splitting to right splitting
g.netrw_list_style = 3 -- tree style view in netrw
g.netrw_winsize = 20
g.netrw_localcopydircmd = 'cp -r'
-- Treesitter
cmd("syntax off")
vim.api.nvim_create_autocmd("FileType", {
callback = function(ev)
pcall(vim.treesitter.start, ev.buf)
end
})
-- Folding
-- o.foldenable = true
-- o.foldlevel = 99
-- o.foldmethod = "expr"
-- o.foldexpr = "v:lua.vim.treesitter.foldexpr()"
-- LSP
-- Requires harper and lua-language-server
-- Lua
vim.lsp.config['luals'] = {
cmd = { 'lua-language-server' },
filetypes = { 'lua' },
root_markers = { { '.luarc.json', '.luarc.jsonc' }, '.git' },
settings = {
Lua = {
runtime = {
version = 'LuaJIT',
}
}
}
}
-- Harper
vim.lsp.config['harper-ls'] = {
cmd = { 'harper-ls', '--stdio' },
filetypes = {
'markdown'
},
root_markers = { '.git' },
single_file_support = true,
settings = {
["harper-ls"] = {
userDictPath = "~/.config/nvim/spell/en.utf-8.add",
fileDictPath = "",
linters = {
SpellCheck = true,
SpelledNumbers = false,
AnA = true,
SentenceCapitalization = true,
UnclosedQuotes = true,
WrongQuotes = false,
LongSentences = true,
RepeatedWords = true,
Spaces = true,
Matcher = true,
CorrectNumberSuffix = true
},
codeActions = {
ForceStable = false
},
markdown = {
IgnoreLinkTitle = false
},
diagnosticSeverity = "hint",
isolateEnglish = false,
dialect = "American",
maxFileLength = 120000
},
},
}
-- Uncommented because I prefer to enable LSP using a keybinding whenever needed. Uncomment to keep it always enabled.
-- vim.lsp.enable('harper-ls', 'luals')
-- Completion
api.nvim_create_autocmd("LspAttach", {
callback = function(ev)
vim.lsp.completion.enable(true, ev.data.client_id, ev.buf, { autotrigger = false })
end,
})
vim.lsp.completion.enable()
-- Snippets
-- I don't really use snippets but have this just in case
---@param trigger string trigger string for snippet
---@param body string snippet text that will be expanded
---@param opts? vim.keymap.set.Opts
function vim.snippet.add(trigger, body, opts)
vim.keymap.set("ia", trigger, function()
-- If abbrev is expanded with keys like "(", ")", "<cr>", "<space>",
-- don't expand the snippet. Only accept "<c-]>" as a trigger key.
local c = vim.fn.nr2char(vim.fn.getchar(0))
if c ~= "" then
vim.api.nvim_feedkeys(trigger .. c, "i", true)
return
end
vim.snippet.expand(body)
end, opts)
end
-- Example
vim.snippet.add(
"fn",
"function ${1:name}($2)\n\t${3:-- content}\nend",
{ buffer = 0 }
)
vim.snippet.add(
"lfn",
"local function ${1:name}($2)\n\t${3:-- content}\nend",
{ buffer = 0 }
)
-- Highlight when yanking
api.nvim_create_autocmd("TextYankPost", {
desc = "Highlight when yanking (copying) text",
group = api.nvim_create_augroup("kickstart-highlight-yank", { clear = true }),
callback = function()
vim.highlight.on_yank()
end,
})
-- UI
-- Color Scheme
o.background = "dark"
cmd "colorscheme default"
-- Transparency
api.nvim_set_hl(0, "Normal", { bg = "none"})
api.nvim_set_hl(0, "NormalNC", { bg = "none"})
api.nvim_set_hl(0, "EndOfBuffer", { bg = "none"})
-- Tabline
opt.showtabline = 1 -- Always show tabline (0=never, 1=when multiple tabs, 2=always)
opt.tabline = '' -- Use default tabline (empty string uses built-in)
-- Transparent tabline appearance
cmd([[
hi TabLineFill guibg=NONE ctermfg=242 ctermbg=NONE
hi TabLineSel guifg=#1c1d23 guibg=#aaedb7
hi TabLine guibg=#1c1d23 guifg=#c4c6cd
]])
-- Statusline
-- Customized, based on https://nuxsh.is-a.dev/blog/custom-nvim-statusline.html
cmd "highlight StatusBG guibg=#1c1d23 guifg=#c4c6cd"
cmd "highlight StatusLineExtra guifg=#1c1d23 guibg=#aaedb7"
cmd "highlight StatusLineAccent guifg=#1c1d23 guibg=#ffc3fa"
cmd "highlight StatuslineAccent guifg=#1c1d23 guibg=#aaedb7"
cmd "highlight StatuslineInsertAccent guifg=#1c1d23 guibg=#f4d88c"
cmd "highlight StatuslineVisualAccent guifg=#1c1d23 guibg=#ffbcb5"
cmd "highlight StatuslineReplaceAccent guifg=#1c1d23 guibg=#83efef"
cmd "highlight StatuslineCmdLineAccent guifg=#1c1d23 guibg=#9fd8ff"
cmd "highlight StatuslineTerminalAccent guifg=#1c1d23 guibg=#c4c6cd"
local modes = {
["n"] = "NORMAL",
["no"] = "NORMAL",
["v"] = "VISUAL",
["V"] = "VISUAL LINE",
[""] = "VISUAL BLOCK",
["s"] = "SELECT",
["S"] = "SELECT LINE",
[""] = "SELECT BLOCK",
["i"] = "INSERT",
["ic"] = "INSERT",
["R"] = "REPLACE",
["Rv"] = "VISUAL REPLACE",
["c"] = "COMMAND",
["cv"] = "VIM EX",
["ce"] = "EX",
["r"] = "PROMPT",
["rm"] = "MOAR",
["r?"] = "CONFIRM",
["!"] = "SHELL",
["t"] = "TERMINAL",
}
local function mode()
local current_mode = vim.api.nvim_get_mode().mode
return string.format(" %s ", modes[current_mode]):upper()
end
local function update_mode_colors()
local current_mode = vim.api.nvim_get_mode().mode
local mode_color = "%#StatusLineAccent#"
if current_mode == "n" then
mode_color = "%#StatuslineAccent#"
elseif current_mode == "i" or current_mode == "ic" then
mode_color = "%#StatuslineInsertAccent#"
elseif current_mode == "v" or current_mode == "V" or current_mode == "" then
mode_color = "%#StatuslineVisualAccent#"
elseif current_mode == "R" then
mode_color = "%#StatuslineReplaceAccent#"
elseif current_mode == "c" then
mode_color = "%#StatuslineCmdLineAccent#"
elseif current_mode == "t" then
mode_color = "%#StatuslineTerminalAccent#"
end
return mode_color
end
local function filepath()
local fpath = vim.fn.fnamemodify(vim.fn.expand "%", ":~:.:h")
if fpath == "" or fpath == "." then
return " "
end
return string.format(" %%<%s/", fpath)
end
local function filename()
local fname = vim.fn.expand "%:t"
if fname == "" then
return ""
end
return fname .. " "
end
local function filetype()
local filetype = vim.opt.filetype:get()
local map = {
help = " HELP",
netrw = " NETRW",
markdown = " MARKDOWN",
org = " ORG",
text = " TEXT",
sh = " SH",
conf = " CONF",
css = " CSS",
lua = " LUA",
python = " PYTHON",
rust = " RUST",
php = " PHP",
zig = " ZIG",
typescript = " TYPESCRIPT",
typescriptreact = " TYPESCRIPT (react)",
javascript = " JAVASCRIPT",
javascriptreact = " JAVASCRIPT (react)"
}
local result = map[filetype] or string.upper(filetype)
return result
end
local function lineinfo()
if vim.bo.filetype == "alpha" then
return ""
end
return " %l:%c "
end
Statusline = {}
Statusline.active = function()
return table.concat {
"%#Statusline#",
update_mode_colors(),
mode(),
"%#StatusBG# ",
filepath(),
filename(),
"%=%#StatusLineExtra#",
filetype(),
lineinfo(),
}
end
function Statusline.inactive()
return table.concat {
"%#StatusBG# ",
filepath(),
filename(),
}
end
function Statusline.short()
return "%#StatusLineNC# NvimTree"
end
api.nvim_exec([[
augroup Statusline
au!
au WinEnter,BufEnter * setlocal statusline=%!v:lua.Statusline.active()
au WinLeave,BufLeave * setlocal statusline=%!v:lua.Statusline.inactive()
au WinEnter,BufEnter,FileType NvimTree setlocal statusline=%!v:lua.Statusline.short()
augroup END
]], false)
-- KEYMAPS
-- Settings
g.mapleader = " "
g.maplocalleader = " "
local keymap = vim.keymap
local opts = { noremap = true, silent = true }
-- Config
keymap.set("n", "<leader>hr", ":luafile %<cr>", { desc = "Reload config" }, opts)
keymap.set("n", "<leader>ht", ":colorscheme ", { desc = "Change theme" }, opts)
-- Find
keymap.set("n", "<leader><leader>", ":find ", { desc = "Find" }, opts)
keymap.set("n", "<leader>.", ":Lexplore<cr>", { desc = "Open Netrw - left split" }, opts)
keymap.set("n", "<leader>>", ":Explore<cr>", { desc = "Open Netrw" }, opts)
-- Files and folders
keymap.set("n", "<leader>fp", ":e ~/Projekty/pocket.nvim/init.lua<cr>", { desc = "Edit config" }, opts)
keymap.set("n", "<leader>fP", ":Explore ~/Projekty/pocket.nvim<cr>", { desc = "Open config folder" }, opts)
keymap.set("n", "<leader>fn", ":e ~/Dokumenty/notatki/<cr>:find ", { desc = "Find in the notes folder" }, opts)
keymap.set("n", "<leader>fN", ":Explore ~/Dokumenty/notatki<cr>", { desc = "Notes folder" }, opts)
keymap.set("n", "<leader>fg", ":e ~/Projekty/<cr>:find ", { desc = "Find in the Projects folder" }, opts)
keymap.set("n", "<leader>fN", ":Explore ~/Projekty<cr>", { desc = "Projects folder" }, opts)
-- Grep
keymap.set("n", "<leader>/", ":copen | :silent :grep ", { desc = "Grep" })
keymap.set("n", "]q", ":cnext<CR>")
keymap.set("n", "[q", ":cprev<CR>")
-- Buffers
keymap.set("n", "<leader>,", ":b ", { desc = "Buffers" }, opts)
keymap.set("n", "<leader><", ":buffers<CR>", { desc = "Buffers" }, opts)
-- Sessions
keymap.set("n", "<leader>ss", ":mksession! ~/.local/share/nvim/session/", { desc = "Save session" }, opts)
keymap.set("n", "<leader>sl", ":source ~/.local/share/nvim/session/", { desc = "Load session" }, opts)
-- Windows/Splits/Buffers
keymap.set("n", "<C-w>", ":q<CR>", { desc = "Close" }, opts)
keymap.set("n", "<C-c>", ":bdelete<CR>", { desc = "Close" }, opts)
keymap.set("n", "<C-n>", "<C-w>v", { desc = "Split window horizontally" }, opts)
keymap.set("n", "<C-h>", "<C-w>h", { desc = "Move to left window" }, opts)
keymap.set("n", "<C-l>", "<C-w>l", { desc = "Move to right window" }, opts)
keymap.set("n", "<C-t>", "<cmd>tabnew<CR>", { desc = "New tab" }, opts)
keymap.set("n", "<C-j>", "<cmd>tabn<CR>", { desc = "Next tab" }, opts)
keymap.set("n", "<C-k>", "<cmd>tabp<CR>", { desc = "Previous tab" }, opts)
-- Movement
keymap.set("n", "j", "gj", { desc = "Move by line" }, opts)
keymap.set("n", "k", "gk", { desc = "Move by line" }, opts)
keymap.set({ "n", "v" }, "gh", "^", { desc = "Go to the beginning line" })
keymap.set({ "n", "v" }, "gl", "$", { desc = "Go to the end of the line" })
keymap.set("v", "gl", "$h", { desc = "Go to the end of the line" })
keymap.set("n", "<C-d>", "<C-d>zz", { desc = "Half page down (centered)" }, opts)
keymap.set("n", "<C-u>", "<C-u>zz", { desc = "Half page up(centered)" }, opts)
-- Yanking
keymap.set("n", "Y", "y$", { desc = "Yank to end of line" })
keymap.set("n", "J", "mzJ`z", { desc = "Combine line with the one below" }, opts)
keymap.set("v", "J", ":m '>+1<CR>gv=gv", { desc = "Move selected line down" }, opts)
keymap.set("v", "K", ":m '<-2<CR>gv=gv", { desc = "Move selected line up" }, opts)
-- Search
keymap.set("n", "n", "nzzzv", { desc = "Better search next" }, opts)
keymap.set("n", "N", "Nzzzv", { desc = "Better search previous" }, opts)
-- Other
keymap.set("n", "<leader>to", "gf<cmd>!feh %<CR><cmd>e#<CR>", { desc = "Open image using feh" }, opts)
keymap.set("i", "hl", "<ESC>", { desc = "Exit insert mode" }, opts)
keymap.set("n", "yc", "yy<cmd>normal gcc<CR>p", { desc = "Uncomment and Copy" }, opts)
-- Duplicate and comment
local function duplicate_and_comment()
local esc = vim.api.nvim_replace_termcodes("<Esc>", true, false, true)
vim.api.nvim_feedkeys(esc, "x", false)
local start_line = vim.fn.line("'<")
local end_line = vim.fn.line("'>")
vim.cmd(start_line .. "," .. end_line .. "yank")
vim.cmd((end_line + 1) .. "put")
vim.api.nvim_feedkeys("gv", "n", false)
vim.api.nvim_feedkeys("gc", "v", false)
end
keymap.set("v", "yc", duplicate_and_comment, { noremap = true, desc = "Duplicate selection and comment original" })
-- Toggles
keymap.set("n", "<leader>tx", "<cmd>!chmod +x %<CR>", { desc = "Chmod open file" }, opts)
keymap.set("n", "<leader>tl", ":set wrap!<CR>", { desc = "Line wrapping" }, opts)
-- LSP
keymap.set("n", "<leader>eh", ":lua vim.lsp.enable('harper-ls')<CR>", { desc = "Enable LSP" }, opts)
keymap.set("n", "<leader>el", ":lua vim.lsp.stop_client(vim.lsp.get_clients())<CR>", { desc = "Disable LSP" }, opts)
keymap.set('n', '<leader>ew', '<cmd>lua vim.diagnostic.setloclist()<CR>', { desc = "Diagnostics - all" }, opts)
keymap.set('n', 'grh', '<cmd>lua vim.diagnostic.open_float()<CR>', { desc = "Diagnostics - at point" }, opts)
-- Spelling
keymap.set("n", "<leader>z,", function()
vim.opt.spell = true
vim.cmd("echo 'Spellcheck enabled'")
end, { desc = "Enable Spellcheck" })
keymap.set("n", "<leader>z.", function()
vim.opt.spell = false
vim.cmd("echo 'Spellcheck disabled'")
end, { desc = "Disable Spellcheck" })
keymap.set("n", "<leader>ze", function()
vim.opt.spelllang = "en"
vim.cmd("echo 'Spell language set to English'")
end, { desc = "Spelling language English" })
keymap.set("n", "<leader>zp", function()
vim.opt.spelllang = "pl"
vim.cmd("echo 'Spell language set to Polish'")
end, { desc = "Spelling language Polish" })
keymap.set("n", "<leader>zb", function()
vim.opt.spelllang = "en,pl"
vim.cmd("echo 'Spell language set to English and Polish'")
end, { desc = "[P]Spelling language English and Polish" })
keymap.set("n", "<leader>zc", function()
vim.cmd("normal! 1z=")
end, { desc = "Spelling suggestions" })
keymap.set("n", "<leader>za", function()
vim.cmd("normal! zg")
end, { desc = "Spelling add word to spellfile" })
-- Copy Full File-Path
vim.keymap.set("n", "<leader>yc", function()
local path = vim.fn.expand("%:p")
vim.fn.setreg("+", path)
print("file:", path)
end)
-- Autoclose
keymap.set("i", "(", "()<left>")
keymap.set("i", "[", "[]<left>")
keymap.set("i", "{", "{}<left>")
keymap.set("i", "<", "<><left>")
-- Focus split
keymap.set("n", "<C-o>", function()
local win = vim.api.nvim_get_current_win()
local wwidth = vim.api.nvim_win_get_width(win)
local wheight = vim.api.nvim_win_get_height(win)
local tab_width = vim.o.columns
local tab_height = vim.o.lines - vim.o.cmdheight
local focused = wwidth >= tab_width * 0.9 and wheight >= tab_height * 0.9
if focused then
vim.cmd("wincmd =") --equalize all win size
else
vim.cmd("wincmd |")
vim.cmd("wincmd _")
end
end)
-- Find
-- Pretty much copy-pasted from https://dev.to/cherryramatis/native-fuzzy-finder-in-neovim-with-lua-and-cool-bindings-1mn5
-- Requires nightly (0.12)
if vim.fn.executable "rg" == 1 then
function _G.RgFindFiles(cmdarg, _cmdcomplete)
local fnames = vim.fn.systemlist('rg --files --hidden --color=never --glob="!.git"')
if #cmdarg == 0 then
return fnames
else
return vim.fn.matchfuzzy(fnames, cmdarg)
end
end
vim.o.findfunc = 'v:lua.RgFindFiles'
end
local function is_cmdline_type_find()
local cmdline_cmd = vim.fn.split(vim.fn.getcmdline(), ' ')[1]
return cmdline_cmd == 'find' or cmdline_cmd == 'fin'
end
vim.api.nvim_create_autocmd({ 'CmdlineChanged', 'CmdlineLeave' }, {
pattern = { '*' },
group = vim.api.nvim_create_augroup('CmdlineAutocompletion', { clear = true }),
callback = function(ev)
local function should_enable_autocomplete()
local cmdline_cmd = vim.fn.split(vim.fn.getcmdline(), ' ')[1]
return is_cmdline_type_find() or cmdline_cmd == 'help' or cmdline_cmd == 'h'
end
if ev.event == 'CmdlineChanged' and should_enable_autocomplete() then
vim.opt.wildmode = 'noselect:lastused,full'
vim.fn.wildtrigger()
end
if ev.event == 'CmdlineLeave' then
vim.opt.wildmode = 'full'
end
end
})
vim.keymap.set('c', '<C-e>', '<home><s-right><c-w>edit<end>', { desc = 'Change command to :edit' })
vim.keymap.set('c', '<C-d>', function()
if not is_cmdline_type_find() then
vim.notify('This binding should be used with :find', vim.log.levels.ERROR)
return
end
local cmdline_arg = vim.fn.split(vim.fn.getcmdline(), ' ')[2]
if vim.uv.fs_realpath(vim.fn.expand(cmdline_arg)) == nil then
vim.notify('The second argument should be a valid path', vim.log.levels.ERROR)
return
end
local keys = vim.api.nvim_replace_termcodes(
'<C-U>edit ' .. vim.fs.dirname(cmdline_arg),
true,
true,
true
)
vim.fn.feedkeys(keys, 'c')
end, { desc = 'Edit the dir for the path' })
vim.keymap.set('c', '<C-n>', '<home><s-right><c-w>vs<end><CR>', { desc = 'Change command to :vs' })
vim.keymap.set('c', '<C-t>', '<home><s-right><c-w>tabe<end><CR>', { desc = 'Change command to :tabe' })
-- PLUGINS
cmd.packadd('nvim.undotree')
cmd.packadd('nvim.difftool')