-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathvimrc
executable file
·2016 lines (1673 loc) · 79.4 KB
/
vimrc
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
" ${VIMRUNTIME}/vimrc
" owner Magnus Woldrich <m@japh.se>
" btime 2009-04-24
" mtime 2024-03-03 16:43:21
" git http://github.com/trapd00r/configs/
" irc japh@irc.libera.chat #vim #zsh #perl
" ‗‗‗‗‗‗‗‗‗‗‗‗ ‗‗‗‗‗‗‗‗‗‗‗‗‗ ‗‗‗‗ ‗‗‗‗ ‗‗‗‗
let g:loaded_matchit = 1
let g:hostname = hostname()
" ========== INIT START =================================
set nocp
filetype plugin indent on
set helpfile=$XDG_CONFIG_HOME/vim/doc/help.txt
if !has('nvim')
set all&
let &runtimepath = $VIMRUNTIME
else
let &runtimepath .= ',' . '/usr/share/nvim/runtime'
let &runtimepath .= ',' . $VIMRUNTIME
endif
call plug#begin(expand($VIMRUNTIME) . '/plugged')
Plug 'trapd00r/automkdir.vim' " create non-existing dirs when opening a new file
Plug 'trapd00r/cccp.vim' " colorcolumn at cursor position
Plug 'trapd00r/currentline.vim' " highlight the current line like a marker pen
Plug 'trapd00r/eqalignsimple.vim' " alignment magic with = and +
Plug 'trapd00r/foldsearches.vim' " fold around searches
Plug 'trapd00r/hlnext.vim' " highlight current search result
Plug 'trapd00r/neverland-vim-theme' " my colorscheme
Plug 'trapd00r/vim-scriptease' " various dev tools
Plug 'trapd00r/yankmatches.vim' " yank/delete matches from a previous search operation
Plug 'trapd00r/LS_COLORS.vim' " dircolors syntax
Plug 'arecarn/vim-fold-cycle' " cycle fold status with <cr>
Plug 'airblade/vim-gitgutter' " git diff markers, git hunks
Plug 'aymericbeaumet/vim-symlink' " let vim auto-follow symlinks, so that vim ~/.vimrc used absolute path
Plug 'github/copilot.vim' " AI, yo
Plug 'junegunn/fzf' " fuzzy...
Plug 'junegunn/fzf.vim' " ... all the things
Plug 'junegunn/rainbow_parentheses.vim' " better rainbows
Plug 'junegunn/vim-plug' " self
Plug 'preservim/tagbar' " tagbar for ctags
Plug 'kien/ctrlp.vim' " I don't use this but ctrlp-funky depends on it
Plug 'kshenoy/vim-signature' " place, toggle, display marks
Plug 'lfv89/vim-interestingwords' " adds ability to highlight specific words
Plug 'machakann/vim-highlightedundo' " highlight undo operations
Plug 'machakann/vim-highlightedyank' " highlight regular yank operations
Plug 'markonm/traces.vim' " live preview of ex commands like :%s
Plug 'pseewald/vim-anyfold' " fold around anything
Plug 'rhysd/clever-f.vim' " keep smashing f
Plug 'rhysd/committia.vim' " better experience dealing with commit msg
Plug 'tacahiroy/ctrlp-funky' " function navigator
Plug 'tpope/vim-fugitive' " git wrapper
Plug 'tpope/vim-repeat' " repeat all the things
Plug 'vim-scripts/AnsiEsc.vim' " highlight strings with esc seq in its color
Plug 'wookayin/fzf-ripgrep.vim' " grep -> fuzzyfind results
Plug 'chrisbra/Colorizer' " colorize hex codes etc
Plug 'andymass/vim-matchup' " % for all the things
Plug 'rhysd/git-messenger.vim' " git blame in a popup
Plug 'ConradIrwin/vim-bracketed-paste' " paste without breaking indentation
Plug 'tpope/vim-dadbod' " database access
Plug 'kristijanhusak/vim-dadbod-ui' " database access ui
Plug 'kristijanhusak/vim-dadbod-completion' " completion for above
Plug 'lifepillar/vim-colortemplate' " colorscheme toolkit for designers
if has('nvim')
Plug 'debugloop/telescope-undo.nvim'
Plug 'Eandrju/cellular-automaton.nvim' " F11, :CellularAutomaton make_it_rain
" Plug 'MeanderingProgrammer/render-markdown.nvim' " :RenderMarkdown
Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'} " improved syntax hl and stuff
Plug 'ja-he/heat.nvim' " git heatmap
Plug 'kevinhwang91/nvim-ufo' " better looking folds
Plug 'kevinhwang91/promise-async' " required for nvim-ufo
Plug 'nvim-lua/plenary.nvim' " required for telescope
Plug 'nvim-telescope/telescope.nvim' " fuzzy finder
" Plug 'lewis6991/gitsigns.nvim' " git stuff
Plug 'nvim-lualine/lualine.nvim' " statusline
Plug 'numToStr/Comment.nvim' " (un)comment everything with #
Plug 'lukas-reineke/indent-blankline.nvim' " indent guides
" Plug 'madox2/vim-ai'
Plug 'VonHeikemen/lsp-zero.nvim' " helper integrating lspconfig and nvim-cmp
Plug 'neovim/nvim-lspconfig' " configs for nvim lsp client
Plug 'williamboman/mason.nvim' " package manager for lsp, dap, linters, formatters
Plug 'williamboman/mason-lspconfig.nvim' " bridge for mason and lspconfig
Plug 'hrsh7th/nvim-cmp' " completion engine
Plug 'hrsh7th/cmp-nvim-lsp' " nvim-lsp source for cmp
Plug 'hrsh7th/cmp-buffer' " buffer source for cmp
Plug 'hrsh7th/cmp-path' " filesystem paths source for cmp
Plug 'hrsh7th/cmp-cmdline' " :cmdline source for cmp
Plug 'hrsh7th/cmp-nvim-lua' " complete neovim's Lua runtime API such vim.lsp.*
Plug 'ray-x/lsp_signature.nvim' " Show function signature when you type
Plug 'hrsh7th/cmp-nvim-lsp-signature-help' " lsp signature help
Plug 'hrsh7th/cmp-copilot' " copilot in cmpmenu
Plug 'L3MON4D3/LuaSnip', {'tag': 'v2.*', 'do': 'make install_jsregexp'} " snippet engine
Plug 'rafamadriz/friendly-snippets' " snippets repository
Plug 'saadparwaiz1/cmp_luasnip' " luasnip source for cmp
Plug 'amarakon/nvim-cmp-fonts' " complete fonts from fc-list
Plug 'stevearc/dressing.nvim' " better ui dialogs (like for lsp renames)
Plug 'aznhe21/actions-preview.nvim' " code actions preview with diff in telescope
" Plug 'stevearc/conform.nvim' " code actions preview with diff in telescope
Plug 'ludovicchabant/vim-gutentags' " tag management
Plug 'pbogut/magento2-ls' " magento2 language server
Plug 'rcarriga/nvim-notify' " notifications
" Plug 'zbirenbaum/copilot.lua'
" Plug 'mikesmithgh/kitty-scrollback.nvim'
Plug 'trapd00r/kitty-scrollback.nvim' " using own fork cause couldn't configure away default opts
" Plug 'lukas-reineke/headlines.nvim'
" codecompanion
" Plug 'nvim-lua/plenary.nvim'
" Plug 'nvim-treesitter/nvim-treesitter'
" Plug 'hrsh7th/nvim-cmp', " Optional: For using slash commands and variables in the chat buffer
" Plug 'nvim-telescope/telescope.nvim', " Optional: For using slash commands
" Plug 'stevearc/dressing.nvim' " Optional: Improves `vim.ui.select`
" Plug 'olimorris/codecompanion.nvim'
" avante
" Plug 'stevearc/dressing.nvim'
" Plug 'nvim-lua/plenary.nvim'
" Plug 'MunifTanjim/nui.nvim'
"
" " Optional deps
" Plug 'nvim-tree/nvim-web-devicons' "or Plug 'echasnovski/mini.icons'
" Plug 'HakonHarnes/img-clip.nvim'
" local llm
Plug 'David-Kunz/gen.nvim'
" Yay, pass source=true if you want to build from source
Plug 'yetone/avante.nvim', { 'branch': 'main', 'do': 'make' }
" only to enable code actions for intellephence...
" Plug 'neoclide/coc.nvim', {'branch': 'release'}
else
endif
" extra syntax rules
Plug 'trapd00r/vim-after-syntax-vim', { 'for': 'vim' }
Plug 'trapd00r/vim-after-syntax-perl', { 'for': 'perl' }
Plug 'trapd00r/vim-after-syntax-zsh', { 'for': ['zsh', 'sh'] }
Plug 'pangloss/vim-javascript', { 'for': 'javascript' }
Plug 'Glench/Vim-Jinja2-Syntax', { 'for': 'jinja' }
Plug 'trapd00r/hass-template.vim', { 'for': 'jinja' }
Plug 'fatih/vim-go', { 'for': 'go' }
Plug 'jparise/vim-graphql', { 'for': 'graphql' }
call plug#end()
" ========== INIT END ===================================
" ========== OPTIONS START ==============================
let &termencoding = &encoding " should be utf-8; exceptions below
set autoindent " copy indent from previous line
set autoread " read file again if changed outside of vim
set backspace=start,indent,eol " what backspace, ^w etc will operate on
set cindent " c program indenting
set cinkeys-=0# " https://stackoverflow.com/questions/354097/how-to-configure-vim-to-not-put-comments-at-the-beginning-of-lines-while-editing#comment127103383_354097
set clipboard=unnamed " define clipboard registers to use
set cdhome " cd to ~ on :cd
set colorcolumn& " useful at times but disabled by default
set complete=.,w,b,u,d,k,kspell " insert mode completion for ^n, ^p
set completeopt+=menuone " use popup menu for completion even if only one match
set cursorline " only use this for CursorLineNr
set define=[^A-Za-z_] " for macro definition
set diffopt=filler,iwhite,context:2,vertical " settings for vimdiff
set display+=lastline,uhex " changes the way text is displayed
set expandtab " use spaces instead of tabs
set fileencodings=utf-8,latin1 " list of fileencodings to try
set fillchars+=fold:\ " chars used for filling the folded line when folded
set foldcolumn=2 " width of foldcolumn
set foldenable " when off, all folds are open
set foldignore=# " lines starting with char will get their fold level from surrounding lines
set foldlevel=99 " folds with a higher level will be closed
set foldlevelstart=99 " do not fold by default
set foldmarker={,} " and these can be adjusted anywhere of course
set foldmethod=marker " fold on defined markers
set foldminlines=2 " close folds with n lines minimum
set foldnestmax=4 " maximum nesting when using syntax or indent foldmethods
set foldopen=block,hor,jump,mark,percent,quickfix,search,tag,undo " actions that will open a fold
set formatoptions=qro " options for formatting; like gq
set grepprg=internal " what grep to use
set helpheight=5 " height of help window
set helplang=en " language of help
set hidden " better buffer handling
set history=50 " ex command history, q:
set hlsearch " highlight searches
set ignorecase " ignore case, but also uses smartmatch
set include=\\<\\(use\\\|require\\)\\> " perl module to...
set includeexpr=substitute(substitute(v:fname,'::','/','g'),'$','.pm','') " ... perl module in filesystem
set incsearch " show matches while typing
set indentkeys-=0# " https://stackoverflow.com/questions/354097/how-to-configure-vim-to-not-put-comments-at-the-beginning-of-lines-while-editing#comment127103383_354097
set isfname+=: " add : to filename pattern
set iskeyword+=$ " perl scalar
set iskeyword+=% " perl hash
set iskeyword+=@-@ " perl array
set iskeyword+=: " perl colon
set iskeyword-=, " remove , from keyword
set laststatus=2 " always how statusline
set list " visualize non-visual characters
set listchars& " '- set it to empty first
set listchars+=conceal:⌦ " '- what to show when concealing something
set listchars+=eol:\ " '- end of line
set listchars+=extends:\ " '- last column when wrap is off
set listchars+=nbsp: " '- non-breaking space
set listchars+=precedes:\ " '- first column when wrap is off
set listchars+=tab:»\ " '- tab
set listchars+=trail:· " '- trailing whitespace
set magic " set magic on for regex but I use \v anyway
set matchpairs+=<:>,«:»,「:」 " match more things with %
"set matchpairs+==:; " match : with %
set matchtime=20 " time to show the match with %
set maxfuncdepth=1000 " avoid recursive functions
set maxmapdepth=500 " avoid recursive mappings
set modeline " yes I want to use modelines
set modelines=2 " number of lines to check for a modeline
set nobackup " no backups, I have persistent undo
set noequalalways " do not auto-equalize size of windows
set noerrorbells " bells are for double-o 7
set nomore " disable the more-prompt
set noshowmode " disable mode change messages
set nospell spelllang=en_us " no spell on, but set spelllang so I can use it if I want to
set nostartofline " modifies some movement commands
set noswapfile " no swaps please
set nowrap " no wrapping since it changes the appearance of the data
set nowritebackup " no backups please
set nrformats=alpha,hex " defines what a number is for increasing/decreasing with ^a,^x
set number norelativenumber " show line numbers
set numberwidth=2 " width of number column
set preserveindent " preserve indent when using <<, >> etc
set pumheight=20 " height and number of suggestions to show in completion popup
set report=0 " always show how many lines have been modified
set ruler " show line and column number
set rulerformat=%30(%=\:b%n%y%m%r%w\ %l,%c%V\ %P%) " format for the above
set scrolloff=40 " context above and below cursor; 999 = exactly in the middle
set shiftwidth=2 " number of spaces to use for a tab
set shortmess=aIoOT " avoid as many hit-enter prompts as possible
" set showbreak=↳ " start of lines when wrap is on
set showbreak=\ " start of lines when wrap is on
set showcmd " show (partial) cmd in last line of screen
set showmatch " briefly display match when jumping to a bracket
set showtabline=0 " hide tablines, don't use
set signcolumn=number " use numbers column for signs, too
set smartcase " case ignored unless uppercase used anywhere
set smarttab " insert blanks according to shiftwidth, tabstop, expandtab
set splitbelow " preferably split below
set ssop=buffers,folds,globals,help,localoptions,options,resize " session options for mksession
set synmaxcol=300 " maximum column to highlight
set t_Co=256 " terminal supports 256 colors
set tabpagemax=4 " max tab pages when using -p flag
set tabstop=2 " shouldn't modify this the help states..?
set tags=./tags,tags,~/dev/tags,~/dev/askas/utils-askas/vim/tags " location of tag files
set textwidth=80 " maximum width of text
set title " set title for the terminal
set timeout " time out on mappings
set timeoutlen=3000 " how long to wait prior to timeout
set ttimeoutlen=50 " the same for terminal keycodes
set ttyfast " my terminal is very fast
set undofile " undo file for all the undos
set undolevels=1024 " persisent undo for 1024 actions
set updatetime=200 " for CursorHold events and GitGutter signs
set virtualedit=block " virtualedit for visual block mode
set visualbell t_vb= " disable visual bells
set wildchar=<Tab> " completion char in cmdline
set wildignore=*.swp,*.bak,*~,blib,*.o,*.png,*.jpe?g,.git,.svn,*.so,.hg " completion should ignore
set wildmenu " command-line completion, enhanced mode
set wildmode=list:longest,full " completion mode
" Vim only options
if !has('nvim')
set term=rxvt-unicode-256color " set terminal
set viminfo=h,'100,\"100,:20,n~/var/vim/viminfo " what to save in the viminfo
set undodir=~/var/vim/undo " where to keep the undos
set lazyredraw " do not redraw screen while executing macros etc
set title " send a title string to the terminal
set cmdheight=1
set formatprg=perl\ -MText::Autoformat\ -e'autoformat({right=>80})' " much better formatting
" Neovim only options
else
set lazyredraw " do not redraw screen while executing macros etc
set cmdheight=1
set notitle " fixes bug in neovim where statusline is messed up
set mouse="" " disable mouse
set notermguicolors
" git blame in winbar
" function! GetGitBlame()
" let lnum = line('.')
" let filename = expand('%:p')
" let blame_cmd = 'git blame -L ' . lnum . ',+1 --porcelain ' . filename
" let blame_output = systemlist(blame_cmd)
"
" let commit_msg = ''
" let author = ''
" let commit_date = ''
"
" for line in blame_output
" if line =~ '^author '
" let author = matchstr(line, 'author \zs.\\+')
" elseif line =~ '^author-mail '
" let author = matchstr(line, 'author-mail <\zs[^>]\+')
" elseif line =~ '^author-time '
" let commit_date = strftime('%Y-%m-%d', str2nr(matchstr(line, 'author-time \zs\d\+')))
" elseif line =~ '^summary '
" let commit_msg = matchstr(line, '^\w\+\s\+\zs\(.*\)')
" elseif line =~ '^Not Committed Yet'
" let commit_msg = 'Not Committed Yet'
" return commit_msg
" endif
" endfor
"
" if commit_msg =~ 'Version of'
" return ' %7*Not commited yet%*'
" endif
"
" return '%7*' . commit_date . '%* %6*' . commit_msg . '%*'
" " return ' ' . '%7*' . commit_date . ' %6*' . commit_msg . ' %5*(%7*' . author . '%5*)%*%9*'
" endfunction
"
" set winbar=%!GetGitBlame()
endif
" ========== OPTIONS END ================================
colorscheme neverland_black_bg
" ========== MAPPINGS START =============================
" ATTENTION! <leader> #1
let mapleader=','
nnoremap <leader>B :lua require'dap'.toggle_breakpoint()
nnoremap <leader>C :lua require'dap'.continue()
inoremap <expr> <Tab> pumvisible() ? "\<C-n>" : "\<Tab>"
inoremap <expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<S-Tab>"
if has('nvim')
nnoremap <leader>ss :Telescope lsp_document_symbols<cr>
nnoremap <leader>dD :Telescope diagnostics<cr>
" Comment.nvim comment/uncomment
nmap # gcc
vmap # gc
" pick completion
imap <C-J> <Down>
imap <C-K> <Up>
cmap <C-J> <Down>
cmap <C-K> <Up>
nnoremap <F11> :call Rain()<cr>
function! Rain()
TSBufEnable highlight
CellularAutomaton make_it_rain
endfunction
endif
" up and down for stepping through the file list
nnoremap <silent> <UP> :prev<cr>
nnoremap <silent> <DOWN> :next<cr>
" left and right to step through the quickfix list
" nnoremap <silent> <LEFT> :cprev<cr>
" nnoremap <silent> <RIGHT> :cnext<cr>
" double <LEFT> and <RIGHT> to jump through the quickfix file list
" nmap <silent> <LEFT><LEFT> :cpfile<CR><C-G>
" nmap <silent> <RIGHT><RIGHT> :cnfile<CR><C-G>
" Github copilot
"imap <silent> <C-j> <Plug>(copilot-next)
"imap <silent> <C-k> <Plug>(copilot-previous)
"imap <silent> <C-\> <Plug>(copilot-dismiss)
" toggle listchars
map <C-q> :set list!<cr>
" go to definition and go back
nnoremap <backspace> <C-]>
nnoremap <tab> <C-T>
" perldoc what's under the cursor
"nnoremap <C-k> :Perldoc<cr>
" search only inside a block/scope/function
nnoremap <leader>/ :normal vi{<esc><esc>/\%V
" jump to the next mark
nnoremap <leader>m :normal ]`<cr>
" dont move when using *
nnoremap <silent> * :let s=winsaveview()<cr>*:call winrestview(s)<cr>
" alt+<dot> - rg *, fzf results
nnoremap <Esc>. :RgFzf*<cr>
" evaluate and execute lines of viml
" needs https://github.com/trapd00r/vim-scriptease
nnoremap <silent> E :Execute<cr>
vnoremap <silent> E :Execute<cr>
" highlight the current line
" https://github.com/trapd00r/currentline.vim
nnoremap <silent> <leader><return> :call HighlightCurrentLine('♥')<cr>
" toggle colorcolumn at cursor position
" unless cursor position is 1, then disable it
nnoremap <silent> <leader>cc :call CCCP()<cr>
" change surrounding quotes
nnoremap <leader>' :normal cs"'<cr>
nnoremap <leader>" :normal cs'"<cr>
" go to start of function
nnoremap <silent> <leader>q :normal [m<cr>
" go to end of function
"nnoremap <silent> <leader>a :normal ]m<cr>
" change the ugly q^single quoted^ to something better
" you want to do
" setxkbmap se -variant nodeadkeys for the ^
nmap <leader>^ cs^<bar>
" highlight undo/redo operations
" nmap u <Plug>(highlightedundo-undo)
" nmap <C-r> <Plug>(highlightedundo-redo)
" highlight the word under the cursor in differently
" these things are cleared with me <C-l> mapping
nnoremap <silent> <leader>h1 :execute 'match CurrentWord1 /\<<c-r><c-w>\>/'<cr>
nnoremap <silent> <leader>h2 :execute 'match CurrentWord2 /\<<c-r><c-w>\>/'<cr>
nnoremap <silent> <leader>h3 :execute 'match CurrentWord3 /\<<c-r><c-w>\>/'<cr>
nnoremap <silent> <leader>h4 :execute 'match CurrentWord4 /\<<c-r><c-w>\>/'<cr>
nnoremap <silent> <leader>h5 :execute 'match CurrentWord5 /\<<c-r><c-w>\>/'<cr>
" toggle comments
"nmap # <Plug>CommentorLine
"vmap # <Plug>Commentor
" close all folds
nnoremap <leader>fc zM
" undoentire git hunk
nnoremap <leader>u :GitGutterUndoHunk<cr>
" go to next git changed hunk
nnoremap <leader>n :GitGutterNextHunk<cr>
" delete block
nnoremap db da{
" folding around git changed hunks, showing 3 lines of context
nmap <silent> zg :GitGutterFold <bar> normal zr<cr>
" folding around searches
nmap <silent> <expr> zz FS_ToggleFoldAroundSearch({'context':1})
nmap <silent> <expr> z2 FS_ToggleFoldAroundSearch({'context':2})
" folding around use statements
nmap <silent> <expr> zu FS_FoldAroundTarget('^\s*use\s\+\S.*;',{'context':1})
" folding around warns
nmap <silent> <expr> zw FS_FoldAroundTarget('^\s*warn\s\+\S.*;',{'context':1})
" folding around mappings
nmap <silent> <expr> zm FS_FoldAroundTarget('^[nvxo]\(nore\)\?map',{'context':1})
" show the current function name
" map <C-s> :call ShowFuncName()<cr>
" use quickfix list to go to func definition
nnoremap <C-o> :CtrlPFunky<cr>
" a double <cr> to supress "Press enter to continue"
"nnoremap <C-c> :exe '!markdown_previewer %'<cr><cr>
nnoremap <silent> <C-c> :<C-U>PipePreview<CR>
" next buffer
nnoremap <C-n> :bnext<cr>
" previous buffer
" nnoremap <C-b> :bprev<cr>
" nnoremap <leader>b :Buffers<cr>
" replace standard :ls with fzf-powered one.
cabbrev ls <c-r>=(getcmdtype()==':' && getcmdpos()==1 ? 'Buffers' : 'ls')<cr>
" Moving around
nnoremap J 10j
nnoremap K 10k
vnoremap J 10j
vnoremap K 10k
" highlight custom text objects
"nnoremap <silent><expr> <backspace> hl#mark()
"nnoremap <silent><expr> <tab> hl#unmark('line')
"vnoremap <silent><expr> <tab> hl#unmark('block')
"highlight HL cterm=bolditalic ctermbg=fg ctermfg=bg
" Return to the previous cursor position
" --------------------------------------
" '' returns to the previous line
" `` returns to the previous line and position
" --------------------------------------
" I never want #1 so I make it a nop and map #2 to #1
map '' <nop>
map '' ``
" Move visual blocks around or dupe them
" vmap <C-h> <Plug>SchleppLeft
" vmap <C-j> <Plug>SchleppDown
" vmap <C-k> <Plug>SchleppUp
" vmap <C-l> <Plug>SchleppRight
" vmap <C-d> <Plug>SchleppDup
"let g:Schlepp#dupTrimWS = 1
" resize windows like in sdorfehs
nnoremap <C-W>J :exe 'resize ' . winheight(0) / 2<cr>
nnoremap <C-W>K :exe 'resize ' . winheight(0) * 2<cr>
nnoremap <C-W>Q :resize 100<cr>
" my redraw key does a few things:
" - remove hlsearch
" - remove hlnext,
" - clear highlighted yanks
" - clear highlighted lines
" - clear highlighted CurrentWord*
" - clear highlighted InterestingWords
" - reset colorcolumn
" - redraw screen
nnoremap <silent> <C-l>
\ :call HLNextOff() <BAR>
\ :nohl <BAR>
\ :hi clear YankedMatches <BAR>
\ :call HighlightCurrentLine('clear') <BAR>
\ :set colorcolumn& <BAR>
\ :redraw <CR>
" resize windows like in sdorfehs
nnoremap <C-W>J :exe 'resize ' . winheight(0) / 2<cr>
nnoremap <C-W>K :exe 'resize ' . winheight(0) * 2<cr>
" sort and operate on visual block selections
" press enter or add flags to sort, i.e -n
" this will sort _only_ what's selected and not the entire
" lines as is default vim behaviour
"vnoremap S :Blockwise !sort<space>
vnoremap B :Blockwise<cr>
vnoremap S :SortByBlock<cr>
" toggle folds with Enter
" nnoremap <silent> <C-m> @=(foldlevel('.')?'za':"\<Space>")<cr>
" search for word under cursor
"nnoremap <silent> <C-g> :exe ":silent! Rg <C-R><C-W>"<cr>
"
" better movement in ex mode
cnoremap <C-*> <c-a>
cnoremap <C-_> <c-f>
cnoremap <C-a> <home>
cnoremap <C-b> <left>
cnoremap <C-d> <del>
cnoremap <C-e> <end>
cnoremap <C-f> <right>
cnoremap <C-h> <S-Left>
cnoremap <C-j> <down>
cnoremap <C-k> <up>
cnoremap <C-l> <S-Right>
cnoremap <C-n> <down>
cnoremap <C-p> <up>
cnoremap <M-b> <S-Left>
cnoremap <M-f> <S-Right>
" ATTENTION! <LEADER> KEY NUMBER TWO
let mapleader=';'
" and back to <leader> #1
let mapleader=','
" ========== FZF START ==================================
" git status
nnoremap <leader>gs :GFiles?<cr>
" use :Gfiles for ctrlp if in a git repo
" otherwise, use normal fzf
"map <silent> <expr> <C-p> FugitiveHead() != '' ? ':GFiles --cached --others --exclude-standard<CR>' : ':Files<CR>'
" use normal :Files if in a magento directory so we can ignore vendor/ directories with fd.ignorefile
map <silent> <expr> <C-p> ':Files<CR>'
" for cases where files aren't part of a git repo
map <silent> <expr> <leader>p FugitiveHead() != '' ? ':GFiles --cached --others <CR>' : ':Files<CR>'
" commits for the current buffer, vselect a line to track changes for it
nnoremap <leader>gc :BCommits<cr>
vnoremap <leader>gc :BCommits<cr>
" display commit history for the current line
" nnoremap ? V:BCommits<cr>
nnoremap ? :GitMessenger<cr>
" commits for the entire project
" nnoremap <leader>Gc :Commits<cr>
" most recent files
if has('nvim')
" nnoremap <space> :Telescope oldfiles sorting_strategy=ascending<cr>
" nnoremap <space> :Telescope frecency workspace=CWD<cr>
nnoremap <space> :History<cr>
nnoremap <leader>gr :call LiveGrepTelescopeProjectDir()<cr>
function! LiveGrepTelescopeProjectDir()
let l:dir = system('git rev-parse --show-toplevel')
let l:dir = substitute(l:dir, '\n$', '', '')
if l:dir ==# ''
echoerr 'Not in a git repo'
return
endif
execute 'Telescope live_grep search_dirs={"' . l:dir . '"}'
endfunction
else
nnoremap <space> :History<cr>
endif
" commandline history
nnoremap <leader>H :History:<cr>
" search history, `
command! QHist call fzf#vim#search_history({'right': '40'})
nnoremap <leader>s :QHist<cr>
" lines, in entire project
nnoremap <leader>l :Lines<cr>
" buffer lines
nnoremap <leader>L :BLines<cr>
" all the marks
nnoremap <leader>M :Marks<cr>
" all the mappings
"nnoremap <leader>m :Maps<cr>
" quickly change ft
nnoremap <leader>ft :Filetypes<cr>
"command! -bang AIR8files call fzf#vim#files('~/dev/askas/air8', <bang>0)
"nnoremap <leader>air :AIR8files<cr>
"nnoremap <leader>f :RgFzf
" Rg word under cursor, and filter results with fzf
nnoremap <C-g> :RgFzf*<cr>
" go to function def
nnoremap <C-S-G> :RgDefFzf*<cr>
" ========== FZF END ====================================
" ========== MAPPINGS END ===============================
" ========== FUNCTIONS START ============================
" go up, like in tridactyl
nnoremap gu :call GoUp()<cr>
function! GoUp()
let b:updir = expand('%:h')
execute ':Explore ' . b:updir
endfunction
" Add code block start/end tags to vimwiki (or markdown)
" The range keyword makes sure we run this function over the
" entire range, instead of over each line in the range
"
" The filetype argument is optional with perl as a default
" :call VimwikiAddCodeBlock('sql') inserts sql code blocks instead
function! VimwikiAddCodeBlock(filetype = 'perl') range
" add google prettify syntax hl matter two lines above
" call append(line("'<") - 1, '<pre class="prettyprint">')
" if needed, we can specify the language to use like this:
" call append(line("'<") - 1, '<pre class="prettyprint lang-' .. a:filetype .. '>')
" Append start of code block and filetype
" before the visual selection
call append(line("'<") - 1, '{{{' .. a:filetype)
" Append end of code block and matter after the visual selection
" call append(line("'>") + 0, '</pre>')
call append(line("'>") + 0, '}}}')
" Expand visual selection by one line
execute ':' . line("'<") - 1
" set mark
normal m<
endfunction
" redirect command to a new scratch buffer
function! Redir(cmd) abort
let output = execute(a:cmd)
20new
setlocal nobuflisted buftype=nofile bufhidden=wipe noswapfile
call setline(1, split(output, "\n"))
endfunction
command! -nargs=1 Redir silent call Redir(<f-args>)
" scratch window for temp things
" bound in my window manager like this:
" bind Return exec urxvt -fg white -bg black -sbg +sb -e vim -c 'call Scratch()'
function! Scratch()
noswapfile hide enew
setlocal buftype=nofile
setlocal bufhidden=hide
setlocal ft=perl
file scratch
startinsert
endfunction
" try to figure out the filetype when there's no extension
function! s:infer_filetype()
let firstline = getline(1)
" perl5
if firstline =~# '^#!.*perl'
set filetype=perl
return
" shell script
elseif firstline =~# '\v^#!/bin/(ba|z)?sh'
set filetype=zsh
return
endif
endfunction
" show syntax group for item under cursor
if has('nvim')
nmap <C-e> :Inspect<cr>
else
nmap <C-e> :call SynStack()<CR>
endif
fu! SynStack()
if !exists("*synstack")
return
endif
echo map(synstack(line('.'), col('.')), 'synIDattr(v:val, "name")')
endfu
" context in statusbar; function, scope or block
function! ContextInStatusbar()
let lnum = line(".")
let col = col(".")
echohl ModeMsg
let g:current_function = getline(search("^[^ \t#/]\\{2}.*[^:]\s*$", 'bWn'))
echohl None
"" matches and returns a str only if the lines matches any of the following:
" viml: fu!, function!, function!
" js: function
" perl: sub
" c: grab_key(KeySym keysym, unsigned int modifiers, Window grab_window)
" css: .store_more_info_wrapper .store_name (a little broken..)
" shell: pastebin() {
" shell: if/elif:
" if g:current_function =~ '\v(^fu[!]?n?[!]?|^sub|^\S+[(].+[)])|^.+[{]|(el)?if \[\[?'
if g:current_function =~ '\v(^fu[!]?n?[!]?|^sub|^\S+[(].+[)])|^.+[{]|(el)?if \[\[?'
" remove sub or function keyword
let funcname = substitute(g:current_function, '\v(sub|fu[!]?n?(ction)?[!]?)\s*', '', '')
return funcname
" can also include scopes or blocks
" return g:current_function
endif
return ''
endfun
" show function name
function! ShowFuncName()
let lnum = line(".")
let col = col(".")
echohl ModeMsg
echo getline(search("^[^ \t#/]\\{2}.*[^:]\s*$", 'bW'))
echohl None
call search("\\%" . lnum . "l" . "\\%" . col . "c")
endfun
" vidir - sanitize filenames (based on x)
fu! Vidir_Sanitize(content)
mark z
"silent! %s/\(\_^[ ]*\)\@<![ ]\+/_/g
"%s/\(\_^\s*\|\_^\s\+\d\+\)\@<!\s/_/g
silent! %s/\v[åä]/a/g
silent! %s/\v[ö]/o/g
silent! %s/\v[ÅÄ]/A/g
silent! %s/\v[Ö]/O/g
silent! %s/,/./g
execute "silent! %s/\v[;<>*|'&!#)([\]{}]//g"
silent! %s/\v_+\ze[.]|\zs[.]\ze_+//g
silent! %s/[$]/S/g
silent! %s/\v-{2,}/-/g
silent! %s/\v_-_/-/g
silent! %s/\v[_]{2,}/_/g
silent! %s/\v[/_-]@<\=[a-z]/\U&/g
silent! %s/\v_(Feat|The|It|Of|At)_/\L&/ig
silent! %s/\v_(Och|N[åa]n)_/\L&/g
if (a:content == 'music') || (a:content == 'mvid')
"silent! %s/\v./\L&/g
silent! %s/\v^\s*[0-9]+\s+\zs\s+/_/g
silent! %s/\(\_^[ ]*\)\@<![ ]\+/_/g
:silent! %s/\v[&]/feat/g
:silent! %s/\v(_[el]p[_]?)/\U\1/ig
:silent! %s/\v([_-]?cd[sm][_-]?|flac|[_-]demo|vinyl|[_-](web|pcb|osv))/\U\1/ig
elseif (a:content == 'tv')
:silent! %s/\v^\s*[0-9]+\s+\zs\s+/./g
silent! %s/\(\_^[ ]*\)\@<![ ]\+/./g
silent! %s/\v[.]-[.]/./g
else
:silent! %s/\v[&]/and/g
endif
'z
delmark z
endfu
" vidir - sort of title-case helper
fu! Vidir_SmartUC()
:s/\w\@<=\ze\u/_/g
:s/\v_+/_/g
":s/\<\@<![A-Z]/_&/g
endfu
" remove trailing whitespace
fu! RemoveTrailingCrap()
if search('\s\+$', 'n')
:%s/\s\+$//
endif
if search( nr2char(182) . '$' )
:execute ":%s/" . nr2char(182) . "//"
endif
endfu
" ========== FUNCTIONS END ==============================
" ========== AUTOCOMMANDS START =========================
" kitty-scrollback
autocmd FileType kitty-scrollback nnoremap <C-d> <Plug>(KsbQuitAll)
autocmd FileType kitty-scrollback setlocal nonumber nolist
augroup TagbarSettings
autocmd!
" autocmd FileType vim,php,perl TagbarOpen
augroup END
augroup NetrwSettings
autocmd!
autocmd FileType netrw setlocal filetype=LS_COLORS.vim
augroup END
augroup custom_nginx
autocmd!
autocmd FileType nginx setlocal iskeyword+=$
autocmd FileType nginx let b:coc_additional_keywords = ['$']
augroup end
" completion for dadbod
autocmd FileType sql,mysql,plsql lua require('cmp').setup.buffer({ sources = {{ name = 'vim-dadbod-completion' }} })
augroup WebbHuset
autocmd!
autocmd BufRead,BufNewFile ~/dev/webbhuset/* setlocal sw=4
" map tab in normal mode to bdelete for php files
" to be used together with backspace, go to definition
autocmd FileType php nnoremap <buffer> <tab> :bdelete<cr>
augroup END
autocmd FileType json setlocal formatprg=jq
" disable automatic comment on newline
autocmd Filetype * setlocal formatoptions-=c formatoptions-=r formatoptions-=o
" enable use of $LS_COLORS coloring in appropriate files
autocmd BufRead,BufNewFile *gitignore,fd.ignorefile,MANIFEST setf LS_COLORS
" do not show tabs in go files
autocmd FileType go setlocal nolist
" enable Rainbows everywhere
autocmd BufRead,BufNewFile * :RainbowParentheses<cr>
" set quickfix window height and make it modifiable
autocmd BufWinEnter quickfix setlocal winheight=40 | setlocal modifiable
" fold config files in a nice way
autocmd BufRead ~/.vimrc,~/etc/vim/vimrc set foldlevel=0 | let &foldmarker='START =====,END ====='
autocmd BufRead ~/.zshrc,~/etc/zsh/zshrc set foldlevel=0 | let &foldmarker='START =====,END ====='
" try to figure out the filetype when there's no extension
" often the case in my bin (~/dev/utils/) directory
autocmd BufRead * call s:infer_filetype()
" evaluate the comment char for the current buffer
" now, the variable b:comment will always hold the correct
" char used for comments in that specific filetype
" this is used for ToggleComment() among other things, mapped
" to #
autocmd BufRead,BufNewFile * silent! let b:comment=split(&commentstring, '%s')[0]
" return to last edit position when opening files
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal! g`\"" |
\ endif
" show only sub defns (and maybe comments)...
let perl_sub_pat = '^\s*\%(sub\|func\|method\|package\)\s\+\k\+'
let vim_sub_pat = '^\s*fu\%[nction!]\s\+\k\+'
augroup FoldSub
autocmd!
autocmd BufEnter * nmap <silent> <expr> zp FS_FoldAroundTarget(perl_sub_pat,'context':1)
autocmd BufEnter * nmap <silent> <expr> za FS_FoldAroundTarget(perl_sub_pat.'\zs\\|^\s*#.*','context':0, 'folds':'invisible')
autocmd BufEnter *.vim,.vimrc nmap <silent> <expr> zp FS_FoldAroundTarget(vim_sub_pat,'context':1)
autocmd BufEnter *.vim,.vimrc nmap <silent> <expr> za FS_FoldAroundTarget(vim_sub_pat.'\\|^\s*".*','context':0, 'folds':'invisible')
autocmd BufEnter * nmap <silent> <expr> zv FS_FoldAroundTarget(vim_sub_pat.'\\|^\s*".*','context':0, 'folds':'invisible')
augroup END
" use the altscreen for :!ls instead of it going back to the terminal
"augroup altscreen
" autocmd!
" autocmd VimEnter,VimResume * let &t_ti = substitute(&t_ti, '\e\[?1049[hl]', '', '') | let &t_te = substitute(&t_te, '\e\[?1049[hl]', '', '')
" autocmd VimLeave,VimSuspend * let &t_ti = save_t_ti | let &t_te = save_t_te
"augroup END
" escape faster!
augroup FastEscape
autocmd!
set notimeout
set ttimeout
set timeoutlen=10
autocmd InsertEnter * set timeout
autocmd InsertLeave * set notimeout
augroup END
" sadly there is no tt2 + html + js syntax file that works
autocmd BufRead,BufNewFile *.tt setf javascript
autocmd BufNewFile,BufRead MANIFEST set filetype=LS_COLORS
autocmd BufNewFile,BufRead vidir* set filetype=LS_COLORS
autocmd BufNewFile,BufRead Changes set filetype=changelog
autocmd BufRead,BufNewFile *.*htm*,*.xml setl sw=1
autocmd BufNewFile *.txt setl cc=
autocmd BufRead /etc/fstab,~/etc/fstab highlight fsDeviceError ctermfg=fg ctermbg=bg cterm=italic
" update modification time
autocmd BufWrite ~/.irssi/scripts/*.pl %s/changed => ["'].*/\="changed => '" . strftime("%c") . "',"/e
autocmd BufWrite ~/.irssi/* %s/changed => ["'].*/\="changed => '" . strftime("%c") . "',"/e
" ========== AUTOCOMMANDS END ===========================
" ========== COMMANDS START =============================
" replace a few builtin commands with versions that send the
" results elsewhere
cabbrev scriptnames <c-r>=(getcmdtype()==':' && getcmdpos()==1 ? 'Scriptnames' : 'scriptnames')<cr>
cabbrev messages <c-r>=(getcmdtype()==':' && getcmdpos()==1 ? 'Messages' : 'messages')<cr>
cabbrev verbose <c-r>=(getcmdtype()==':' && getcmdpos()==1 ? 'Verbose' : 'verbose')<cr>
" you'll need my vim fork: http://github.com/trapd00r/wim
if v:progname == 'wim'
comclear
try
" this one is especially annoying
command! tohtml TOhtml
command! vresize vert resize 80
command! hresize resize 60
command! Write write
command! Command command