-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.lua
More file actions
634 lines (574 loc) · 19.5 KB
/
init.lua
File metadata and controls
634 lines (574 loc) · 19.5 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
624
625
626
627
628
629
630
631
632
633
634
vim.opt.number = true
vim.opt.relativenumber = true
vim.g.mapleader = " "
-- Fix number column width
vim.opt.numberwidth = 4 -- Minimum number column width
vim.opt.signcolumn = "yes:1" -- Always show sign column with fixed width
-- Bootstrap packer.nvim
local ensure_packer = function()
local fn = vim.fn
local install_path = fn.stdpath('data') .. '/site/pack/packer/start/packer.nvim'
if fn.empty(fn.glob(install_path)) > 0 then
fn.system({'git', 'clone', '--depth', '1', 'https://github.com/wbthomason/packer.nvim', install_path})
vim.cmd [[packadd packer.nvim]]
return true
end
return false
end
local packer_bootstrap = ensure_packer()
-- Initialize plugins using packer.nvim
require('packer').startup(function(use)
use 'wbthomason/packer.nvim' -- Packer itself
use "rebelot/kanagawa.nvim" -- Kanagawa colorscheme
-- Basic utilities
use 'tpope/vim-sensible'
use 'nvim-lua/plenary.nvim'
-- LSP Config (language server protocol)
use 'neovim/nvim-lspconfig'
-- Status line
use 'nvim-lualine/lualine.nvim'
-- File tree
use {
'kyazdani42/nvim-tree.lua',
requires = {'kyazdani42/nvim-web-devicons'},
config = function()
require("nvim-tree").setup {
view = {
width = 30,
side = "left"
},
filters = {
dotfiles = true
},
actions = {
open_file = {
quit_on_open = false,
window_picker = {
enable = true
}
}
},
renderer = {
icons = {
show = {
file = true,
folder = true,
folder_arrow = true,
git = true
}
}
},
on_attach = function(bufnr)
local api = require('nvim-tree.api')
local function opts(desc)
return { desc = 'nvim-tree: ' .. desc, buffer = bufnr, noremap = true, silent = true, nowait = true }
end
-- Default mappings
api.config.mappings.default_on_attach(bufnr)
-- Custom mappings
vim.keymap.set('n', 'a', api.fs.create, opts('Create'))
vim.keymap.set('n', 'd', api.fs.remove, opts('Delete'))
vim.keymap.set('n', 'r', api.fs.rename, opts('Rename'))
vim.keymap.set('n', 'c', api.fs.copy.node, opts('Copy'))
vim.keymap.set('n', 'x', api.fs.cut, opts('Cut'))
vim.keymap.set('n', 'p', api.fs.paste, opts('Paste'))
vim.keymap.set('n', 'y', api.fs.copy.filename, opts('Copy Name'))
vim.keymap.set('n', 'Y', api.fs.copy.relative_path, opts('Copy Path'))
end
}
end
}
-- Syntax highlighting with Treesitter
use {
'nvim-treesitter/nvim-treesitter',
run = function()
require('nvim-treesitter.install').update({ with_sync = true })()
end
}
-- Telescope
use {
'nvim-telescope/telescope.nvim',
tag = '0.1.5',
requires = { 'nvim-lua/plenary.nvim' }
}
-- Telescope file browser extension
use { "nvim-telescope/telescope-file-browser.nvim" }
-- Autocompletion and snippets
use {
'hrsh7th/nvim-cmp',
requires = {
'hrsh7th/cmp-nvim-lsp',
'hrsh7th/cmp-buffer',
'hrsh7th/cmp-path',
'L3MON4D3/LuaSnip',
'saadparwaiz1/cmp_luasnip',
'rafamadriz/friendly-snippets'
}
}
-- LSP Kind for nice icons in completion
use {
'onsails/lspkind.nvim',
config = function()
require('lspkind').init({
mode = 'symbol_text',
maxwidth = 50,
symbol_map = {
Supermaven = "🤖"
}
})
end
}
-- Mason for easy LSP installation
use {
"williamboman/mason.nvim",
"williamboman/mason-lspconfig.nvim"
}
-- Git signs
use {
'lewis6991/gitsigns.nvim',
config = function()
require('gitsigns').setup({
signs = {
add = { text = '│' },
change = { text = '│' },
delete = { text = '_' },
topdelete = { text = '‾' },
changedelete = { text = '~' },
untracked = { text = '┆' },
},
signcolumn = true,
current_line_blame = true,
current_line_blame_opts = {
virt_text = true,
virt_text_pos = 'eol',
delay = 500,
},
on_attach = function(bufnr)
local gs = package.loaded.gitsigns
-- Navigation between hunks
vim.keymap.set('n', ']c', function()
if vim.wo.diff then return ']c' end
vim.schedule(function() gs.next_hunk() end)
return '<Ignore>'
end, {expr=true, buffer = bufnr})
vim.keymap.set('n', '[c', function()
if vim.wo.diff then return '[c' end
vim.schedule(function() gs.prev_hunk() end)
return '<Ignore>'
end, {expr=true, buffer = bufnr})
end
})
end
}
-- Multi-cursor support
use 'mg979/vim-visual-multi'
-- Auto pairs and tags
use {
"windwp/nvim-autopairs",
config = function()
require("nvim-autopairs").setup({
check_ts = true, -- Enable treesitter
ts_config = {
lua = {'string'},
javascript = {'template_string'},
java = false,
}
})
end
}
-- Auto close and rename JSX tags
use {
'windwp/nvim-ts-autotag',
config = function()
require('nvim-ts-autotag').setup({
filetypes = {
'html', 'javascript', 'typescript', 'javascriptreact',
'typescriptreact', 'svelte', 'vue', 'tsx', 'jsx', 'xml'
},
})
end
}
-- Comment toggler
use {
'numToStr/Comment.nvim',
config = function()
require('Comment').setup({
padding = true,
sticky = true,
toggler = {
line = 'gcc',
block = 'gbc',
},
opleader = {
line = 'gc',
block = 'gb',
},
})
-- Add Ctrl+/ mapping for both normal and visual mode
vim.keymap.set('n', '<C-_>', function()
require('Comment.api').toggle.linewise.current()
end, { noremap = true, silent = true })
vim.keymap.set('x', '<C-_>', function()
local esc = vim.api.nvim_replace_termcodes('<ESC>', true, false, true)
vim.api.nvim_feedkeys(esc, 'nx', false)
require('Comment.api').toggle.linewise(vim.fn.visualmode())
end, { noremap = true, silent = true })
end
}
-- Which-key for keybinding hints
use {
"folke/which-key.nvim",
config = function()
require("which-key").setup({
window = {
border = "single",
position = "bottom",
},
})
end
}
-- Highlight and navigate between matching code blocks
use {
'andymass/vim-matchup',
setup = function()
vim.g.matchup_matchparen_offscreen = { method = "popup" }
end
}
-- Supermaven AI completion
use {
"supermaven-inc/supermaven-nvim",
config = function()
require("supermaven-nvim").setup({
keymaps = {
accept_suggestion = "<Tab>",
clear_suggestion = "<C-]>",
accept_word = "<C-j>",
},
color = {
suggestion_color = "#ffffff",
cterm = 244,
},
log_level = "info",
disable_inline_completion = true, -- disable inline since we're using cmp
})
end
}
-- Prettier through null-ls
use {
"jose-elias-alvarez/null-ls.nvim",
requires = { "nvim-lua/plenary.nvim" },
config = function()
local null_ls = require("null-ls")
null_ls.setup({
sources = {
null_ls.builtins.formatting.prettier.with({
filetypes = {
"javascript",
"javascriptreact",
"typescript",
"typescriptreact",
"vue",
"css",
"scss",
"less",
"html",
"json",
"yaml",
"markdown",
"graphql"
},
}),
},
})
-- Format on save
vim.cmd([[
augroup FormatAutogroup
autocmd!
autocmd BufWritePre *.js,*.jsx,*.ts,*.tsx,*.css,*.scss,*.json,*.md lua vim.lsp.buf.format()
augroup END
]])
end
}
-- Automatically sync plugins if packer.nvim was just installed
if packer_bootstrap then
require('packer').sync()
end
end)
-- Mason Setup
require("mason").setup({
ui = {
icons = {
package_installed = "✓",
package_pending = "➜",
package_uninstalled = "✗"
}
}
})
require("mason-lspconfig").setup({
ensure_installed = {
"typescript-language-server", -- TypeScript/JavaScript
"eslint-lsp", -- ESLint
"html-lsp", -- HTML
"css-lsp", -- CSS
"json-lsp", -- JSON
},
automatic_installation = true
})
-- LSP Configuration
local lspconfig = require('lspconfig')
-- TypeScript/JavaScript
lspconfig.typescript.setup({
on_attach = function(client, bufnr)
-- Disable tsserver formatting as we will use prettier
client.server_capabilities.documentFormattingProvider = false
client.server_capabilities.documentRangeFormattingProvider = false
on_attach(client, bufnr)
end,
})
-- HTML
lspconfig.html.setup({
on_attach = on_attach
})
-- CSS
lspconfig.cssls.setup({
on_attach = on_attach
})
-- Lua
lspconfig.lua_ls.setup({
on_attach = on_attach
})
-- Indentation settings
vim.opt.expandtab = true -- Convert tabs to spaces
vim.opt.tabstop = 2 -- Number of spaces for a tab
vim.opt.shiftwidth = 2 -- Number of spaces for each indentation level
vim.opt.softtabstop = 2 -- Number of spaces for a tab in editing operations
vim.opt.smartindent = true -- Smart autoindenting on new lines
vim.opt.autoindent = true -- Copy indent from current line when starting a new line
-- File type specific indentation
vim.api.nvim_create_autocmd("FileType", {
pattern = {"javascript", "javascriptreact", "typescript", "typescriptreact"},
callback = function()
vim.bo.tabstop = 2
vim.bo.shiftwidth = 2
vim.bo.softtabstop = 2
vim.bo.expandtab = true
vim.bo.autoindent = true
vim.bo.smartindent = true
end
})
-- Folding settings
vim.opt.foldmethod = 'expr'
vim.opt.foldexpr = 'nvim_treesitter#foldexpr()'
vim.opt.foldenable = true
vim.opt.foldlevel = 99 -- Start with all folds open
-- Treesitter configuration
require('nvim-treesitter.configs').setup {
ensure_installed = {
"javascript",
"typescript",
"tsx",
"html",
"css",
"json",
"lua"
},
highlight = {
enable = true,
additional_vim_regex_highlighting = false,
},
indent = {
enable = true
},
autotag = {
enable = true,
filetypes = {
'html', 'javascript', 'typescript', 'javascriptreact',
'typescriptreact', 'svelte', 'vue', 'tsx', 'jsx', 'xml'
},
}
}
-- Set filetypes for JSX/TSX files
vim.filetype.add({
extension = {
jsx = "javascriptreact",
tsx = "typescriptreact"
}
})
-- Status line configuration
require('lualine').setup {
options = {
icons_enabled = true,
theme = 'auto',
component_separators = { left = '', right = ''},
section_separators = { left = '', right = ''},
disabled_filetypes = {
statusline = {},
winbar = {},
},
ignore_focus = {},
always_divide_middle = true,
globalstatus = false,
refresh = {
statusline = 1000,
tabline = 1000,
winbar = 1000,
}
},
sections = {
lualine_a = {'mode'},
lualine_b = {'branch', 'diff', 'diagnostics'},
lualine_c = {
{
'filename',
path = 1, -- Show relative path
file_status = true,
symbols = {
modified = ' ●',
readonly = ' ',
unnamed = '[No Name]',
}
}
},
lualine_x = {'encoding', 'fileformat', 'filetype'},
lualine_y = {'progress'},
lualine_z = {'location'}
},
inactive_sections = {
lualine_a = {},
lualine_b = {},
lualine_c = {'filename'},
lualine_x = {'location'},
lualine_y = {},
lualine_z = {}
},
tabline = {},
winbar = {},
inactive_winbar = {},
extensions = {}
}
-- Default options:
require('kanagawa').setup({
compile = false,
undercurl = true,
commentStyle = { italic = true },
functionStyle = {},
keywordStyle = { italic = true },
statementStyle = { bold = true },
typeStyle = {},
transparent = false,
dimInactive = false,
terminalColors = true,
colors = { palette = {}, theme = { wave = {}, lotus = {}, dragon = {}, all = {} } },
overrides = function(colors) return {} end,
theme = "wave",
background = { dark = "wave", light = "lotus" }
})
-- Setup must be called before loading colorscheme
vim.cmd("colorscheme kanagawa")
-- Keymap for NvimTree
vim.api.nvim_set_keymap('n', '<leader>e', ':NvimTreeToggle<CR>', { noremap = true, silent = true })
-- Basic keymaps
vim.keymap.set('n', '<leader>v', ':vsplit<CR>', { noremap = true, silent = true })
-- Window navigation
vim.keymap.set('n', '<C-h>', '<C-w>h', { noremap = true, silent = true })
vim.keymap.set('n', '<C-l>', '<C-w>l', { noremap = true, silent = true })
vim.keymap.set('n', '<C-w>', ':q<CR>', { noremap = true, silent = true })
-- Format keybinding
vim.keymap.set('n', '<leader>f', function()
vim.lsp.buf.format({ timeout_ms = 5000 })
end, { noremap = true, silent = true })
-- Telescope keymaps
local builtin = require('telescope.builtin')
vim.keymap.set('n', '<leader>ff', builtin.find_files, {})
vim.keymap.set('n', '<leader>fg', builtin.live_grep, {})
vim.keymap.set('n', '<leader>fb', builtin.buffers, {})
vim.keymap.set('n', '<leader>fh', builtin.help_tags, {})
-- Telescope setup
require('telescope').setup{
defaults = {
file_ignore_patterns = {"node_modules"},
mappings = {
i = {
["<C-j>"] = "move_selection_next",
["<C-k>"] = "move_selection_previous"
}
}
}
}
-- Additional editor settings
vim.opt.clipboard = "unnamedplus" -- Use system clipboard
vim.opt.scrolloff = 8 -- Keep 8 lines above/below cursor
vim.opt.sidescrolloff = 8 -- Keep 8 columns left/right of cursor
vim.opt.cursorline = true -- Highlight current line
vim.opt.wrap = false -- Don't wrap lines
vim.opt.mouse = "a" -- Enable mouse support
-- Copy/Paste keybindings
vim.keymap.set('v', '<C-c>', '"+y', { noremap = true, silent = true }) -- Copy in visual mode
vim.keymap.set('v', '<C-x>', '"+d', { noremap = true, silent = true }) -- Cut in visual mode
vim.keymap.set('n', '<C-v>', '"+p', { noremap = true, silent = true }) -- Paste in normal mode
vim.keymap.set('i', '<C-v>', '<C-r>+', { noremap = true, silent = true }) -- Paste in insert mode
vim.keymap.set('c', '<C-v>', '<C-r>+', { noremap = true, silent = true }) -- Paste in command mode
vim.keymap.set('v', '<C-v>', '"+P', { noremap = true, silent = true }) -- Paste in visual mode
-- Additional keymaps for better navigation
vim.keymap.set('n', '<C-d>', '<C-d>zz', { noremap = true, silent = true }) -- Keep cursor in middle when jumping
vim.keymap.set('n', '<C-u>', '<C-u>zz', { noremap = true, silent = true })
vim.keymap.set('n', 'n', 'nzzzv', { noremap = true, silent = true }) -- Keep cursor in middle when searching
vim.keymap.set('n', 'N', 'Nzzzv', { noremap = true, silent = true })
-- Completion setup
local cmp = require('cmp')
local lspkind = require('lspkind')
cmp.setup({
snippet = {
expand = function(args)
require('luasnip').lsp_expand(args.body)
end,
},
mapping = {
['<C-Space>'] = cmp.mapping.complete(),
['<CR>'] = cmp.mapping.confirm({ select = true }),
['<Tab>'] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
else
fallback()
end
end, { 'i', 's' }),
['<S-Tab>'] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
else
fallback()
end
end, { 'i', 's' }),
},
sources = cmp.config.sources({
{ name = 'supermaven' }, -- Add Supermaven as a source
{ name = 'nvim_lsp' },
{ name = 'luasnip' },
{ name = 'buffer' },
}),
formatting = {
format = lspkind.cmp_format({
mode = 'symbol_text',
maxwidth = 50,
symbol_map = {
Supermaven = "🤖"
}
})
}
})
-- Common on_attach function for LSP
local on_attach = function(client, bufnr)
-- Enable completion triggered by <c-x><c-o>
vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc')
-- LSP keybindings
local opts = { noremap = true, silent = true, buffer = bufnr }
vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts)
vim.keymap.set('n', 'gh', vim.lsp.buf.hover, opts)
vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, opts)
vim.keymap.set('n', 'gr', vim.lsp.buf.references, opts)
vim.keymap.set('n', '<leader>rn', vim.lsp.buf.rename, opts)
vim.keymap.set('n', '<leader>ca', vim.lsp.buf.code_action, opts)
vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, opts)
vim.keymap.set('n', ']d', vim.diagnostic.goto_next, opts)
end