-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvimrc
More file actions
1072 lines (911 loc) · 37.8 KB
/
Copy pathvimrc
File metadata and controls
1072 lines (911 loc) · 37.8 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
"-----------------------------------------------------------------------------
" Front matter
"-----------------------------------------------------------------------------
set nocompatible " Turn on vim defaults (instead of vi compatibility)
set encoding=utf-8 " Use UTF-8 encoding for displaying properly
let mapleader=' ' " Leader key is Space instead of \
"-----------------------------------------------------------------------------
" Set up .vim-local
"-----------------------------------------------------------------------------
let s:vimlocaldir = $HOME . "/.vim-local"
let s:vimlocaldir_swp = s:vimlocaldir . "/swp"
if finddir(s:vimlocaldir) ==# ""
call mkdir(s:vimlocaldir, "", 0700)
call mkdir(s:vimlocaldir_swp, "", 0700)
endif
"-----------------------------------------------------------------------------
" Includes and Plugins
"-----------------------------------------------------------------------------
call plug#begin()
Plug 'godlygeek/tabular'
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
Plug 'Shougo/unite.vim'
Plug 'Shougo/vimproc.vim'
Plug 'Shougo/vimfiler.vim'
if executable("node")
Plug 'neoclide/coc.nvim', {'branch': 'release'}
endif
Plug 'airblade/vim-gitgutter', {'branch': 'main'}
if executable("fzf")
Plug 'alok/notational-fzf-vim'
endif
Plug 'alvan/vim-closetag'
Plug 'aquach/vim-http-client'
if executable("direnv")
Plug 'direnv/direnv.vim'
endif
Plug 'easymotion/vim-easymotion'
Plug 'hashivim/vim-terraform'
Plug 'iamcco/markdown-preview.nvim', {'do': { -> mkdp#util#install() }, 'for': ['markdown', 'vim-plug']}
Plug 'itchyny/vim-qfedit'
Plug 'liuchengxu/vim-which-key'
Plug 'LnL7/vim-nix'
Plug 'mbbill/undotree'
Plug 'matschaffer/vim-islime2'
Plug 'michaeljsmith/vim-indent-object'
Plug 'plasticboy/vim-markdown'
Plug 'terrastruct/d2-vim'
Plug 'tpope/vim-fugitive'
Plug 'tpope/vim-repeat'
Plug 'tpope/vim-commentary'
Plug 'tpope/vim-obsession'
Plug 'tyru/open-browser.vim'
Plug 'vim-airline/vim-airline'
Plug 'vim-crystal/vim-crystal'
Plug 'vim-scripts/LargeFile'
Plug 'vim-scripts/utl.vim'
Plug 'vim-utils/vim-vertical-move'
Plug 'zigford/vim-powershell'
" AI
Plug 'ggml-org/llama.vim'
" Elixir
Plug 'elixir-editors/vim-elixir'
" Rust
Plug 'rust-lang/rust.vim'
" JS/JSX/Typescript/GQL
Plug 'pangloss/vim-javascript' " JavaScript support
Plug 'leafgarland/typescript-vim' " TypeScript syntax
Plug 'maxmellon/vim-jsx-pretty' " JS and JSX syntax
Plug 'jparise/vim-graphql' " GraphQL syntax
" Games
Plug 'katono/rogue.vim'
call plug#end()
let html_no_rendering=1 " [syntax/html.vim] Don't make html fancy, like underlining links
set t_Co=256 " Instruct vim to use 256-color mode
let c_C99=1 " [alternative-syntaxes] For std_c syntax to recognize C99
let g:LargeFile=20 " [LargeFile.vim] Files larger than 20 MB will not have syntax enabled
let g:paredit_mode = 0 " Paredit is annoying
filetype plugin indent on " Detect file type, and load plugins and indents for the filetype
runtime macros/matchit.vim " % can match more things
runtime ftplugin/man.vim " Provides colorful Man command in vim
" Todo
let g:todo_root = '~'
let g:todo_open_command = 'elinks'
" Closetag
let g:closetag_filenames = '*.html,*.xhtml,*.phtml,*.ex,*.eex,*.leex'
let g:closetag_xhtml_filenames = '*.xhtml,*.jsx'
let g:closetag_filetypes = 'html,xhtml,phtml,xml'
let g:closetag_xhtml_filetypes = 'xhtml,jsx'
let g:closetag_shortcut = '>'
let g:closetag_close_shortcut = ' >'
" FZF
nnoremap <C-p> :FZF<CR>
" Tabular
vnoremap <Leader>a :Tabular /=
" Undotree
nnoremap <leader>u :UndotreeToggle<cr>
"-----------------------------------------------------------------------------
" Global Options
"-----------------------------------------------------------------------------
set autoindent " Copy indent from current line when starting new line, or follow smartindent or cindent
set autoread " When a file was changed outside of vim and not inside, autoread it again
set background=dark " Indicate for syntax on that we have a dark background
set backspace=indent,eol,start " We can backspace over autoindent, line breaks (to join lines), and start of insert
set clipboard=unnamed,unnamedplus " Use the system clipboard instead of multiple clipboards
set complete=.,w,b " C-n/C-p scans current buf, other window bufs, and other loaded buffers
set cursorline " Highlight the current line the cursor is on
set directory=$HOME/.vim-local/swp " Swap files will all be at the home directory
set expandtab " Tab keys is spaces instead of tab (C-V Tab will tab)
set foldlevelstart=99 " Do not fold all the things by default
set formatoptions=clnqr2 " Automatic format options (about all of them except auto-format)
set grepprg=rg\ --vimgrep " Use ripgrep/rg for grepping instead of grep
set hidden " Can hide buffers when abandoning them (don't need to save to switch)
set incsearch " Incremental search (go there while I am typing)
set laststatus=2 " Always show a status line
set list " Shows special characters, like tabs, end of lines, spaces, and so forth
set listchars=tab:__,trail:. " Tabs look like ____, and trailing spaces look like .
set matchpairs=(:),{:},[:] " Show highlight match for these symbols
set nobackup " Don't make backups of files
set nohlsearch " Highlights search matches
set nomodeline " No vulnerabilities, thank you
set nostartofline " When switching buffers, do not move the cursor to the start of the line
set nowrap " Turn off visual line wrap
set nowritebackup " Turn off making a backup before overwriting a file
set number
set pastetoggle=<F11> " F11 toggles Paste vs Nopaste for Insert mode
set ruler " Show the line and column number of the cursor position
set shiftwidth=4 " Indention spaces
set shortmess+=c " Don't give ins-completion-menu messages
set showcmd " Show partial commands at the last line of the screen
set showmode " Show mode in the last line (--INSERT--, etc)
set sidescroll=0 " At the end of a line, shift screen so cursor is at the middle
set signcolumn=yes " Always show signcolumns
set nosmartindent " No smart indention; it isn't actually smart
set smarttab " Use shiftwidth to guide tab indention
set nospell " By default, don't spellcheck
set spelllang=en_us " Spell language is US English
set splitbelow " If you split the window, the new window will be below the current
set suffixes=.bak,.obj,.swp,.o " These get low priority when matching wildcards (see wildchar)
set tabstop=4 " Tab spaces
set textwidth=78 " Maximum width of text being inserted
set updatetime=300 " You will have bad experience for diagnostic messages when it's default 4000
set visualbell " Flash instead of beeping
set wildchar=^I " Tab starts wildchar expansion in the command-line
set wildmenu " When wildchar is activate, you can cycle through a menu of matches
set wildmode=list:longest " When more than one match, list all matches and complete till longest common string
syntax on
colorscheme shadow
" viminfo settings
" '32 => remember marks for 32 previous files
" f1 => remember marks '0 to '9 and 'A to 'Z; '0 is current cursor position
" <10 => Max number of lines saved for each register (10)
" s10 => Max size of a register in kB (10 kB)
" n... => Name of the viminfo file
set viminfo='32,f1,<10,s10,n$HOME/.vim-local/viminfo
" Status Line settings
set statusline=%<%f\ %h%m%r%=%-14.(%l,%c%V%)\ %P
let g:airline#extensions#tabline#enabled = 1
let g:airline#extensions#tabline#left_sep = ' '
let g:airline#extensions#tabline#left_alt_sep = ''
let g:airline#extensions#tabline#right_sep = ''
let g:airline#extensions#tabline#right_alt_sep = ''
"don't autoselect first item in omnicomplete, show if only one item (for preview)
"remove preview if you don't want to see any documentation whatsoever.
set completeopt=longest,menuone,preview
" Autoread
augroup autoread_autos
autocmd!
" Trigger `autoread` when files changes on disk
" https://unix.stackexchange.com/questions/149209/refresh-changed-content-of-file-opened-in-vim/383044#383044
" https://vi.stackexchange.com/questions/13692/prevent-focusgained-autocmd-running-in-command-line-editing-mode
autocmd FocusGained,BufEnter,CursorHold,CursorHoldI * if mode() != 'c' | checktime | endif
" Notification after file change
" https://vi.stackexchange.com/questions/13091/autocmd-event-for-autoread
autocmd FileChangedShellPost *
\ echohl WarningMsg | echo "File changed on disk. Buffer reloaded." | echohl None
augroup END
"-----------------------------------------------------------------------------
" AI
"-----------------------------------------------------------------------------
let g:llama_config = {
\ 'endpoint_fim': 'http://127.0.0.1:8012/completion',
\ 'keymap_fim_trigger': '<C-L>',
\ 'keymap_fim_accept_full': '<Tab>',
\ 'keymap_fim_accept_line': '<S-Tab>',
\ 'keymap_fim_accept_word': '<C-Right>',
\ 'auto_fim': v:true,
\ }
"-----------------------------------------------------------------------------
" vim-vertical-move
"-----------------------------------------------------------------------------
let g:vertical_move_default_mapping = 0
nmap <silent> <leader>j <Plug>(vertical_move_down)
nmap <silent> <leader>k <Plug>(vertical_move_up)
xmap <silent> <leader>j <Plug>(vertical_move_down)
xmap <silent> <leader>k <Plug>(vertical_move_up)
"-----------------------------------------------------------------------------
" coc
"-----------------------------------------------------------------------------
" Took a lot of advice from https://pragmaticpineapple.com/ultimate-vim-typescript-setup/
let g:airline#extensions#coc#enabled = 1
let g:airline#extensions#coc#show_coc_status = 1
let g:coc_global_extensions = ['coc-json', 'coc-python', 'coc-go', 'coc-rust-analyzer', 'coc-tsserver', 'coc-elixir', 'coc-lua', 'coc-erlang_ls']
inoremap <silent><expr> <C-@> coc#refresh()
" Make <CR> to accept selected completion item or notify coc.nvim to format
" <C-g>u breaks current undo, please make your own choice.
inoremap <silent><expr> <CR> coc#pum#visible() ? coc#pum#confirm() : "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"
" Remap keys for applying codeAction to the current line.
nmap <leader>ac <Plug>(coc-codeaction)
" Apply AutoFix to problem on the current line.
nmap <leader>qf <Plug>(coc-fix-current)
" GoTo code navigation.
nmap <silent> gd <Plug>(coc-definition)
nmap <silent> gy <Plug>(coc-type-definition)
nmap <silent> gi <Plug>(coc-implementation)
nmap <silent> gr <Plug>(coc-references)
" Keys for popups
nnoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? coc#float#scroll(1) : "\<C-f>"
nnoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? coc#float#scroll(0) : "\<C-b>"
inoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? "\<c-r>=coc#float#scroll(1)\<cr>" : "\<Right>"
inoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? "\<c-r>=coc#float#scroll(0)\<cr>" : "\<Left>"
vnoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? coc#float#scroll(1) : "\<C-f>"
vnoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? coc#float#scroll(0) : "\<C-b>"
command! CocElixirLS CocCommand workspace.showOutput elixir
"-----------------------------------------------------------------------------
" iSlime
"-----------------------------------------------------------------------------
let g:islime2_29_mode=1
nnoremap <leader>ck :%y r<cr>:call islime2#iTermSendNext(substitute(@r, '\\', '\\\\', 'g'))<CR>
vnoremap <leader>cc :<C-u>call islime2#iTermSendOperator(visualmode(), 1)<CR>
nnoremap <leader>cc vip:<C-u>call islime2#iTermSendOperator(visualmode(), 1)<CR>
"-----------------------------------------------------------------------------
" Python
"-----------------------------------------------------------------------------
function ConfigurePython()
nnoremap <buffer> <silent> <leader>ee :CocCommand python.execInTerminal<cr>
vnoremap <buffer> <silent> <leader>ee :<C-u>CocCommand python.execSelectionInTerminal<cr>
endfunction
augroup python_autos
autocmd!
autocmd FileType python call ConfigurePython()
augroup END
"-----------------------------------------------------------------------------
" vimrc
"-----------------------------------------------------------------------------
function VimrcFoldText()
return '+ ' . substitute(getline(v:foldstart+1), '^" ', '', '') . ' (' . (v:foldend - v:foldstart + 1) . 'L)'
endfunction
function ConfigureVimrc()
setlocal foldmethod=expr
setlocal foldexpr=getline(v:lnum)=~'^\"----------'&&getline(v:lnum+1)=~'^\"\ .'&&getline(v:lnum+2)=~'^\"----------'?'>1':1
setlocal foldtext=VimrcFoldText()
nnoremap <buffer> <Tab> za
nnoremap <buffer> <S-Tab> zM
endfunction
augroup filetype_vim
autocmd!
autocmd BufNewFile,BufRead vimrc call ConfigureVimrc()
augroup END
"-----------------------------------------------------------------------------
" vimfiler
"-----------------------------------------------------------------------------
let g:vimfiler_as_default_explorer = 1
let g:vimfiler_tree_leaf_icon = ""
let g:vimfiler_tree_opened_icon = "◿"
let g:vimfiler_tree_closed_icon = "▶"
let g:vimfiler_readonly_file_icon = "×"
let g:vimfiler_tree_indentation = 2
call vimfiler#custom#profile('default', 'context', {
\ 'safe' : 0,
\ })
function! s:toggle_tree(is_recursive) abort "{{{
let file = vimfiler#get_file(b:vimfiler)
if empty(file) || vimfiler#get_filename() == '..'
if vimfiler#get_filename() == '..'
call vimfiler#mappings#cd('..')
endif
return
endif
if !file.vimfiler__is_directory
" Search parent directory.
for cnt in reverse(range(1, line('.')-1))
let nest_level = get(vimfiler#get_file(b:vimfiler, cnt),
\ 'vimfiler__nest_level', -1)
if (a:is_recursive && nest_level == 0) ||
\ (!a:is_recursive &&
\ nest_level >= 0 && nest_level < file.vimfiler__nest_level)
call cursor(cnt, 0)
call s:toggle_tree(a:is_recursive)
break
endif
endfor
return
endif
if file.vimfiler__is_opened
call s:unexpand_tree()
else
call s:expand_tree(a:is_recursive)
endif
endfunction"}}}
function! s:expand_tree(is_recursive) abort "{{{
let cursor_file = vimfiler#get_file(b:vimfiler)
if empty(cursor_file) || vimfiler#get_filename() == '..'
if vimfiler#get_filename() == '..'
call vimfiler#mappings#cd('..')
endif
return
endif
if !cursor_file.vimfiler__is_directory
" Search parent directory.
for cnt in reverse(range(1, line('.')-1))
let nest_level = get(vimfiler#get_file(b:vimfiler, cnt),
\ 'vimfiler__nest_level', -1)
if (a:is_recursive && nest_level == 0) ||
\ (!a:is_recursive &&
\ nest_level >= 0 &&
\ nest_level < cursor_file.vimfiler__nest_level)
call cursor(cnt, 0)
call s:expand_tree(a:is_recursive)
break
endif
endfor
return
endif
if cursor_file.vimfiler__is_opened
if a:is_recursive
call s:unexpand_tree()
endif
return
endif
let cursor_file.vimfiler__is_opened = 1
" Expand tree.
let nestlevel = cursor_file.vimfiler__nest_level + 1
if a:is_recursive
let original_files = vimfiler#mappings#expand_tree_rec(cursor_file)
let files =
\ unite#filters#matcher_vimfiler_mask#define().filter(
\ copy(original_files),
\ { 'input' : b:vimfiler.current_mask })
else
let original_files =
\ vimfiler#get_directory_files(cursor_file.action__path)
for file in original_files
" Initialize.
let file.vimfiler__nest_level = nestlevel
endfor
let files =
\ unite#filters#matcher_vimfiler_mask#define().filter(
\ copy(original_files),
\ { 'input' : b:vimfiler.current_mask })
endif
if !a:is_recursive && !b:vimfiler.is_visible_ignore_files
let files = vimfiler#helper#_call_filters(
\ files, b:vimfiler.context)
endif
let index = vimfiler#get_file_index(b:vimfiler, line('.'))
let index_orig =
\ vimfiler#get_original_file_index(line('.'))
call extend(b:vimfiler.all_files, files, index+1)
call extend(b:vimfiler.current_files, files, index+1)
call extend(b:vimfiler.original_files, original_files, index_orig+1)
let b:vimfiler.all_files_len += len(files)
if b:vimfiler.context.auto_expand
\ && !a:is_recursive && len(files) == 1
\ && files[0].vimfiler__is_directory
" Expand recursive.
" call cursor(line('.') + 1, 0)
call s:expand_tree(a:is_recursive)
elseif g:vimfiler_expand_jump_to_first_child && !a:is_recursive
\ || b:vimfiler.context.auto_expand
" Move to next line.
" call cursor(line('.') + 1, 0)
endif
call vimfiler#view#_redraw_screen()
endfunction"}}}
function! s:unexpand_tree() abort "{{{
let cursor_file = vimfiler#get_file(b:vimfiler)
if empty(cursor_file) || vimfiler#get_filename() == '..'
return
endif
if !cursor_file.vimfiler__is_directory ||
\ (!has_key(cursor_file, 'vimfiler__parent')
\ && !cursor_file.vimfiler__is_opened)
" Search parent directory.
for cnt in reverse(range(1, line('.')-1))
let nest_level = get(vimfiler#get_file(b:vimfiler, cnt),
\ 'vimfiler__nest_level', -1)
if nest_level >= 0 && nest_level < cursor_file.vimfiler__nest_level
call cursor(cnt, 0)
call s:unexpand_tree()
break
endif
endfor
return
endif
if !cursor_file.vimfiler__is_opened &&
\ has_key(cursor_file, 'vimfiler__parent')
let parent_file = cursor_file.vimfiler__parent
let parent_file.vimfiler__is_opened = 0
call remove(cursor_file, 'vimfiler__parent')
for key in keys(parent_file)
let cursor_file[key] = parent_file[key]
endfor
endif
let cursor_file.vimfiler__is_opened = 0
try
setlocal modifiable
setlocal noreadonly
call setline('.', vimfiler#view#_get_print_lines([cursor_file]))
finally
setlocal nomodifiable
setlocal readonly
endtry
" Unexpand tree.
let nestlevel = cursor_file.vimfiler__nest_level
" Search children.
let index = vimfiler#get_file_index(b:vimfiler, line('.'))
let end = index
for cursor_file in b:vimfiler.current_files[index+1 :]
if cursor_file.vimfiler__nest_level <= nestlevel
break
endif
let end += 1
endfor
if end - index > 0
let index_orig = vimfiler#get_original_file_index(line('.'))
let end_orig = index_orig
for file in b:vimfiler.original_files[index_orig+1 :]
if file.vimfiler__nest_level <= nestlevel
break
endif
let end_orig += 1
endfor
" Delete children.
let b:vimfiler.all_files = b:vimfiler.all_files[: index]
\ + b:vimfiler.all_files[end+1 :]
let b:vimfiler.all_files_len += len(b:vimfiler.all_files)
let b:vimfiler.current_files = b:vimfiler.current_files[: index]
\ + b:vimfiler.current_files[end+1 :]
let b:vimfiler.original_files = b:vimfiler.original_files[: index_orig]
\ + b:vimfiler.original_files[end_orig+1 :]
let pos = getpos('.')
call vimfiler#view#_redraw_screen()
call setpos('.', pos)
endif
endfunction"}}}
function ConfigureVimfiler()
highlight link vimfilerNonMark Identifier
" Swap these two keybindings in vimfiler to something more intuitive
nmap <buffer> <nowait> o <Plug>(vimfiler_cd_or_edit)
nmap <buffer> <nowait> <Enter> <Plug>(vimfiler_expand_or_edit)
" I would rather Tab does marking than space
nmap <buffer> <nowait> <Tab> <Plug>(vimfiler_toggle_mark_current_line)
vunmap <buffer> <Space>
nunmap <buffer> <Space>
" Basic movement I don't want vimfiler to take over
nunmap <buffer> H
nunmap <buffer> L
nunmap <buffer> M
nunmap <buffer> G
" I do not like the cursor movement after expansion, and I can only
" disable that by copying and modifying the toggle_tree and expand_tree
" functions.
nnoremap <buffer><silent> <Plug>(vimfiler_expand_tree)
\ :<C-u>call <SID>toggle_tree(0)<CR>
nnoremap <buffer><silent> <Plug>(vimfiler_expand_tree_recursive)
\ :<C-u>call <SID>toggle_tree(1)<CR>
endfunction
augroup vimfiler_autos
autocmd!
autocmd FileType vimfiler call ConfigureVimfiler()
augroup END
"-----------------------------------------------------------------------------
" vim-gitgutter
"-----------------------------------------------------------------------------
let g:gitgutter_diff_args = '-w' " Don't diff the whitespace
"-----------------------------------------------------------------------------
" vim-go
"-----------------------------------------------------------------------------
let g:go_fmt_command = "goimports"
let g:go_highlight_functions = 1
let g:go_highlight_methods = 1
let g:go_highlight_fields = 1
let g:go_highlight_types = 1
let g:go_highlight_operators = 1
let g:go_highlight_build_constraints = 1
"-----------------------------------------------------------------------------
" notational-fzf-vim
"-----------------------------------------------------------------------------
let g:nv_search_paths = ["~/.deft"]
let g:nv_default_extension = '.md'
function! s:StartNV()
execute "NV"
endfunction
nnoremap <silent> <F12> :call <SID>StartNV()<cr>
nnoremap <silent> <leader>s :call <SID>StartNV()<cr>
"-----------------------------------------------------------------------------
" netrw - this comes with vim for directory exploration
"-----------------------------------------------------------------------------
let g:netrw_banner = 0
let g:netrw_liststyle = 3
let g:netrw_browse_split = 0
let g:netrw_altv = 1
let g:netrw_winsize = 20
function ConfigureNetrw()
syn match netrwBar /|/
highlight link netrwBar Comment
endfunction
augroup netrw_autos
autocmd!
autocmd FileType netrw call ConfigureNetrw()
augroup END
"-----------------------------------------------------------------------------
" vim-markdown
"-----------------------------------------------------------------------------
let g:vim_markdown_folding_style_pythonic = 1
let g:vim_markdown_auto_insert_bullets = 0
let g:vim_markdown_new_list_item_indent = 0
let g:vim_markdown_toc_autofit = 1
let g:vim_markdown_folding_level = 0
function ConfigureMarkdown()
highlight link htmlH1 Statement
highlight link htmlH2 Statement
highlight link htmlH3 Statement
highlight link htmlH4 Statement
highlight link htmlH5 Statement
highlight link htmlH6 Statement
highlight link mkdHeading Function
nnoremap <buffer> <Tab> za
nnoremap <buffer> <S-Tab> zM
syntax sync minlines=10000 " A little slower but useful for larger markdown blocks
endfunction
augroup markdown_autos
autocmd!
autocmd FileType markdown call ConfigureMarkdown()
augroup END
"-----------------------------------------------------------------------------
" open-browser
"-----------------------------------------------------------------------------
let g:netrw_nogx = 1 " disable netrw's gx mapping.
nnoremap gx <Plug>(openbrowser-smart-search)
vnoremap gx <Plug>(openbrowser-smart-search)
"-----------------------------------------------------------------------------
" yaml
"-----------------------------------------------------------------------------
function ConfigureYAML()
setlocal ts=2 sts=2 sw=2 expandtab
endfunction
augroup yaml_autos
autocmd!
autocmd FileType yaml call ConfigureYAML()
augroup END
"-----------------------------------------------------------------------------
" Rogue
" ----------------------------------------------------------------------------
let g:rogue#directory = s:vimlocaldir
let g:rogue#fruit = "strawberry"
"-----------------------------------------------------------------------------
" Easy EasyMotion
"-----------------------------------------------------------------------------
let g:EasyMotion_do_mapping = 0 " Disable default mappings
let g:EasyMotion_smartcase = 1
let g:EasyMotion_keys = 'abcdefghijklmnopqrstuvwxyz'
" Jump to anywhere you want with minimal keystrokes, with just one key binding.
" `s{char}{label}`
map <Leader><Leader> <Plug>(easymotion-bd-w)
" or
" `s{char}{char}{label}`
" Need one more keystroke, but on average, it may be more comfortable.
" nmap <Leader><Leader> <Plug>(easymotion-overwin-f2)
" JK motions: Line motions
map <Leader>j <Plug>(easymotion-j)
map <Leader>k <Plug>(easymotion-k)
"-----------------------------------------------------------------------------
" Global Keymappings
"-----------------------------------------------------------------------------
" Commenting with commentary
nmap <silent> <C-c> <Plug>CommentaryLine
vmap <silent> <C-c> <Plug>Commentary
" Mapping typical keys
noremap <PageUp>
noremap <PageDown>
noremap <Home> 0
noremap <End> $
noremap <C-Home> 1G
noremap <C-End> G$
noremap <silent> <C-d> 12j
noremap <silent> <C-u> 12k
function! RgiWithDir(search_string = "")
" User specifies a directory, we cd to it, we call :Rgi, and we cd back out.
let l:original_dir = getcwd()
let l:dir = input('Directory (default: '.l:original_dir.'): ', '', 'dir')
if l:dir != ''
execute ':cd ' . l:dir
endif
execute ":Rgi " . a:search_string
execute ':cd ' . l:original_dir
endfunction
nnoremap <silent> <leader>f yiw:call RgiWithDir("<C-r>"")<CR>
vnoremap <silent> <leader>f y:call RgiWithDir("<C-r>"")<CR>
vnoremap <silent> <leader><C-f> y:call RgiWithDir("<C-r>"")<CR>
" Fast ESC alternative in Insert mode
inoremap jk <Esc>
" Searching what is highlighted
vnoremap <leader>/ y/<C-R>"
" Like emacs occur; occur on what you last searched for
nnoremap g/ :set hlsearch<CR>:vimgrep /<C-R>//j %<CR>\|:cw<CR>
" Command line
cnoremap <C-A> <Home>
cnoremap <C-E> <End>
cnoremap <Esc>b <S-Left>
cnoremap <Esc>f <S-Right>
cnoremap <Esc><Backspace> <C-W>
cnoremap ∫ <S-Left>
cnoremap ƒ <S-Right>
cnoremap <A-Backspace> <C-W>
" Playing with vimrc
nnoremap <leader>ve :e $MYVIMRC<cr>
nnoremap <leader>vs :source $MYVIMRC<cr>
" Journaling with notational/deft
function s:GetLatestJournalEntry()
let l:all_entries = split(globpath(expand("~/.deft"), "todo-*.md"), "\n")
call sort(l:all_entries)
if len(l:all_entries) > 0
return l:all_entries[-1:-1][0]
endif
endfunction
function OpenJournal()
let l:today = strftime("%Y-%m-%d")
let l:today_journal = expand("~/.deft/todo-" . l:today . ".md")
let l:yesterday_journal = s:GetLatestJournalEntry()
if filereadable(l:today_journal)
execute "edit" l:today_journal
else
if (l:yesterday_journal !=# "0") && filereadable(l:yesterday_journal)
let l:yesterday_content = readfile(l:yesterday_journal, "b")
call writefile(l:yesterday_content, l:today_journal, "b")
execute "edit" l:today_journal
call deletebufline(bufname("%"), 1, 1)
else
execute "edit" l:today_journal
endif
call appendbufline(bufname("%"), 0, "TODO:" . l:today)
execute "write"
endif
endfunction
command! -nargs=0 OpenJournal call OpenJournal()
nnoremap <silent> <leader>l :OpenJournal<cr>
" Fast searching with rg and fzf
function! s:HandleRgSelection(lines) abort
let l:file_info = split(a:lines[2], ":")
execute("edit " . l:file_info[0])
execute("normal! " . l:file_info[1] . "G")
endfunction
command! -nargs=1 -bang Rg grep <args> *
command! -nargs=* -bang Rgi
\ call fzf#run(
\ fzf#wrap({
\ 'sink*': function('<SID>HandleRgSelection'),
\ 'window': 'edit',
\ 'source': join([
\ 'rg',
\ '--follow',
\ '--smart-case',
\ '--line-number',
\ '--color never',
\ '--no-messages',
\ '--no-heading',
\ '--with-filename',
\ '""',
\ '2>/dev/null',
\ ]),
\ 'down': '40%',
\ 'options': join([
\ '--query ' . ((<q-args> is '') ? '""' : shellescape(<q-args>)),
\ '--print-query',
\ '--ansi',
\ '--multi',
\ '--exact',
\ '--inline-info',
\ '--delimiter=":"',
\ '--with-nth=' . '3..',
\ '--tiebreak=' . 'length,begin' ,
\ '--expect=' . 'ctrl-s,ctrl-v,ctrl-t',
\ '--bind=' . join([
\ 'alt-a:select-all',
\ 'alt-q:deselect-all',
\ 'alt-p:toggle-preview',
\ 'alt-u:page-up',
\ 'alt-d:page-down',
\ 'ctrl-w:backward-kill-word',
\ ], ','),
\ '--preview="echo {} | awk -F: ''{print \$1 \" -H \" \$2 \" -r \" (\$2 < 10 ? 0 : (\$2 - 10)) \":\" (\$2 + 10)}'' | xargs bat -f 2>/dev/null || true"',
\ '--preview-window=' . join(filter(copy([
\ 'right',
\ ]),
\ 'v:val != "" ')
\ ,':')
\ ])},<bang>0))
" Easier formatting
function FormatOrIndent()
normal! ml
let l:attrName = synIDattr(synIDtrans(synID(line("."), col("."), 1)), "name")
if l:attrName ==# "Comment"
call SyntaxVisualSelect('b')
normal! gq
elseif l:attrName ==# "" || &ft ==# "" || &ft ==# "gitcommit"
normal! gqip
elseif &ft ==# "lisp"
normal! =ap
elseif &ft ==# "perl" && executable("perltidy")
execute "normal! VaB:!perltidy -q\<cr>"
else
normal! ml=aB
endif
normal! `l
endfunction
inoremap <silent> <Esc>q <Esc>:call FormatOrIndent()<CR>a
nnoremap <silent> <Esc>q :call FormatOrIndent()<CR>
vnoremap <silent> <Esc>q :call FormatOrIndent()<CR>
inoremap <silent> œ <Esc>:call FormatOrIndent()<CR>a
nnoremap <silent> œ :call FormatOrIndent()<CR>
vnoremap <silent> œ :call FormatOrIndent()<CR>
" Tab navigation
function CustomPreviousTab()
bp
endfunction
function CustomNextTab()
bn
endfunction
function CustomNewTab()
new
endfunction
nnoremap <silent> <Esc>k :call CustomPreviousTab()<cr>
nnoremap <silent> <Esc>j :call CustomNextTab()<cr>
nnoremap <silent> <Esc>c :if len(getwininfo()) ==# 1<cr>bd!<cr>else<cr>q!<cr>endif<cr>
nnoremap <silent> <Esc>n :call CustomNewTab()<cr>
nnoremap <Esc>t :tabnew<space><C-R>=expand("%:p")<cr>
nnoremap Q :echo "I just saved you from Q"<cr>
noremap gV `[v`]
onoremap s t_
" Navigation through one of the lists
let g:quickfix_or_location_navigation = 'quickfix'
function ToggleQuickfixOrLocationList()
if g:quickfix_or_location_navigation ==# 'quickfix'
let g:quickfix_or_location_navigation = 'location'
echo "Using location list for <C-k> and <C-j> navigation"
else
let g:quickfix_or_location_navigation = 'quickfix'
echo "Using quickfix list for <C-k> and <C-j> navigation"
endif
endfunction
function NextQuickfixOrLocationList()
try
if g:quickfix_or_location_navigation ==# 'quickfix'
cnext
else
lnext
endif
catch /^Vim\%((\a\+)\)\=:E42:/
echo "Empty " . g:quickfix_or_location_navigation . " list"
catch /^Vim\%((\a\+)\)\=:E776:/
echo "No more items in " . g:quickfix_or_location_navigation . " list"
catch /^Vim\%((\a\+)\)\=:E553:/
echo "No more items in " . g:quickfix_or_location_navigation . " list"
endtry
endfunction
function PrevQuickfixOrLocationList()
try
if g:quickfix_or_location_navigation ==# 'quickfix'
cprevious
else
lprevious
endif
catch /^Vim\%((\a\+)\)\=:E42:/
echo "Empty " . g:quickfix_or_location_navigation . " list"
catch /^Vim\%((\a\+)\)\=:E776:/
echo "No more items in " . g:quickfix_or_location_navigation . " list"
catch /^Vim\%((\a\+)\)\=:E553:/
echo "No more items in " . g:quickfix_or_location_navigation . " list"
endtry
endfunction
nnoremap <silent> <Leader>n :call ToggleQuickfixOrLocationList()<cr>
nnoremap <silent> <C-k> :call PrevQuickfixOrLocationList()<cr>
nnoremap <silent> <C-j> :call NextQuickfixOrLocationList()<cr>
" Easy way to fill the llist with Coc diagnostics
nnoremap <silent> <C-h> :CocDiagnostics<cr><C-w>c:lfirst<cr>
" Inserting markdown
nnoremap <silent> <leader>` o<CR>```<CR>```<CR><Esc>kO<Esc>
" Integrate with github browsing
function! GithubBrowse() range
execute ':!gh browse ' . expand('%') . ':' . a:firstline . '-' . a:lastline
endfunction
nnoremap <silent> <leader>gl :call GithubBrowse()<cr>
vnoremap <silent> <leader>gl :call GithubBrowse()<cr>
function! SplitSeries()
let l:line = getline(".")
" Handle splitting on Elixir pipes
if l:line =~ "|>"
let l:indention = matchstr(l:line, '^\s*')
if substitute(l:line, "|>.*$", "", "") =~ "="
let l:indention = l:indention . " "
silent execute 's/=\s*/=' . l:indention . '/'
endif
silent execute 's/\s*|>\s*/' . l:indention . '|> /g'
endif
endfunction
nnoremap <silent> gS :call SplitSeries()<cr>
function! PrefixElixirPipe()
let [l:bufnum, l:lnum, l:col, l:off] = getpos('.')
normal! ^
let [l:bufnum_start, l:lnum_start, l:col_start, l:off_start] = getpos('.')
normal! i|>
if l:col_start < l:col
call setpos('.', [l:bufnum, l:lnum, l:col + 3, l:off])
else
call setpos('.', [l:bufnum, l:lnum, l:col, l:off])
endif
endfunction
noremap <silent> <C-\> :call PrefixElixirPipe()<cr>
nnoremap <silent> <Leader>i o\|> IO.inspect(limit: :infinity)<Esc>
"-----------------------------------------------------------------------------
" Autocommands
"-----------------------------------------------------------------------------
set viewoptions-=options
augroup vimrc
autocmd!
autocmd BufWinLeave *.md
\ if expand('%') != '' && &buftype !~ 'nofile'
\| mkview!
\| endif
autocmd BufWinEnter *.md
\ if expand('%') != '' && &buftype !~ 'nofile'
\| silent loadview
\| endif
augroup END
" If the buffer is in viminfo, go to the last recorded cursor position
" Configure mail buffers (especially for mutt usage)
function! ConfigureMail()
set ft=mail
set shiftwidth=2
set tabstop=2
set textwidth=70
set spell spelllang=en_us
endfunction
" Go files require a specific standard
function! ConfigureGo()
set noexpandtab
set nolist
endfunction
function! ConfigureTypescript()
set shiftwidth=2
set tabstop=2
endfunction
function! ConfigureElixir()
nnoremap <buffer> <silent> K :call CocAction('doHover')<CR>
endfunction