summaryrefslogtreecommitdiff
path: root/nvim/init.vim
blob: 433dd2d89f395cf0717326cfb068bfa34386f076 (plain)
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
" =============================================================================
"  General Settings
" =============================================================================

" Enable syntax highlighting
syntax enable

" Use hybrid colorscheme
let g:hybrid_custom_term_colors = 1
set background=dark
colorscheme hybrid

" Set file encoding
set encoding=utf-8

" Disable swap files for performance and simplicity
set noswapfile

" Clipboard sharing
set clipboard+=unnamedplus

" Enable relative numbers
set number

" Indentation and basic text manipulation
set smartindent       " Smart indentation
set smartcase         " Case-insensitive search unless uppercase is used
set incsearch         " Show search matches as you type

" Split window behavior
set splitbelow splitright

" Wildcard completion behavior
set wildmode=longest:full,full

" Tab behavior
set tabstop=4 softtabstop=4
set shiftwidth=4
set expandtab

" Remove trailing whitespace on save
autocmd BufWritePre * %s/\s\+$//e

" Disable automatic commenting for easier commenting with plugins
autocmd FileType * setlocal formatoptions-=c formatoptions-=r formatoptions-=o

" =============================================================================
" Plugin Management (vim-plug)
" =============================================================================

call plug#begin('~/.vim/plugged')

    " Appearance and UI
    Plug 'nvim-lualine/lualine.nvim'
    "Plug 'vim-airline/vim-airline' " DEPRECATED: IN NEW VERSION, SWITCHED TO LUALINE
    "Plug 'vim-airline/vim-airline-themes'
    "Plug 'ryanoasis/vim-devicons'
    Plug 'nvim-tree/nvim-web-devicons'

    " Text manipulation
    Plug 'tpope/vim-surround'
    "Plug 'jiangmiao/auto-pairs' " Automatic parentheses and quotes etc. I don t like it tbh
    Plug 'norcalli/nvim-colorizer.lua'
    Plug 'preservim/nerdcommenter'

    " Language support
    Plug 'sheerun/vim-polyglot'

    " File explorer
    Plug 'preservim/nerdtree'

    " Git integration
    Plug 'airblade/vim-gitgutter'
    Plug 'tpope/vim-fugitive'

    " Discord presence
    Plug 'andweeb/presence.nvim'

    " Telescope for fuzzy finding
    Plug 'nvim-lua/plenary.nvim'
    Plug 'nvim-telescope/telescope.nvim'

    " Code completion and AI
    Plug 'github/copilot.vim'

    " Mason (LSP, DAP, linter, formatter manager)
    Plug 'williamboman/mason.nvim'
    Plug 'williamboman/mason-lspconfig.nvim'

    " Language server protocol (LSP)
    Plug 'neovim/nvim-lspconfig'

    " Autocompletion LSP
    Plug 'hrsh7th/nvim-cmp'
    Plug 'hrsh7th/cmp-nvim-lsp'
    Plug 'hrsh7th/cmp-buffer'
    Plug 'hrsh7th/cmp-path'
    Plug 'hrsh7th/cmp-cmdline'
    Plug 'saadparwaiz1/cmp_luasnip'

    " Snippets
    Plug 'L3MON4D3/LuaSnip'
    Plug 'rafamadriz/friendly-snippets'

    " null-ls (for linters and formatters)
    "Plug 'jose-elias-alvarez/null-ls.nvim' " DEPRECATED: after neovim 0.10
    Plug 'nvimtools/none-ls.nvim' " fork that supports neovim 0.11

    " Diagnostics UI (optional UI for LSP diagnostics)
    Plug 'j-hui/fidget.nvim'

    " Rust language tools
    Plug 'rust-lang/rust.vim'

    " Go language tools
    Plug 'fatih/vim-go', { 'do': ':GoUpdateBinaries' }

    " Latex tools
    Plug 'lervag/vimtex'

call plug#end()

" =============================================================================
" Language Specific Configurations
" =============================================================================

" [Rust.vim] Syntax checker provider
let g:syntastic_rust_checkers = ['cargo']

" ZIG Formatter autosave - disable
let g:zig_fmt_autosave = 0

" =============================================================================
" Telescope Configurations
" =============================================================================

" Find files
nnoremap <leader>f <cmd>Telescope find_files<cr>
" Live grep
nnoremap <leader>fg <cmd>Telescope live_grep<cr>
" Find open buffers
nnoremap <leader>fb <cmd>Telescope buffers<cr>
" Find help tags
nnoremap <leader>fh <cmd>Telescope help_tags<cr>

" =============================================================================
" Vimtex Configurations
" =============================================================================

let g:vimtex_view_method = 'zathura'
let g:vimtex_compiler_method = 'tectonic'
let g:vimtex_view_general_viewer = 'okular'
let g:vimtex_view_general_options = '--unique file:@pdf\#src:@line@tex'
let maplocalleader = ","

" Do not automatically open the quickfix window, if you want to open it, use ,le
let g:vimtex_quickfix_mode = 0

augroup vimtex_auto_compile
    autocmd!
    autocmd BufWritePost *.tex call vimtex#compiler#compile()
augroup END

" =============================================================================
" Discord Presence
" =============================================================================

let g:presence_neovim_image_text="The One True Text Editor"
let g:presence_main_image="file"

" =============================================================================
" Airline Configurations
" =============================================================================

" DEPRECATED: I used to use airline, but I switched to lualine for better performance and more customization options. I keep these settings here in case I want to switch back or if I want to use some of the themes or extensions that airline offers.

"let g:airline_powerline_fonts = 1
"let g:airline#extensions#tabline#enabled = 1
"let g:airline_theme='deus'

" for vimtex
"let g:airline#extensions#vimtex#enabled = 1

" Enable filetype plugins and indentation
filetype plugin indent on

" =============================================================================
" UI Settings
" =============================================================================

" Disable --INSERT-- mode display
set noshowmode

" Enable true color support for nvim-colorizer
set termguicolors

" Setup nvim-colorizer
lua require'colorizer'.setup()

" Lualine transparent background
highlight StatusLine guibg=NONE ctermbg=NONE
highlight StatusLineNC guibg=NONE ctermbg=NONE
highlight TabLineFill guibg=NONE ctermbg=NONE

" =============================================================================
" Cursor highlight line
" =============================================================================

hi CursorLine   cterm=NONE ctermbg=256
hi CursorColumn cterm=NONE ctermbg=257
nnoremap <Leader>b :set cursorline! <CR>

" =============================================================================
" Fidget Configuration
" =============================================================================

highlight FidgetTask guibg=NONE ctermbg=NONE

" =============================================================================
" Remaps
" =============================================================================

nnoremap <C-r> :%s//g<Left><Left>

" Toggle NerdTree
nnoremap <leader>\ :NERDTreeToggle<CR>
nnoremap <C-e> :NERDTreeFocus<CR>

" NERDTree setup
let NERDTreeShowHidden=1
let NERDTreeIgnore=['\.pyc$', '\~$', '\.swp$']

" Exit Vim if NERDTree is the only window left.
autocmd BufEnter * if tabpagenr('$') == 1 && winnr('$') == 1 && exists('b:NERDTree') && b:NERDTree.isTabTree() | quit | endif

" Spell check toggle
map S :setlocal spell! spelllang=en_us<CR>

" Quick save and exit
map zz :wq<CR>
map zx :q!<CR>
map zs :w<CR>

" =============================================================================
" Copilot Setup
" =============================================================================

" Disable copilot for text, markdown and latex files
autocmd FileType text let g:copilot_enabled = 0
autocmd FileType markdown let g:copilot_enabled = 0
autocmd FileType tex let g:copilot_enabled = 0

" =============================================================================
" NeoVide Setup
" =============================================================================

if exists("g:neovide")
    set guifont=Inconsolata:h8
    let g:neovide_opacity = 1
    let g:neovide_normal_opacity = 0.70
    let g:neovide_cursor_vfx_mode = "pixiedust"
endif

" =============================================================================
" LSP Setup
" =============================================================================

lua << EOF

local custom_onedark = require('lualine.themes.onedark')

for _, mode in pairs(custom_onedark) do
  if mode.c then
    mode.c.bg = 'NONE'
  end
end

require('lualine').setup {
  options = {
    theme = custom_onedark,

    icons_enabled = true,
    component_separators = { left = '', right = ''},
    section_separators = { left = '', right = ''},
    globalstatus = true,
  },

  tabline = {
    lualine_a = {'buffers'},
    lualine_b = {},
    lualine_c = {},
    lualine_x = {},
    lualine_y = {},
    lualine_z = {'tabs'}
  },

  sections = {
    lualine_c = {
      'filename',
      function()
        if vim.bo.filetype == 'tex' and vim.fn.exists('*vimtex#statusline') == 1 then
          return vim.fn['vimtex#statusline']()
        end
        return ''
      end
    }
  }
}

-- Keymap utility functions
local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(0, ...) end

-- Global settings for LSP client.
vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, {
  border = "rounded",
})

-- Keymap settings (defined in the on_attach function)
local lsp_keymaps = function(bufnr)
  buf_set_keymap("n", "gd", "<cmd>lua vim.lsp.buf.definition()<cr>", { desc = "Go to definition" })
  buf_set_keymap("n", "gD", "<cmd>lua vim.lsp.buf.declaration()<cr>", { desc = "Go to declaration" })
  buf_set_keymap("n", "K", "<cmd>lua vim.lsp.buf.hover()<cr>", { desc = "Hover information" })
  buf_set_keymap("n", "<leader>lr", "<cmd>lua vim.lsp.buf.rename()<cr>", { desc = "Rename symbol" })
  buf_set_keymap("n", "<leader>lf", "<cmd>lua vim.lsp.buf.format()<cr>", { desc = "Format document" })
  buf_set_keymap("n", "<leader>la", "<cmd>lua vim.lsp.buf.code_action()<cr>", { desc = "Code action" })
  buf_set_keymap("n", "<leader>l ", "<cmd>lua vim.diagnostic.open_float()<cr>", { desc = "Diagnostics" })
  buf_set_keymap("n", "gr", "<cmd>lua vim.lsp.buf.references()<cr>", { desc = "Show references" })
  buf_set_keymap("n", "[d", "<cmd>lua vim.diagnostic.goto_prev()<cr>", { desc = "Previous diagnostic" })
  buf_set_keymap("n", "]d", "<cmd>lua vim.diagnostic.goto_next()<cr>", { desc = "Next diagnostic" })
end

-- On attach callback to apply keymaps and custom settings
local on_attach = function(client, bufnr)
  -- Add LSP keymaps.
  lsp_keymaps(bufnr)
end

-- Mason configurations
require("mason").setup {}

require("mason-lspconfig").setup {
  -- List of servers to automatically install if they're not already installed
  ensure_installed = {
    "pyright",
    "gopls",
    "rust_analyzer",
    "clangd",
    "zls",
    "jdtls",
    "texlab",
    "rnix",

    "bashls",
    "jsonls",
    "cssls",
    "svelte",
    "asm_lsp",
    "csharp_ls",
    "neocmake",
    "ast_grep",
    "dockerls",
    "glslls",
    "graphql",
    "html",
    "htmx",
    "denols",
    "harper_ls",
    "glsl_analyzer",
    "opencl_ls",
    "prismals",
    "sqlls",
    "tinymist",
    "vimls",
    "vuels",
  },
  -- Whether servers that are set up (via lspconfig) should be automatically installed
  automatic_installation = true,
}

-- LSP server configurations
local servers = {
  pyright = {
    settings = {
      python = {
        analysis = {
          autoSearchPaths = true,
          diagnosticMode = "openFilesOnly",
          typeCheckingMode = "basic",
          useLibraryCodeForTypes = true,
        },
      },
    },
  },
  gopls = {
    settings = {
      gopls = {
        gofumpt = true,
      },
    },
  },
  rust_analyzer = {
    settings = {
      ["rust-analyzer"] = {
        checkOnSave = {
          command = "clippy",
        },
        cargo = {
          allFeatures = true,
        }
      },
    },
  },
  clangd = {
    on_attach = function(client, bufnr)
      lsp_keymaps(bufnr)
      client.server_capabilities.semanticTokensProvider = nil
    end
  },
  zls = {
    on_attach = function(client, bufnr)
      lsp_keymaps(bufnr)
      client.server_capabilities.semanticTokensProvider = nil
    end
  },
  dartls = {
    on_attach = function(client, bufnr)
      lsp_keymaps(bufnr)
      client.server_capabilities.semanticTokensProvider = nil
    end
  },
  jdtls = {
    on_attach = function(client, bufnr)
      lsp_keymaps(bufnr)
      client.server_capabilities.semanticTokensProvider = nil
    end
  },
  texlab = {
    on_attach = function(client, bufnr)
      lsp_keymaps(bufnr)
      client.server_capabilities.semanticTokensProvider = nil
    end
  },
  rnix = {
    on_attach = function(client, bufnr)
      lsp_keymaps(bufnr)
      client.server_capabilities.semanticTokensProvider = nil
    end
  },
}

local capabilities = require('cmp_nvim_lsp').default_capabilities()

for server, config in pairs(servers) do
  config = vim.tbl_deep_extend("force", {
    on_attach = on_attach,
    capabilities = capabilities,
  }, config or {})

  -- Verify if we're on Neovim 0.11+ (which has native vim.lsp.config)
  if vim.lsp.config then
    vim.lsp.config(server, config)
    vim.lsp.enable(server)
  else
    -- Fallback for Neovim 0.10
    require("lspconfig")[server].setup(config)
  end
end

-- null-ls (for formatters/linters not provided by LSP)
local null_ls = require("null-ls")

null_ls.setup({
  -- on_attach = on_attach, -- Remove on_attach from here
  sources = {
    -- Get formatters and linters from Mason
    null_ls.builtins.formatting.stylua,
    null_ls.builtins.formatting.black.with({
      extra_args = { "--fast" },
      -- Only use black if a .git or pyproject.toml is present
      condition = function(utils)
        return utils.root_has_file({".git", "pyproject.toml"})
      end,
    }),
    null_ls.builtins.formatting.isort,
    -- null_ls.builtins.diagnostics.flake8,
    null_ls.builtins.formatting.gofmt,
    null_ls.builtins.formatting.goimports,
    -- null_ls.builtins.formatting.rustfmt,
  },
})

-- cmp setup
local cmp = require 'cmp'

require("luasnip.loaders.from_vscode").lazy_load()

cmp.setup({
  snippet = {
    expand = function(args)
      require('luasnip').lsp_expand(args.body)
    end,
  },
  mapping = cmp.mapping.preset.insert({
    ['<C-d>'] = 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 }),
  }),
  sources = cmp.config.sources({
    { name = 'nvim_lsp' },
    { name = 'luasnip' },
    { name = 'buffer' },
    { name = 'path' },
  }),
})

-- Diagnostics UI (fidget.nvim)
require("fidget").setup({
    notification = {
        window = {
            winblend = 0,
        }
    }
})

local ls = require("luasnip")
local s = ls.snippet
local t = ls.text_node
local i = ls.insert_node
local fmt = require("luasnip.extras.fmt").fmt

ls.add_snippets("tex", {
  -- 1. Mediu matematic inline rapid
  -- Scrii "mk" -> devine "$ cursor $"
  s("mk", {
    t("$"), i(1), t("$"), i(0)
  }),

  -- 2. Fracții
  -- Scrii "ff" -> devine "\frac{ cursor }{ }"
  s("ff", {
    t("\\frac{"), i(1), t("}{"), i(2), t("}"), i(0)
  }),

  -- 3. Ecuație numerotată
  -- Scrii "eq" -> mediu equation
  s("eq", {
    t({"\\begin{equation}", "\t"}),
    i(1),
    t({"", "\\end{equation}"}), i(0)
  }),

  -- 4. Ecuație nenumerotată (align*)
  -- Scrii "al" -> mediu align*
  s("al", {
    t({"\\begin{align*}", "\t"}),
    i(1),
    t({"", "\\end{align*}"}), i(0)
  }),

  -- 5. Bold text
  -- Scrii "bf" -> \textbf{}
  s("bf", {
    t("\\textbf{"), i(1), t("}"), i(0)
  }),
})

EOF