-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.lua
More file actions
466 lines (420 loc) · 17.6 KB
/
Copy pathinit.lua
File metadata and controls
466 lines (420 loc) · 17.6 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
-- =============================================================================
-- Basic Neovim Settings
-- These are fundamental settings for Neovim's behavior and appearance.
-- =============================================================================
-- Set tabstop, shiftwidth, expandtab for consistent indentation.
-- Python typically uses 4 spaces for indentation.
vim.opt.tabstop = 4
vim.opt.shiftwidth = 4
vim.opt.expandtab = true -- Use spaces instead of tabs
-- Enable line numbers and relative line numbers for navigation.
vim.opt.number = true
vim.opt.relativenumber = true
-- Enable mouse support in all modes.
vim.opt.mouse = 'a'
-- Enable case-insensitive searching, but sensitive if uppercase is used.
vim.opt.ignorecase = true
vim.opt.smartcase = true
-- Set wrap to false to avoid wrapping long lines.
vim.opt.wrap = false
-- Set the default file encoding to UTF-8.
vim.opt.encoding = "utf-8"
vim.opt.fileencoding = "utf-8"
-- Set the leader key (often used for custom keybindings).
-- By default, it's backslash. Space is a popular alternative.
vim.g.mapleader = ' '
vim.g.maplocalleader = ' '
-- Enable persistent undo.
vim.opt.undofile = true
-- Highlight the current line.
vim.opt.cursorline = true
-- Add a scroll off value (lines around cursor when scrolling).
vim.opt.scrolloff = 8
-- Set signcolumn to 'yes' to always show the sign column for diagnostics.
vim.opt.signcolumn = 'yes'
-- =============================================================================
-- Lazy.nvim Plugin Manager Setup
-- Lazy.nvim is a fast and easy-to-use plugin manager for Neovim.
-- It automatically installs and manages plugins defined in the 'plugins' table.
-- =============================================================================
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
vim.fn.system({"git", "clone", "--filter=blob:none", "https://github.com/folke/lazy.nvim.git", lazypath})
end
vim.opt.rtp:prepend(lazypath)
-- Define the plugins to be installed and configured.
require("lazy").setup({
-- === Core Development Experience ===
{
'neovim/nvim-lspconfig', -- Collection of configurations for Neovim's built-in LSP.
dependencies = {
'williamboman/mason.nvim', -- Plugin to manage LSP servers, DAP servers, linters, and formatters.
'williamboman/mason-lspconfig.nvim', -- Bridges mason.nvim with nvim-lspconfig.
'hrsh7th/cmp-nvim-lsp', -- nvim-cmp source for Neovim's built-in LSP.
'hrsh7th/cmp-buffer', -- nvim-cmp source for words in the current buffer.
'hrsh7th/nvim-cmp', -- Auto-completion plugin for Neovim.
'L3MON4D3/LuaSnip', -- Snippet engine.
'saadparwaiz1/cmp_luasnip', -- nvim-cmp source for LuaSnip.
'rafamadriz/friendly-snippets', -- Set of useful snippets.
},
config = function()
-- LSP configuration setup (uses the native vim.lsp.config API, Neovim 0.11+)
local capabilities = require('cmp_nvim_lsp').default_capabilities()
-- Diagnostics display: inline message after the line (off by default since
-- Neovim 0.11) plus a bordered float for the full text.
vim.diagnostic.config({
virtual_text = true,
float = { border = 'rounded', source = true },
severity_sort = true,
})
-- Show the full diagnostic message for the current line in a float
vim.keymap.set('n', '<leader>d', vim.diagnostic.open_float, { desc = 'Show Line Diagnostics' })
-- Set keymaps for LSP actions whenever any LSP client attaches to a buffer
vim.api.nvim_create_autocmd('LspAttach', {
group = vim.api.nvim_create_augroup('UserLspConfig', { clear = true }),
callback = function(args)
local bufnr = args.buf
vim.bo[bufnr].omnifunc = 'v:lua.vim.lsp.omnifunc'
-- Jump keymaps go through Telescope: single result jumps directly,
-- multiple results open a fuzzy-searchable picker with previews.
local tb = require('telescope.builtin')
vim.keymap.set('n', 'gd', tb.lsp_definitions, { desc = 'Go to Definition', buffer = bufnr })
vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, { desc = 'Go to Declaration', buffer = bufnr })
vim.keymap.set('n', 'gr', tb.lsp_references, { desc = 'Show References', buffer = bufnr })
vim.keymap.set('n', 'gi', tb.lsp_implementations, { desc = 'Go to Implementation', buffer = bufnr })
vim.keymap.set('n', 'K', vim.lsp.buf.hover, { desc = 'Hover Documentation', buffer = bufnr })
vim.keymap.set('n', '<leader>rn', vim.lsp.buf.rename, { desc = 'Rename Symbol', buffer = bufnr })
vim.keymap.set('n', '<leader>ca', vim.lsp.buf.code_action, { desc = 'Code Action', buffer = bufnr })
vim.keymap.set('n', '<leader>f', function() vim.lsp.buf.format { async = true } end, { desc = 'Format Document', buffer = bufnr })
vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, { desc = 'Go to previous diagnostic', buffer = bufnr })
vim.keymap.set('n', ']d', vim.diagnostic.goto_next, { desc = 'Go to next diagnostic', buffer = bufnr })
vim.keymap.set('n', '<leader>vws', vim.lsp.buf.workspace_symbol, { desc = 'Workspace Symbols', buffer = bufnr })
end,
})
-- Setup for nvim-cmp
local cmp = require('cmp')
local luasnip = require('luasnip')
cmp.setup({
snippet = {
expand = function(args)
luasnip.lsp_expand(args.body) -- For `luasnip` users.
end,
},
window = {
completion = cmp.config.window.bordered(),
documentation = cmp.config.window.bordered(),
},
mapping = cmp.mapping.preset.insert({
['<C-b>'] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4),
['<C-Space>'] = cmp.mapping.complete(),
['<C-e>'] = cmp.mapping.abort(),
['<CR>'] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
}),
sources = cmp.config.sources({
{ name = 'nvim_lsp' }, -- LSP completion (code suggestions from language server)
{ name = 'luasnip' }, -- Snippets (e.g., 'for' expands to a for loop structure)
}, {
{ name = 'buffer' }, -- Completion from current buffer words
})
})
-- Default config applied to all LSP servers (cmp completion capabilities)
vim.lsp.config('*', {
capabilities = capabilities,
})
-- Server-specific settings (merged with nvim-lspconfig's defaults)
-- 'ruff' LSP server (linting/formatting)
vim.lsp.config('ruff', {
filetypes = { 'python' },
settings = {
args = {
'--stdin-filename', '%f',
'--fix',
'--exit-zero',
'--force-exclude',
'--isolated',
'--respect-gitignore',
'--extend-select', 'I', -- Enable auto-fixable import sorting with 'I'
},
format = {
enabled = true
},
},
})
-- 'pyright' LSP server (semantic completion, definitions)
vim.lsp.config('pyright', {
filetypes = { 'python' },
settings = {
-- You can add specific pyright settings here if needed, e.g.:
-- python = {
-- analysis = {
-- typeCheckingMode = "basic",
-- },
-- },
},
})
-- Mason setup
require('mason').setup()
-- mason-lspconfig v2: installs the servers below and automatically
-- enables every mason-installed server via vim.lsp.enable()
require('mason-lspconfig').setup({
ensure_installed = { 'ruff', 'pyright', 'lua_ls', 'omnisharp' },
})
end
},
{
'nvim-treesitter/nvim-treesitter', -- Enhanced syntax highlighting and structural editing
build = ':TSUpdate', -- Command to run after installation
config = function()
require('nvim-treesitter.configs').setup({
ensure_installed = { 'python', 'lua', 'vim', 'c_sharp' }, -- Install parsers for these languages
highlight = {
enable = true, -- Enable syntax highlighting
},
indent = {
enable = true, -- Enable indentation
},
})
end
},
{
'nvim-telescope/telescope.nvim', -- Fuzzy finder for files, buffers, etc.
tag = '0.1.x',
dependencies = {
'nvim-lua/plenary.nvim',
-- Compiled C fuzzy matcher: much faster matching and better result ranking
{
'nvim-telescope/telescope-fzf-native.nvim',
build = vim.fn.has('win32') == 1
and 'cmake -S. -Bbuild -DCMAKE_BUILD_TYPE=Release && cmake --build build --config Release'
or 'make',
},
},
config = function()
require('telescope').setup({})
require('telescope').load_extension('fzf')
local builtin = require('telescope.builtin')
vim.keymap.set('n', '<leader>ff', builtin.find_files, { desc = 'Find Files' })
vim.keymap.set('n', '<leader>fg', builtin.live_grep, { desc = 'Live Grep (search content)' })
vim.keymap.set('n', '<leader>fb', builtin.buffers, { desc = 'Find Buffers' })
vim.keymap.set('n', '<leader>fh', builtin.help_tags, { desc = 'Help Tags' })
vim.keymap.set('n', '<leader>fd', builtin.diagnostics, { desc = 'Show Diagnostics' })
-- Colorscheme switcher with live preview as you move through the list
vim.keymap.set('n', '<leader>cs', function()
builtin.colorscheme({ enable_preview = true })
end, { desc = 'Switch Colorscheme (live preview)' })
end
},
{
'nvim-tree/nvim-tree.lua', -- File explorer
dependencies = {
'nvim-tree/nvim-web-devicons', -- Required for icons
},
config = function()
require('nvim-tree').setup({
sort_by = "name", -- Corrected: Changed from 'filetime' to 'name'
view = {
width = 30,
relativenumber = true,
},
renderer = {
group_empty = true,
},
filters = {
dotfiles = false,
},
})
vim.keymap.set('n', '<leader>e', ':NvimTreeToggle<CR>', { desc = 'Toggle NvimTree' })
end
},
{
'lukas-reineke/indent-blankline.nvim', -- Indentation guides
main = 'ibl',
config = function()
require('ibl').setup({
-- For example, disable for certain filetypes
exclude = {
filetypes = {
"help", "terminal", "dashboard", "packer", "gitcommit", "NvimTree", "lazy",
},
},
})
end
},
{
'nvim-lualine/lualine.nvim', -- Status line
dependencies = { 'nvim-tree/nvim-web-devicons' },
config = function()
require('lualine').setup({
options = {
icons_enabled = true,
theme = 'auto', -- Use a theme, 'auto' tries to pick one based on your colorscheme
component_separators = { left = '', right = ''},
section_separators = { left = '', right = ''},
disabled_filetypes = {
statusline = {},
winbar = {},
},
ignore_focus = {},
always_last_line = true,
globalstatus = true, -- Show statusline always
},
sections = {
lualine_a = {'mode'},
lualine_b = {'branch', 'diff', 'diagnostics'},
lualine_c = {'filename'},
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 = {},
extensions = {}
})
end
},
{
'akinsho/toggleterm.nvim', -- Integrated terminal
version = "*",
config = function()
require("toggleterm").setup({
size = 20,
open_mapping = [[<C-t>]], -- Keybinding to open/close terminal
hide_numbers = true,
direction = 'float', -- 'float' for floating window, 'horizontal' or 'vertical'
terminal_mappings = true, -- Map normal mode commands to terminal mode
shell = vim.o.shell,
})
-- Create a Python terminal
vim.keymap.set("n", "<leader>py", "<cmd>ToggleTerm direction=float size=30<CR>", { desc = "Python Terminal" })
-- Function to execute current Python file in ToggleTerm
vim.api.nvim_create_user_command('PythonRun', function()
-- Ensure ToggleTerm is opened
vim.cmd('ToggleTerm direction=float size=30')
-- Get current file path
local file_path = vim.fn.expand('%:p')
-- Send command to the terminal
vim.cmd('ToggleTermSendCommand python ' .. vim.fn.shellescape(file_path))
end, { desc = 'Run Current Python File' })
vim.keymap.set('n', '<leader>pr', ':PythonRun<CR>', { desc = 'Run Current Python File' })
end
},
{
"lervag/vimtex",
lazy = false, -- Very important: VimTeX should not be lazy-loaded for best results
init = function()
-- VimTeX configuration goes here
-- This is where you tell it which PDF viewer to use
vim.g.vimtex_view_method = 'zathura' -- Change to 'skim' or 'general' if needed
-- This sets the 'leader' for VimTeX commands.
-- By default it is \, but many people prefer <localleader>
vim.g.vimtex_mappings_enabled = 1
vim.g.vimtex_view_skim_sync = 1
vim.g.vimtex_view_skim_activate = 1
vim.g.tex_flavor = 'latex'
vim.g.vimtex_view_method = 'skim'
vim.g.vimtex_quickfix_mode = 0
vim.g.vimtex_compiler_method = 'latexmk'
end
},
-- === Optional: Colorscheme ===
{
'ray-x/lsp_signature.nvim', -- Auto-popup function signature with current argument highlighted as you type
event = 'LspAttach',
config = function()
require('lsp_signature').setup({
hint_enable = false, -- No virtual text hint, just the floating signature window
handler_opts = { border = 'rounded' },
})
end
},
{
'lewis6991/gitsigns.nvim', -- Git change markers in the gutter, hunk preview/blame
config = function()
require('gitsigns').setup()
vim.keymap.set('n', '<leader>gp', ':Gitsigns preview_hunk<CR>', { desc = 'Preview Git Hunk' })
vim.keymap.set('n', '<leader>gb', ':Gitsigns blame_line<CR>', { desc = 'Git Blame Line' })
vim.keymap.set('n', ']h', ':Gitsigns next_hunk<CR>', { desc = 'Next Git Hunk' })
vim.keymap.set('n', '[h', ':Gitsigns prev_hunk<CR>', { desc = 'Previous Git Hunk' })
end
},
{
'mbbill/undotree', -- Visualize and navigate the undo history tree
config = function()
vim.keymap.set('n', '<leader>u', vim.cmd.UndotreeToggle, { desc = 'Toggle Undotree' })
end
},
-- A small stable of colorschemes, all loaded eagerly so they can be
-- switched on the fly (see the <leader>cs Telescope picker below).
{ 'srcery-colors/srcery-vim', lazy = false, priority = 1000 }, -- retro terminal, high color
{ 'rebelot/kanagawa.nvim', lazy = false, priority = 1000 }, -- muted ink-wash tones (try kanagawa-dragon)
{ 'sainnhe/gruvbox-material', lazy = false, priority = 1000 }, -- softer, grayer gruvbox
{ 'vague-theme/vague.nvim', lazy = false, priority = 1000 }, -- very muted, low-color minimal
{ 'slugbyte/lackluster.nvim', lazy = false, priority = 1000 }, -- grayscale, near-black bg, minimal color
}, {})
-- Default colorscheme (all themes above are loaded eagerly, so this is safe).
-- Use <leader>cs to browse and switch schemes on the fly with live preview.
local status_ok, _ = pcall(vim.cmd.colorscheme, "lackluster-night")
if not status_ok then
vim.notify("Colorscheme lackluster-night not found!", vim.log.levels.WARN)
vim.cmd.colorscheme "default"
end
-- =============================================================================
-- Autocommands (Optional but useful)
-- Automatic commands that run on certain events.
-- =============================================================================
-- Auto-resize NvimTree when window changes
vim.api.nvim_create_autocmd('VimResized', {
callback = function()
require('nvim-tree.api').view.sync()
end,
})
require("luasnip").config.set_config({
history = true,
updateevenets = "TextChanges,TextChangedI",
enable_autosnippets = true,
})
require("luasnip.loaders.from_lua").load({paths = vim.fn.stdpath("config") .. "/LuaSnip/"})
-- Ensure correct filetype for Python files (though LSP usually handles this)
vim.api.nvim_create_autocmd({'BufNewFile', 'BufRead'}, {
pattern = '*.py',
command = 'set filetype=python',
})
-- Format on save (requires an LSP capable of formatting, like ruff_lsp)
vim.api.nvim_create_autocmd('BufWritePre', {
pattern = '*.py',
callback = function()
vim.lsp.buf.format { async = true }
end,
})
-- Highlight yanked text
vim.api.nvim_create_autocmd('TextYankPost', {
group = vim.api.nvim_create_augroup('YankHighlight', { clear = true }),
callback = function()
vim.highlight.on_yank({
higroup = 'IncSearch',
timeout = 150,
})
end,
})
-- LuaSnip
require("luasnip").config.set_config({ -- Setting LuaSnip config
-- Enable autotriggered snippets
enable_autosnippets = true,
-- Use Tab (or some other key if you prefer) to trigger visual selection
store_selection_keys = "<Tab>",
})
-- https://ejmastnak.com/tutorials/vim-latex/luasnip/
vim.cmd[[
"Expand or jump in insert mode
imap <silent><expr> <Tab> luasnip#expand_or_jumpable() ? '<Plug>luasnip-expand-or-jump' : '<Tab>'
"Jump forward through tabstops in visual mode
smap <silent><expr> <Tab> luasnip#jumpable(1) ? '<Plug>luasnip-jump-next' : '<Tab>'
]]