-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.vim
More file actions
1758 lines (1517 loc) · 55.1 KB
/
init.vim
File metadata and controls
1758 lines (1517 loc) · 55.1 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
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
" Auto-install vim-plug if not present
let data_dir = has('nvim') ? stdpath('data') . '/site' : '~/.vim'
if empty(glob(data_dir . '/autoload/plug.vim'))
silent execute '!curl -fLo '.data_dir.'/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim'
autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
endif
call plug#begin()
" LSP Support with Mason
Plug 'williamboman/mason.nvim' " Mason
Plug 'williamboman/mason-lspconfig.nvim' " Mason LSP Config
Plug 'neovim/nvim-lspconfig' " LSP Configuration
Plug 'mfussenegger/nvim-lint' " Linting engine
Plug 'stevearc/conform.nvim' " Formatting engine
Plug 'hrsh7th/nvim-cmp' " Completion Engine
Plug 'hrsh7th/cmp-nvim-lsp' " LSP completion
Plug 'hrsh7th/cmp-buffer' " Buffer completion
Plug 'hrsh7th/cmp-cmdline' " Command line completion
Plug 'hrsh7th/cmp-path' " Path completion
" Local LLM completion
Plug 'nomnivore/ollama.nvim', { 'dependencies': ['nvim-lua/plenary.nvim'] } " Ollama AI completion
" GitHub Copilot
Plug 'github/copilot.vim' " Neovim plugin for GitHub Copilot
" Elixir Development
Plug 'elixir-editors/vim-elixir' " Vim configuration files for Elixir
" Neovim <-> IPython
Plug 'jpalardy/vim-slime'
" CSV viewer
Plug 'hat0uma/csvview.nvim' " A Neovim plugin for CSV file editing.
" Theme
Plug 'catppuccin/nvim', { 'as': 'catppuccin' } " Catppuccin theme
" Fuzzy finding and dependencies
Plug 'nvim-lua/plenary.nvim' " Plugin dependency
Plug 'nvim-tree/nvim-web-devicons' " optional for icons
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } } " optional for the 'fzf' command
Plug 'junegunn/fzf.vim' " fzf vim bindings
" Essential Plugins
Plug 'tpope/vim-surround' " Plugin for surrounding text
Plug 'tpope/vim-commentary' " Commenting plugin
Plug 'tpope/vim-repeat' " Repeat plugin
Plug 'tpope/vim-unimpaired' " Unimpaired plugin
" Git
Plug 'tpope/vim-fugitive' " Git integration
Plug 'lewis6991/gitsigns.nvim' " Git signs
Plug 'sindrets/diffview.nvim' " Easily cycling through diffs for all modified files for any git rev
" Additional Quality of Life Improvements
Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'} " Treesitter for syntax highlighting
Plug 'wellle/context.vim' " Shows the context of the currently visible buffer contents
Plug 'windwp/nvim-autopairs' " Autopairs for auto closing brackets
Plug 'lukas-reineke/indent-blankline.nvim' " Indentation lines
Plug 'wolandark/vim-piper' " Text to speech
Plug 'machakann/vim-highlightedyank' " Highlight yanked text
Plug 'iamcco/markdown-preview.nvim', { 'do': { -> mkdp#util#install() }, 'for': ['markdown', 'vim-plug']}
Plug 'preservim/tagbar' " Displays tags in a window, ordered by scope
Plug 'jakobkhansen/journal.nvim' " Keep notes
Plug 'folke/which-key.nvim' " Helps you remember your Neovim keymaps
Plug 'norcalli/nvim-colorizer.lua' " Colour preview
call plug#end()
""" Catppuccin Theme Configuration with Accessibility Improvements
lua << EOF
require("catppuccin").setup({
flavour = "mocha", -- The highest contrast variant
no_italic = false,
no_bold = false, -- Keep bold for structure
styles = {
comments = {},
conditionals = {},
loops = {},
functions = {},
keywords = {},
strings = {},
variables = {},
numbers = {},
booleans = {},
properties = {},
types = {},
},
color_overrides = {
mocha = {
base = "#000000", -- Deeper black for better contrast
text = "#FFFFFF", -- Brighter text
},
},
integrations = {
which_key = true,
treesitter = true,
mason = true,
native_lsp = {
enabled = true,
underlines = {
errors = { "underline" },
hints = { "underline" },
information = { "underline" },
warnings = { "underline" },
},
},
},
})
EOF
" Set the theme
colorscheme catppuccin
" Additional accessibility improvements
hi CursorLine guibg=#303030 ctermbg=236
hi Comment guifg=#a0a0a0 ctermfg=247
hi Visual guibg=#005f87 ctermbg=24 guifg=#ffffff ctermfg=15
hi Search guibg=#ffaf00 ctermbg=214 guifg=#000000 ctermfg=0
" Make gutter line numbers more accessible
hi LineNr guifg=#CCCCCC ctermfg=252 guibg=#1a1a1a ctermbg=234
hi CursorLineNr guifg=#FFFFFF ctermfg=15 guibg=#303030 ctermbg=236 gui=bold cterm=bold
" Make hover documentation windows more visible
hi NormalFloat guibg=#303446 guifg=#ffffff gui=NONE
""" Catppuccin Theme Configuration with Accessibility Improvements
""" Use jq for JSON formatting
" Makes :Format run `:%!jq .`
command! Format %!jq .
""" Use jq for JSON formatting
""" vim-slime configuration for IPython
let g:slime_target = "tmux"
let g:slime_default_config = {"socket_name": get(split($TMUX, ','), 0), "target_pane": ":.1"}
let g:slime_dont_ask_default = 1
let g:slime_python_ipython = 1
let g:slime_bracketed_paste = 1 " Better paste support for REPLs
let g:slime_send_as_block = 1 " Global setting for proper multi-line selection sending in all REPLs
" Language-specific settings
" Keep your existing cell navigation (works perfectly with vim-slime)
" Clear the [c and ]c mappings from gitsigns
silent! unmap [c
silent! unmap ]c
" Your existing FlashCurrentCell function (keep as-is)
function! FlashCurrentCell()
" Save current CursorLine highlight settings
let cursorline_enabled = &cursorline
let hl_cursorline = execute('highlight CursorLine')
" Enable cursorline and set to bright yellow temporarily
set cursorline
highlight CursorLine ctermbg=yellow guibg=#FFFF00
" Redraw screen to show highlight
redraw
" Wait briefly
sleep 100m
" Restore original CursorLine settings
if !cursorline_enabled
set nocursorline
else
" Parse the original highlight command to restore it
let matches = matchlist(hl_cursorline, 'xxx\s\+\(.*\)')
if len(matches) > 1
execute 'highlight CursorLine ' . matches[1]
else
" Fallback to a standard style if parsing fails
highlight CursorLine guibg=#303030 ctermbg=236
endif
endif
" Redraw again to apply restored settings
redraw
endfunction
" Function to send current cell
function! SlimeSendCell()
" Save cursor position
let save_pos = getpos('.')
" Get the appropriate cell delimiter pattern based on filetype
let cell_pattern = "^# %%" " Default for Python
" Use filetype-specific cell patterns
" Find cell boundaries using the appropriate pattern
let cell_start = search(cell_pattern, "bcnW")
let cell_end = search(cell_pattern, "nW")
if cell_start == 0
let cell_start = 1
endif
if cell_end == 0
let cell_end = line('$')
else
let cell_end = cell_end - 1
endif
" Send the cell
execute cell_start . "," . cell_end . "SlimeSend"
" Restore cursor position
call setpos('.', save_pos)
" Flash the cell
call FlashCurrentCell()
endfunction
""" vim-slime configuration
""" ollama.nvim configuration
lua << EOF
local opts = {
model = "mistral",
url = "http://127.0.0.1:11434",
serve = {
on_start = false,
command = "ollama",
args = { "serve" },
stop_command = "pkill",
stop_args = { "-SIGTERM", "ollama" },
}
}
require("ollama").setup(opts)
vim.keymap.set("i", "<C-x><C-o>", function()
require("cmp").complete({
config = {
sources = {
{ name = "ollama" },
{ name = "path"},
}
}
})
end)
EOF
""" ollama.nvim configuration
""" GitHub Copilot
" Enable Copilot for specific languages
let g:copilot_enabled = 1
let g:copilot_filetypes = {
\ "vim": v:true,
\ "python": v:true,
\ "toml": v:true,
\ "yaml": v:true,
\ "json": v:true,
\ "markdown": v:true,
\ "elixir": v:true,
\ "zig": v:true,
\ "sh": v:true,
\ "zsh": v:true,
\ "*": v:false,
\ }
let g:copilot_model = "gemini-2.5-pro"
""" GitHub Copilot
""" journal.nvim
lua << EOF
local opts = {
filetype = 'md', -- Filetype to use for new journal entries
root = '~/journal', -- Root directory for journal entries
date_format = '%d/%m/%Y', -- Date format for `:Journal <date-modifier>`
autocomplete_date_modifier = "end", -- "always"|"never"|"end". Enable date modifier autocompletion
-- Configuration for journal entries
journal = {
-- Default configuration for `:Journal <date-modifier>`
format = '%Y/%m-%B/daily/%d-%A',
template = '# %A %B %d %Y\n',
frequency = { day = 1 },
-- Nested configurations for `:Journal <type> <type> ... <date-modifier>`
entries = {
day = {
format = '%Y/%m-%B/daily/%d-%A', -- Format of the journal entry in the filesystem.
template = '# %A %B %d %Y\n', -- Optional. Template used when creating a new journal entry
frequency = { day = 1 }, -- Optional. The frequency of the journal entry. Used for `:Journal next`, `:Journal -2` etc
},
week = {
format = '%Y/%m-%B/weekly/week-%W',
template = "# Week %W %B %Y\n",
frequency = { day = 7 },
date_modifier = "monday" -- Optional. Date modifier applied before other modifier given to `:Journal`
},
month = {
format = '%Y/%m-%B/%B',
template = "# %B %Y\n",
frequency = { month = 1 }
},
year = {
format = '%Y/%Y',
template = "# %Y\n",
frequency = { year = 1 }
},
},
}
}
require("journal").setup(opts)
EOF
""" journal.nvim
" Leader Configuration
let mapleader = " "
let maplocalleader = ","
""" Basic Settings
set relativenumber
set expandtab " Use spaces instead of tabs
set tabstop=4 " Tab = 4 spaces
set shiftwidth=4 " Tab = 4 spaces
set softtabstop=4 " Number of spaces for a tab in insert mode
set autoindent " Auto indent
set smartindent " Smart autoindenting when starting a new line
set cindent " Stricter indenting rules for C-like languages
set indentexpr= " Let cindent handle indenting
set wrap " Wrap lines
set signcolumn=yes
set updatetime=300
set completeopt=menu,menuone,noselect
set colorcolumn=90 " Column indicating 90 characters
set cursorcolumn " Indentation guide
set cursorline
set ruler " Always show current position
set hlsearch " Highlight search results
set incsearch " Makes search act like search in modern browsers
set encoding=utf8 " Set utf8 as standard encoding
set ffs=unix,dos,mac " Use Unix as the standard file type
set spell " Enable spell checking
set spelllang=en_gb
set clipboard=unnamedplus " Clipboard Settings
set background=dark " Set dark background
if $COLORTERM == 'gnome-terminal'
set t_Co=256 " 256 colours
endif
set termguicolors " True colour support
""" Basic Settings
"" Highlight on hover
set updatetime=1000
augroup HighlightOnHover
autocmd!
autocmd CursorMoved * exe printf('match IncSearch /\V\<%s\>/', escape(expand('<cword>'), '/\'))
autocmd CursorHold,CursorHoldI * match none
augroup END
"" Highlight on hover
""" Statusline configuration
set laststatus=3 " Global statusline (Neovim only)
set noshowmode " Don't show mode in command line
" Mode dictionary with simpler names
let g:currentmode = {
\ 'n' : 'NORMAL',
\ 'no' : 'N·OP',
\ 'v' : 'VISUAL',
\ 'V' : 'V·LINE',
\ "\<C-V>" : 'V·BLOCK',
\ 's' : 'SELECT',
\ 'S' : 'S·LINE',
\ "\<C-S>" : 'S·BLOCK',
\ 'i' : 'INSERT',
\ 'R' : 'REPLACE',
\ 'Rv' : 'V·REPLACE',
\ 'c' : 'COMMAND',
\ 't' : 'TERMINAL'
\}
" More reliable mode function that doesn't depend on g:currentmode dictionary
function! CurrentMode()
let l:mode = mode()
return get(g:currentmode, l:mode, l:mode)
endfunction
" Simplified helper functions
function! StatusPaste()
return &paste ? 'PASTE ' : ''
endfunction
function! StatusSpell()
return &spell ? 'SPELL ' : ''
endfunction
" Cache virtual env name when it doesn't change often
let s:last_venv = ''
let s:venv_name = ''
function! StatusVenv()
if exists('$VIRTUAL_ENV')
let l:current_venv = $VIRTUAL_ENV
if s:last_venv != l:current_venv
let s:last_venv = l:current_venv
let l:venv = fnamemodify(l:current_venv, ':t')
let s:venv_name = l:venv ==# '.venv' ? fnamemodify(l:current_venv, ':h:t') : l:venv
endif
return s:venv_name
endif
let s:last_venv = ''
return ''
endfunction
" Display path in ~/project/file.ext format
function! PWDPath()
let l:full_path = expand('%:p')
let l:home = $HOME
" Replace home directory with tilde
if l:full_path =~# '^' . l:home
return '~' . l:full_path[len(l:home):]
endif
" If not under home, return the full path
return l:full_path
endfunction
" More informative git status with branch and changes
function! GitInfo()
if !exists('*FugitiveHead') || FugitiveHead() == ''
return ''
endif
let l:branch = FugitiveHead()
" Optional: Add status indicators if you have fugitive
return ' branch:' . l:branch . ' '
endfunction
" Statusline colours - simplified to use a single setup function
function! SetupStatusline()
" Define base colors
let l:fg = '#F8F8F2'
let l:bg_normal = '#005F87'
let l:bg_insert = '#AF5F00'
" Apply highlights using variables
exe 'hi StModeNormal guifg=' . l:fg . ' guibg=' . l:bg_normal . ' gui=bold'
" Define highlight groups with accessible, harmonious colours
hi StModeNormal guifg=#F8F8F2 guibg=#005F87 ctermfg=255 ctermbg=24 gui=bold " Blue
hi StModeInsert guifg=#F8F8F2 guibg=#AF5F00 ctermfg=255 ctermbg=130 gui=bold " Amber
hi StModeVisual guifg=#F8F8F2 guibg=#D70000 ctermfg=255 ctermbg=160 gui=bold " Red
hi StModeReplace guifg=#F8F8F2 guibg=#8700AF ctermfg=255 ctermbg=91 gui=bold " Purple
hi StModeCommand guifg=#F8F8F2 guibg=#005F5F ctermfg=255 ctermbg=23 gui=bold " Teal
hi StInfo guifg=#F8F8F2 guibg=#3A3A3A ctermfg=255 ctermbg=237 gui=none " Dark gray
hi StPath guifg=#F8F8F2 guibg=#005F87 ctermfg=255 ctermbg=24 gui=none " Blue
hi StGit guifg=#F8F8F2 guibg=#5F8700 ctermfg=255 ctermbg=64 gui=none " Green
hi StVenv guifg=#F8F8F2 guibg=#5F5F87 ctermfg=255 ctermbg=60 gui=none " Slate
hi StPosition guifg=#F8F8F2 guibg=#3A3A3A ctermfg=255 ctermbg=237 gui=none " Dark gray
" Update statusline with dynamically coloured mode segment
let &statusline = ''
let &statusline .= 'mode:%{%StatuslineMode()%}' " Mode with dynamic colours
let &statusline .= '%#StInfo# fmt:%{&ff} state:%{StatusPaste()}%{StatusSpell()} ' " Format and states
let &statusline .= '%#StPath# path:%{PWDPath()} ' " File path relative to home
let &statusline .= '%#StGit#%{GitInfo()}%*' " Git status
let &statusline .= '%=' " Switch sides
let &statusline .= '%#StVenv#%{StatusVenv()!=""?(" venv:(".StatusVenv().")"):""}' " Virtual env if exists
let &statusline .= '%#StPosition# Ln:%l Col:%c %p%% ' " Position info (clearer labels)
endfunction
" Dynamic mode colours function - more reliable
function! StatuslineMode()
let l:mode = mode()
" Set highlight based on mode
if l:mode =~# '\v(n|no)'
exe 'hi! link StatusLine StModeNormal'
return 'NORMAL '
elseif l:mode =~# '\v(i)'
exe 'hi! link StatusLine StModeInsert'
return 'INSERT '
elseif l:mode =~# '\v(v|V|\<C-v>)'
exe 'hi! link StatusLine StModeVisual'
return 'VISUAL '
elseif l:mode =~# '\v(R)'
exe 'hi! link StatusLine StModeReplace'
return 'REPLACE '
elseif l:mode =~# '\v(c)'
exe 'hi! link StatusLine StModeCommand'
return 'COMMAND '
else
exe 'hi! link StatusLine StModeNormal'
return ' ' . get(g:currentmode, l:mode, l:mode) . ' '
endif
endfunction
" Initialize the statusline when vim starts and ensure it updates properly
augroup StatusLineSetup
autocmd!
autocmd VimEnter,ColorScheme * call SetupStatusline()
" Only redraw on more specific events
autocmd BufEnter,WinEnter,FileType,BufWritePost,TextChanged,InsertLeave *
\ if &laststatus > 0 | redrawstatus | endif
augroup END
" Call setup immediately
call SetupStatusline()
""" Statusline Configuration
""" piper TTS
let g:piper_bin = '~/.venv/bin/piper'
let g:piper_voice = '/usr/share/piper-voices/en_GB-alba-medium.onnx'
" <space>tw = SpeakWord()
" <space>tc = SpeakCurrentLine()
" <space>tp = SpeakCurrentParagraph()
" <space>tf = SpeakCurrentFile()
" <space>tv = SpeakVisualSelection()
""" piper TTS
""" Spelling mistakes will be coloured up red.
hi SpellBad cterm=underline ctermfg=203 guifg=#ff5f5f
hi SpellLocal cterm=underline ctermfg=203 guifg=#ff5f5f
hi SpellRare cterm=underline ctermfg=203 guifg=#ff5f5f
hi SpellCap cterm=underline ctermfg=203 guifg=#ff5f5f
""" Spelling mistakes will be coloured up red.
""" tagbar
" https://github.com/preservim/tagbar/blob/d55d454bd3d5b027ebf0e8c75b8f88e4eddad8d8/doc/tagbar.txt#L512
let g:tagbar_left = 1
let g:tagbar_autoclose = 0
let g:tagbar_autofocus = 0 " If you set this option the cursor will move to the Tagbar window when it is opened
let g:tagbar_compact = 1 " 0: Show short help and blank lines between top-level scopes
" 1: Don't show the short help or the blank lines.
" 2: Don't show the short help but show the blank lines.
let g:tagbar_show_data_type = 1
let g:tagbar_show_linenumbers = 1
let g:tagbar_iconchars = ['▶', '▼'] " (default on Linux and Mac OS X)
" let g:tagbar_iconchars = ['▸', '▾']
" let g:tagbar_iconchars = ['▷', '◢']
" Zig configuration for tagbar (Exuberant Ctags)
let g:tagbar_type_zig = {
\ 'ctagstype': 'Zig',
\ 'kinds': [
\ 'f:functions',
\ 's:structs',
\ 'e:enums',
\ 'u:unions',
\ 'c:constants',
\ 'v:variables',
\ 't:tests',
\ ],
\ 'sort': 0
\ }
""" tagbar
" Autopairs Configuration
lua << EOF
require("nvim-autopairs").setup({})
EOF
" Indent Blankline Configuration
lua << EOF
require("ibl").setup()
EOF
""" Mason Configuration
lua << EOF
require("mason").setup()
require("mason-lspconfig").setup({
ensure_installed = {
"jedi_language_server", -- Python LSP
"dockerls", -- Docker
"markdown_oxide", -- Markdown
"bashls", -- Bash
"biome", -- JSON
"yamlls", -- YAML
"zls", -- Zig Language Server
"elixirls", -- Elixir Language Server
},
automatic_installation = false,
handlers = {
-- Jedi for Python LSP features (code intelligence)
jedi_language_server = function()
require('lspconfig').jedi_language_server.setup({
on_attach = on_attach,
capabilities = capabilities,
})
end,
-- Zig Language Server
zls = function()
require("lspconfig").zls.setup({
cmd = { vim.fn.expand("$HOME/.zig/zls") },
on_attach = on_attach,
capabilities = capabilities,
settings = {
zls = {
enable_build_on_save = true,
enable_autofix = true,
enable_inlay_hints = true,
inlay_hints_hide_redundant_param_names = true,
inlay_hints_hide_redundant_param_names_last_token = true,
}
}
})
end,
-- Docker Language Server
dockerls = function()
require("lspconfig").dockerls.setup({
on_attach = on_attach,
capabilities = capabilities,
cmd = { "docker-langserver", "--stdio" },
filetypes = { "Dockerfile", "dockerfile", "Containerfile", "containerfile" },
root_dir = require("lspconfig").util.root_pattern("Dockerfile", ".git"),
})
end,
-- Markdown Oxide
markdown_oxide = function()
require("lspconfig").markdown_oxide.setup({
on_attach = on_attach,
capabilities = capabilities,
filetypes = { "markdown", "markdown.mdx" },
root_dir = require("lspconfig").util.root_pattern(".git"),
})
end,
-- Bash Language Server
bashls = function()
require("lspconfig").bashls.setup({
on_attach = on_attach,
capabilities = capabilities,
filetypes = { "sh", "bash", "zsh" },
root_dir = require("lspconfig").util.root_pattern(".git"),
})
end,
-- Biome (JSON)
biome = function()
require("lspconfig").biome.setup({
on_attach = on_attach,
capabilities = capabilities,
})
end,
-- YAML Language Server
yamlls = function()
require("lspconfig").yamlls.setup({
on_attach = on_attach,
capabilities = capabilities,
})
end,
-- Elixir Language Server
elixirls = function()
require("lspconfig").elixirls.setup({
on_attach = on_attach,
capabilities = capabilities,
})
end,
}
})
EOF
""" Mason Configuration
""" Completion setup
lua << EOF
-- Completion Setup
local cmp = require("cmp")
cmp.setup({
snippet = {
-- REQUIRED - you must specify a snippet engine
expand = function(args)
-- vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users.
-- require('luasnip').lsp_expand(args.body) -- For `luasnip` users.
-- require('snippy').expand_snippet(args.body) -- For `snippy` users.
-- vim.fn["UltiSnips#Anon"](args.body) -- For `ultisnips` users.
vim.snippet.expand(args.body) -- For native neovim snippets (Neovim v0.10+)
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" },
{ name = "buffer" },
{ name = "path"},
{ name = "ollama" },
})
})
EOF
""" Completion setup
""" LSP Configuration
lua << EOF
-- Configure diagnostics once (remove duplicate config)
-- This config is moved and consolidated below with the main diagnostic config
-- Proper file type detection
vim.cmd([[
augroup python_lsp
autocmd!
autocmd FileType python lua vim.diagnostic.enable(true)
autocmd FileType python setlocal omnifunc=v:lua.vim.lsp.omnifunc
augroup END
]])
-- Add this before your LSP configurations
vim.api.nvim_create_autocmd('LspAttach', {
group = vim.api.nvim_create_augroup('UserLspConfig', {}),
callback = function(ev)
-- Enable completion triggered by <c-x><c-o>
vim.bo[ev.buf].omnifunc = 'v:lua.vim.lsp.omnifunc'
-- Buffer local mappings.
local opts = { buffer = ev.buf }
vim.keymap.set('n', 'K', function()
local winid = require('vim.lsp.util').open_floating_preview(
{'Fetching documentation...'}, 'markdown', {
border = 'rounded',
focusable = true,
})
vim.lsp.buf.hover()
end, opts)
end,
})
-- Configure signature help handler once (globally, outside on_attach)
vim.lsp.handlers['textDocument/signatureHelp'] = vim.lsp.with(
vim.lsp.handlers.signature_help, {
border = 'rounded',
close_events = { 'CursorMoved', 'BufHidden', 'InsertCharPre' },
focusable = true,
}
)
-- LSP Configuration
local capabilities = require('cmp_nvim_lsp').default_capabilities()
-- LSP Keybindings
local on_attach = function(client, bufnr)
-- Common options for most keymaps
local opts = { noremap = true, silent = true, buffer = bufnr }
-- Programming filetypes where signature help should auto-trigger
local programming_filetypes = {'python'}
-- Set up signature help auto-trigger only for programming files
if vim.tbl_contains(programming_filetypes, vim.bo.filetype) then
-- Use InsertCharPre instead of TextChangedI - fires BEFORE character insertion
vim.api.nvim_create_autocmd('InsertCharPre', {
buffer = bufnr,
callback = function()
local char = vim.v.char
if char == '(' or char == ',' then
vim.schedule(function()
pcall(vim.lsp.buf.signature_help)
end)
end
end,
})
-- Backup: CursorHoldI for when pausing inside function calls
vim.api.nvim_create_autocmd('CursorHoldI', {
buffer = bufnr,
callback = function()
local line = vim.api.nvim_get_current_line()
local col = vim.api.nvim_win_get_cursor(0)[2]
local before_cursor = col > 0 and line:sub(1, col) or ''
-- Only trigger if we're likely inside a function call
if before_cursor:match('%(') and not before_cursor:match('%)') then
pcall(vim.lsp.buf.signature_help)
end
end,
})
end
end
EOF
""" LSP Configuration
""" Linting and Formatting Configuration
lua << EOF
-- Linting Configuration
local lint = require('lint')
-- Register ty as a custom linter
lint.linters.ty = {
cmd = "ty",
stdin = false,
args = {
"--show-error-codes",
"--show-column-numbers"
},
ignore_exitcode = true,
parser = function(output, bufnr)
local diagnostics = {}
for _, line in ipairs(vim.split(output, '\n')) do
-- Parse ty output lines that look like: file.py:line:col: error: message [error-code]
local file, line, col, severity, message, code =
line:match(".-:(%d+):(%d+): (%w+): (.-) %[(.-)%]")
if line and col and message then
local severity_map = {
error = vim.diagnostic.severity.ERROR,
warning = vim.diagnostic.severity.WARN,
note = vim.diagnostic.severity.INFO,
hint = vim.diagnostic.severity.HINT
}
table.insert(diagnostics, {
lnum = tonumber(line) - 1, -- 0-indexed
col = tonumber(col) - 1, -- 0-indexed
message = message .. (code and " [" .. code .. "]" or ""),
source = "ty",
severity = severity_map[severity] or vim.diagnostic.severity.ERROR
})
end
end
return diagnostics
end
}
lint.linters_by_ft = {
python = {'ruff', 'ty'},
zig = {'zig'},
elixir = {'credo'},
}
-- Simple ruff linter that runs on actual file (not stdin) to find pyproject.toml
lint.linters.ruff = {
cmd = "ruff",
stdin = false,
args = {
"check",
"--output-format=json",
function() return vim.api.nvim_buf_get_name(0) end
},
ignore_exitcode = true,
parser = function(output, bufnr, cwd)
local ok, decoded = pcall(vim.json.decode, output)
if not ok then return {} end
local diagnostics = {}
if decoded and type(decoded) == "table" then
for _, item in ipairs(decoded) do
if item.location then
table.insert(diagnostics, {
lnum = (item.location.row or 1) - 1,
col = (item.location.column or 1) - 1,
message = item.message or "Ruff error",
severity = vim.diagnostic.severity.WARN,
source = "ruff",
code = item.code
})
end
end
end
return diagnostics
end
}
-- Credo linter for Elixir
lint.linters.credo = {
cmd = "mix",
stdin = false,
args = {
"credo",
"suggest",
"--format",
"json",
"--read-from-stdin",
function() return vim.api.nvim_buf_get_name(0) end
},
ignore_exitcode = true,
parser = function(output, bufnr, cwd)
local ok, decoded = pcall(vim.json.decode, output)
if not ok then return {} end
local diagnostics = {}
if decoded and type(decoded) == "table" and decoded.issues then
for _, issue in ipairs(decoded.issues) do
table.insert(diagnostics, {
lnum = (issue.line_no or 1) - 1,
col = (issue.column or 1) - 1,
message = issue.message or "Credo issue",
severity = vim.diagnostic.severity.WARN,
source = "credo",
code = issue.check
})
end
end
return diagnostics
end,
-- Check if Credo is available in the current Mix project
condition = function(ctx)
local handle = io.popen("mix help | grep -q credo")
if handle then
local result = handle:close()
return result == 0
end
return false
end
}
-- Simple command to show diagnostics in popup
vim.api.nvim_create_user_command("ShowDiagnostics", function()
vim.diagnostic.open_float()
end, {})
-- Function to count diagnostics and update status line
local function update_diagnostics_status()
local diagnostics = vim.diagnostic.get(0)
local error_count = 0
local warn_count = 0
local error_lines = {}
local warn_lines = {}
for _, diag in ipairs(diagnostics) do
if diag.severity == vim.diagnostic.severity.ERROR then
error_count = error_count + 1
table.insert(error_lines, diag.lnum + 1) -- +1 to convert to 1-based line numbers
elseif diag.severity == vim.diagnostic.severity.WARN then
warn_count = warn_count + 1
table.insert(warn_lines, diag.lnum + 1) -- +1 to convert to 1-based line numbers
end
end
-- Sort line numbers
table.sort(error_lines)
table.sort(warn_lines)
-- Prepare location strings (with up to 3 line numbers shown)
local error_loc = #error_lines > 0 and
" [Lines: " .. table.concat(error_lines, ",", 1, math.min(3, #error_lines)) ..
(#error_lines > 3 and "..." or "") .. "]" or ""
local warn_loc = #warn_lines > 0 and
" [Lines: " .. table.concat(warn_lines, ",", 1, math.min(3, #warn_lines)) ..
(#warn_lines > 3 and "..." or "") .. "]" or ""
-- Display diagnostic count in command line with locations
if error_count > 0 or warn_count > 0 then
local msg = string.format("Linting: %d errors%s, %d warnings%s",
error_count, error_loc, warn_count, warn_loc)
vim.api.nvim_echo({{msg, "WarningMsg"}}, false, {})
end
-- Update statusline variable
vim.g.linting_status = ""
if error_count > 0 then
vim.g.linting_status = vim.g.linting_status .. "E:" .. error_count
if #error_lines > 0 then
-- Show first error location
vim.g.linting_status = vim.g.linting_status .. "@" .. error_lines[1]
end
vim.g.linting_status = vim.g.linting_status .. " "
end
if warn_count > 0 then
vim.g.linting_status = vim.g.linting_status .. "W:" .. warn_count
if #warn_lines > 0 then
-- Show first warning location
vim.g.linting_status = vim.g.linting_status .. "@" .. warn_lines[1]
end
vim.g.linting_status = vim.g.linting_status .. " "
end
end
-- Set up linting on file save
vim.api.nvim_create_autocmd({ "BufWritePost" }, {
pattern = { "*.py", "*.zig", "*.ex", "*.exs" },