-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvimrc
More file actions
1038 lines (873 loc) · 37.5 KB
/
vimrc
File metadata and controls
1038 lines (873 loc) · 37.5 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
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Author: Manas (weirdsmiley) <manas18244 at iiitd dot ac dot in>
" Last Changed: June 23, 2022
"
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Archlinux's global vimrc: /usr/share/vim/vimfiles/archlinux.vim
" ! makes Vim source all found files
" runtime! archlinux.vim
" Man command in Vim: /usr/share/vim/vim82/ftplugin/man.vim
" Use: :Man fork
runtime ftplugin/man.vim
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Differing from Vi-compatibility; its setting affects a lot of other options
set nocompatible
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Remap leader key to comma(,)
" SUGGESTION: Consider better key for Leader
let mapleader = ','
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Autocompletion
" longest: complete till longest common string
" list: if more than one match, list all matches
" full: complete next full match
set wildmode=longest,list,full
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Orientation of tab and pane of man page, when opened
" options available: 'vert'(vsplit) and 'tab'(tabedit)
" from /usr/share/vim/vim82/ftplugin/man.vim :171
let g:ft_man_open_mode = 'vert'
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Setting local leader to backslash(\)
" To be used for mappings which are local to a buffer
" map.txt suggests <Leader> should be used for global plugin and
" <LocalLeader> in a filetype plugin
" SUGGESTION: Consider better key for LocalLeader
let maplocalleader = "\\"
" Disable Ex-mode FFS!
nnoremap Q <NOP>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Time out on mappings
set timeout
" Time out on keycodes
set ttimeout
" Set timeout to 500 ms
set timeoutlen=300
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Orientation of opened windows
" Split a window below and right side(vsplit) always
set splitbelow splitright
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Open help on right window
" WORK: Does not work more than once in same instance
autocmd FileType help wincmd L
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Vim-plug Settings
call plug#begin()
Plug 'JuliaEditorSupport/julia-vim'
Plug 'fatih/vim-go'
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'junegunn/fzf.vim'
Plug 'lervag/vimtex'
Plug 'mbbill/undotree'
Plug 'ajmwagar/vim-deus'
Plug 'ludovicchabant/vim-gutentags'
Plug 'morhetz/gruvbox'
Plug 'neoclide/coc.nvim', {'branch': 'release', 'for': ['rust', 'erlang'], 'do': 'yarn install --frozen-lockfile'}
Plug 'preservim/nerdcommenter'
Plug 'preservim/nerdtree'
Plug 'rhysd/vim-llvm'
Plug 'rust-lang/rust.vim'
Plug 'ryanoasis/vim-devicons'
Plug 'stsewd/fzf-checkout.vim'
Plug 'tpope/vim-surround'
Plug 'vim-airline/vim-airline'
Plug 'ycm-core/YouCompleteMe'
Plug 'tomlion/vim-solidity'
Plug 'felipec/notmuch-vim'
Plug '~/.vim/plugged/para.vim'
Plug '~/.vim/plugged/vim-draw'
Plug '~/.vim/plugged/vim-math'
Plug '~/.vim/plugged/vim-schedule-highlight'
Plug '~/.vim/plugged/example-plugin'
" For Testing (Nvim-R)
Plug 'jalvesaq/Nvim-R', {'branch': 'stable'}
call plug#end()
set rtp+=~/.fzf
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" WORK: Add comment; arrange plugins
" Load plugins here (pathogen or vundle)
" execute pathogen#infect()
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Syntax highlighting
" 'syntax enable' keeps current color setting while 'syntax on' overrides
" user settings with defaults
syntax enable
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Wrap long lines
" Automatically wrap text that extends beyond the screen length.
set wrap
" Wrap lines at character in 'breakat'(string) instead of last character
" that fits on screen
set linebreak
" Indent wrapped lines
set breakindent
" Shift wrapped lines by 4 spaces
set breakindentopt=shift:4
" Remap movements keys when wrapping in on
" eg. j → gj, k → gk
" Ack: https://vimtricks.com/p/word-wrapping/
let s:wrapenabled = 0
function! ToggleWrap()
set wrap nolist " nolist disables whitespace chars being visible
if s:wrapenabled
unmap j
unmap k
unmap 0
unmap ^
unmap $
let s:wrapenabled = 0
else
nnoremap j gj
nnoremap k gk
nnoremap 0 g0
nnoremap ^ g^
nnoremap $ g$
vnoremap j gj
vnoremap k gk
vnoremap 0 g0
vnoremap ^ g^
vnoremap $ g$
let s:wrapenabled = 1
endif
endfunction
nnoremap <Leader>s :call ToggleWrap()<CR>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Filetype settings
filetype on
filetype plugin indent on
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Tab settings
" Number of spaces <Tab> counts for
set tabstop=2
" Count of spaces <Tab> counts for while editing
set softtabstop=2
" Spaces used for every indentation by >> <<
set shiftwidth=2
" On pressing tab, insert 4 spaces
set expandtab
" Round indent to multiple of width
set shiftround
" Special case for rust files (:meh)
autocmd FileType rust set tabstop=4 | set softtabstop=4 | set shiftwidth=4
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Auto read when a file is changed outside of Vim
set autoread
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Hybrid line numbering
set relativenumber number
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Case matching while searching
"""""""""""""""""""""""""""""""
" case-sensitive pattern matching
set ignorecase
" override ignorecase if search regex contains mixed-case
set smartcase
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Keep 5 lines off edge while scrolling
set scrolloff=5
" Smooth scrolling
" map <C-U> <C-Y><C-Y><C-Y><C-Y><C-Y><C-Y><C-Y><C-Y><C-Y><C-Y><C-Y><C-Y>
" map <C-D> <C-E><C-E><C-E><C-E><C-E><C-E><C-E><C-E><C-E><C-E><C-E><C-E>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" copy at least n last messages from :messages
function! CTCFromMessages(n)
" It copies last n messages from :messages to the clipboard ('+' register)
" TODO: Do I need last n or just last?
execute "redir @+"
execute "1message"
execute "redir END"
silent echo "CTCFromMessages: copied " . a:n . " messages"
endfunction
nnoremap CC :call CTCFromMessages(1)<CR>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Switch buffers without saving
set hidden
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Search settings
set hlsearch
set incsearch
" Show search number
set shortmess-=S
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Remove search highlights
nnoremap <silent> <leader><space> :noh<cr>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Improve smoothness of redrawing
set ttyfast
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Remap movement keys when wrapping is on
" augroup OnWrapMovements
" au!
" autocmd Filetype tex,markdown map j gj
" autocmd Filetype tex,markdown map k gk
" augroup END
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Save current buffer (VERY STUPID MAPPING, BUT I LIKE IT)
nnoremap <leader>w :w<CR>
nnoremap <leader>q :q<CR>
" Exit Vim after deleting all buffers (unsaved)
nnoremap ZQ :%bd\|q<CR>
" Disable W & Q in Command-mode
" cnoremap W<CR> w<CR>
" cnoremap Q<CR> q<CR>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" WORK: Tons of editing needed
" entering special chars
" for ä - a <BS> :
" for ǎ - a <BS> <
" <BS> = backspaceFiletype
" although, use <C-k>, <C-v> if not a touch typist
"set dg
" enable xterm_clipboard for outside vim copying/pasting
" only if vim --version | grep xterm_clipboard
" return +xterm_clipboard
" set clipboard=unnamedplus
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" .viminfo stores information about windows at closing which can be used while
" reopening those files
set viminfo='10,<100,:100,%,n~/.vim/.viminfo
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Do not put message about the current mode on bottom line
set noshowmode
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Partial command on bottom right corner of screen
set showcmd
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Show tabline always
set showtabline=2
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Character encoding
set encoding=utf-8
set fileencoding=utf-8
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Font settings
if has("gui_running")
set guifont=Inconsolata\ 16
else
set guifont=DroidSansMono\ Nerd\ Font\ 16
endif
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Theme settings
" Colorscheme
colorscheme gruvbox
" Set dark mode
set background=dark
" Status line color
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Characters to fill the statuslines and vertical separators
set fillchars+=vert:┆
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Normally, Vim destroys tree of undos when a buffer is deleted.
" Persistent undo: enable Vim to keep undo changes for all files even
" after unloading a buffer.
set undofile
set undolevels=5000
set undodir=~/.vim/undodir/
" Ack: Lifepillar
command! -nargs=0 CleanUpUndoFiles !find ~/.vim/undodir -type f -mtime 100 -delete
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Undotree settings
" =================
nnoremap <F5> :UndotreeToggle<cr>
if !exists('g:undotree_WindowLayout')
let g:undotree_WindowLayout = 2
endif
let g:undotree_SetFocusWhenToggle = 1
let g:undotree_TreeNodeShape = '≫'
let g:undotree_TreeVertShape = '│'
let g:undotree_HighlightChangedText = 1
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Status line be always visible
set laststatus=2
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" NERDTree Configurations
" =======================
" Toggle NERDTree window
map <leader>n :NERDTreeToggle<CR>
" Quick close NERDTree after opening a file
let NERDTreeQuitOnOpen = 1
" Expanding arrows
let g:NERDTreeDirArrowExpandable = '➤'
let g:NERDTreeDirArrowCollapsible = '⮩ '
" Disable hijacking
let g:NERDTreeHijackNetrw = 0
" Store bookmarks
let NERDTreeBookmarksFile=expand("$HOME/.vim/NERDTreeBookmarks")
" Show bookmarks table
let NERDTreeShowBookmarks=1
" Highlight cursor line in NERDTree window
let NERDTreeHighlightCursorline=1
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" NERDCommenter configurations
" ============================
" Add a whitespace around comment delimiters
let g:NERDSpaceDelims = 1
" Use compact syntax for prettified multi-line comments
let g:NERDCompactSexyComs = 1
" Align line-wise comment delimiters flush left instead following code indent.
let g:NERDDefaultAlign = 'left'
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Compiling and executing various source codes
" ============================================
" SUGGESTION: try doing if binary exists without change then dont compile again
" Opening a popup win for running programs
" function! TerminalPopupWin()
" let s:filename = expand('%')
" let s:cmdlist = './a.out'
" let buf = term_start(s:cmdlist, #{hidden: 1, term_finish: 'open'})
" echom s:cmdlist
" let winid = popup_create(buf, #{minwidth: 120, minheight: 26})
" endfunction
" Compile and run cpp code
autocmd FileType cpp nnoremap <Leader>l :w <bar> !clear && clang++ -g % && echo "done compiling" && echo "running..." && ./a.out<cr>
autocmd FileType cpp nnoremap ;l :w <bar> !clear && clang++ -g -fstandalone-debug % && gdb ./a.out<cr>
" Compile and run c code
autocmd FileType c nnoremap <Leader>l :w <bar> !clear && gcc -g % && echo "done compiling" && echo "running..." && ./a.out<cr>
autocmd FileType c nnoremap ;l :w <bar> !clear && gcc -g % && gdb ./a.out<cr>
" Compiler and run Fortran code
autocmd Filetype fortran nnoremap <Leader>l :w <bar> :!clear && gfortran % && echo "done compiling" && echo "running..." && ./a.out<cr>
" Interpret python code
autocmd Filetype python nnoremap <Leader>l :w <bar> !clear && python %<cr>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Building various markup language files
" ======================================
" Compile a markdown file and open it in a pdf viewer
" SUGGESTION: Not compiling if unchanged file
function! Compile_Open_MD()
" compile using pandoc
let pdfname = expand(expand('%:t:r') . ".pdf")
execute '!echo "Generating pdf..." && pandoc % -o ' . pdfname . ' --table-of-contents --pdf-engine=xelatex --indented-code-classes=c --highlight-style=tango -V documentclass=report -V papersize=A5 -V colorlinks -V urlcolor=NavyBlue -V toccolor=NavyBlue -V geometry:"top=1cm, bottom=1.5cm, left=1cm, right=1cm" > /dev/null 2>&1 '
" open using okular
execute 'silent !okular ' . pdfname . ' &> /dev/null &'
" redraw vim windows after opening the pdf
redraw!
endfunction
" Compile a LaTex file and open it in a pdf viewer
" SUGGESTION: Collect all log files in a directory in cwd
function! Compile_Open_Latex()
" compile using pdflatex
let pdfname = expand(expand('%:t:r') . ".pdf")
execute '!echo "Generating pdf..." && pdflatex -interaction nonstopmode % -o ' . pdfname . ' > /dev/null 2>&1 '
" open using okular
execute 'silent !okular ' . pdfname . ' &> /dev/null &'
" redraw vim windows after opening the pdf
redraw!
endfunction
" Augroup for mappings which control compilation for various files
augroup CompileController
au!
autocmd FileType markdown nnoremap <Leader>l :call Compile_Open_MD()<cr>
autocmd FileType tex nnoremap <Leader>l :call Compile_Open_Latex()<cr>
augroup END
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Resize current buffer
" =====================
" Change size by +10
nnoremap ]= :res +10<cr>
" Change size by -10
nnoremap ]- :res -10<cr>
" resize vertically
nnoremap [= :vert res +10<cr>
nnoremap [- :vert res -10<cr>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" If < 4 buffers are opened in current window then power mapping maps each
" buffer to <Function> keys (F1, F2, F3, F4)
function! MapBuffers()
let s:buffers_list = filter(range(1, bufnr('$')), 'buflisted(v:val)')
let s:buffers_count = len(s:buffers_list)
if s:buffers_count > 4
echo "More than 4 buffers! I am not programmed for this."
else
" loop through elements of buffers_list and exec nnoremap
let idx = 1
for buf in s:buffers_list
execute "nnoremap <F" . idx . "> :" . buf . "b<CR>"
let idx += 1
endfor
echo "Mapped buffers to Function keys."
endif
endfunction
" Power mapping : map buffers to respective function keys
nnoremap <leader>mm :call MapBuffers()<CR>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Change terminal's colors
" SUGGESTION: Fix directory colors in terminal
" hi Terminal ctermbg=black ctermfg=white guibg=black guifg=white
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Movements between different tabs made easy
nnoremap <C-h> :tabprev<CR>
nnoremap <C-l> :tabnext<CR>
" Inside terminal mode
tnoremap <C-h> <C-w>:tabprev<CR>
tnoremap <C-l> <C-w>:tabnext<CR>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Open terminal vertically in split pane
nnoremap tt :vertical terminal<CR>
" Setting terminal size to 24x80; prevents terminal resizing if other panes
" are resized and terminal's data getting lost
set termwinsize=0*80
" Open terminal in a new tab
" nnoremap TT :tab terminal ++close<CR>
function! OpenTerminalInNewTab()
" For mapping <F1> to Terminal tab and last tab
" for moving back and forth
execute "tab terminal ++close"
" execute "tmap <F1> <C-w>gt"
set termwinsize=
set termwinsize=0*80
" Do we need these? vvvvvvvvv
" execute "normal! <F1>"
" execute "nmap <F1> <C-w>gt"
" execute "normal! <F1>"
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^
endfunction
nnoremap TT :call OpenTerminalInNewTab()<CR>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Quick open ~/.vimrc
" Using global marks: Just add a global mark like mV (mark .vimrc) and reach
" here via 'V
" Ack: VimTricks:Bookmark frequent locations
nnoremap <leader>ev :vsp $MYVIMRC<CR>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Configurations for Rust
" =======================
" Disable default style recomm (tabs=4, textwidth=99)
let g:rust_recommended_style = 0
" Enable folding
let g:rust_fold = 1
" URL for rust playground
let g:rust_playpen_url = 'https://play.rust-lang.org/'
" Compiling and running code
" BIG ERROR: Opening different filetypes in vertical split, <Leader>l doesn't
" run appropriate commands, mixes up with other pane's filetype
autocmd FileType rust nnoremap <Leader>l :RustRun!<cr>
" redefine RustPlay cmd with copying the URL and opening in firefox tab
function! RustPlayRedefined()
let URL = split(execute("RustPlay"), " ")
silent exec "!firefox --new-tab '".URL[1]."'"
redraw!
endfunction
autocmd Filetype rust nnoremap <LocalLeader>l :call RustPlayRedefined()<CR>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Configurations for vimtex
" =========================
" Activate vimtex for latex files with tex filetype
let g:tex_flavor = 'latex'
" Autocompletion
let g:vimtex_complete_enabled = 1
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Skeletons Templates
function! Skel(which_dir, which_template)
let l:curr_pwd = getcwd()
if curr_pwd[0:len(a:which_dir)-1] ==# a:which_dir
if a:which_template ==# 'cpp'
silent! execute '0r ~/.vim/templates/skeleton_cp.cpp'
17
elseif a:which_template ==# 'latex'
silent! execute '0r ~/.vim/templates/skeleton_latex.tex'
execute "set filetype=tex"
30
elseif a:which_template ==# 'c'
silent! execute '0r ~/.vim/templates/skeleton_c.c'
5
elseif a:which_template ==# 'rust'
silent! execute '0r ~/.vim/templates/skeleton_rust.rs'
5
elseif a:which_template ==# 'java'
silent! execute '0r ~/.vim/templates/skeleton_java.java'
6
endif
endif
endfunction
" FIXME: Major improvements needed!
augroup Templates
au!
au BufNewFile *.cpp call Skel('/home/neon/workspace/codechef', 'cpp')
au BufNewFile *.cpp call Skel('/home/neon/workspace/codeforces', 'cpp')
au BufNewFile *.cpp call Skel('/home/neon/workspace/codejam', 'cpp')
au BufNewFile *.cpp call Skel('/home/neon/workspace/foobarcp', 'cpp')
au BufNewFile *.cpp call Skel('/home/neon/workspace/hashcode', 'cpp')
au BufNewFile *.tex call Skel('/home/neon', 'latex')
au BufNewFile *.c call Skel('/home/neon', 'c')
au BufNewFile *.rs call Skel('/home/neon/workspace/codeforces', 'rust')
au BufNewFile *.java call Skel('/home/neon', 'java')
augroup END
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" add current time while hitting enter key in insert mode
" useful while note-taking etc.
" for buffer local mappings :
" if timestamping is needed only in one buffer, define function in
" command-mode, and use
" :inoremap <buffer> <CR> <ESC>:call PrependTime()<CR>A
" to define buffer-local map
"
" another way is to use Funcref `:h Funcref`
" but this way throws some error of refer. not found in other buffers
"
" If have multiple dynamic variables for each template file which need to be
" updated:
" For e.g.
" Name: <AUTHOR>
" Date: <TODAY>
" etc
"
" :%s/<\([^>]*\)>/\=get({'TODAY':strftime('%c'), 'AUTHOR':$USER}, submatch(1), submatch(1))
"
" function PrependTime(which_dir)
" let l:curr_pwd = getcwd()
" if curr_pwd[0:len(a:which_dir)-1] ==# a:which_dir
" r !printf '[' && date | awk '{printf $5}' && printf '] '
" " execute 'normal A'
" endif
" endfunction
" au FileType markdown inoremap <ENTER> <ESC>:call PrependTime('/home/neon/workspace/notes')<cr>A
"
"
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Custom syntax highlighting for ~/workspace/notes/ -- MOVED TO ~/w/notes/ dir.
" autocmd BufNewFile,BufRead ~/workspace/notes/* source ~/workspace/notes/syntax.vim
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Turn off relative numbering when buffer loses focus
" Ack: https://github.com/jeffkreeftmeijer/vim-numbertoggle
augroup numbertoggle
au!
au BufEnter,FocusGained,WinEnter * if &number | set relativenumber | endif
au BufLeave,FocusLost,WinLeave * if &number | set norelativenumber | endif
augroup END
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Don't go outside 80 chars in a line
augroup Overflow80
au!
" Set border when entering insert mode
au InsertEnter *.txt,*.md,*.c,*.cpp,*.py,*.java,*.scala,*.rs,*.sh set colorcolumn=80 | set textwidth=80
" Unset border before leaving insert mode
au InsertLeave *.txt,*.md,*.c,*.cpp,*.py,*.java,*.scala,*.rs,*.sh set colorcolumn=
augroup END
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Switch to alternate file (if available)
nnoremap <Leader>. <C-^>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Add '=' or '-' below the title line in insert mode
au FileType text,markdown inoremap <buffer> === <ESC>kyypV:s/./=/g<cr>:noh<cr>o
au FileType text,markdown inoremap <buffer> --- <ESC>kyypV:s/./-/g<cr>:noh<cr>o
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" When using codeblocks inside a markdown file, use the syntax coloring for
" that particular language
let g:markdown_fenced_languages = ['c', 'python', 'rust', 'java',
\ 'javascript', 'js=javascript', 'xml', 'html', 'css', 'ruby', 'erlang', 'scala',
\ 'vim']
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Modeline disabled ( Vulnerability: CVE-2019-12735 )
set modeline
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" play chess using chs and stockfish engine
" Any way to increase buffer-local font size change
" Or zoom
" Look for +xfontset option in vim
function! PlayChess()
if has('terminal')
let level = input('Which Level? (1-8) ', '1')
" execute ":vertical terminal ++close chs level=" . level
highlight TermChess ctermfg=15 ctermbg=0 guifg=white guibg=black
let term_buffer = term_start("chs level=" . level, {"term_name":"Chess", "term_rows":40, "term_cols":60, "vertical":1, "curwin":0, "norestore":1, "term_finish":"close", "term_highlight":"TermChess"})
endif
endfunction
" Controller
map <leader>pc :call PlayChess()<cr>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Ctrl-p configurations
" =====================
" Initializing plugin
" set runtimepath^=~/.vim/bundle/ctrlp.vim
" Customize mappings
" let g:ctrlp_map = '<c-p>'
" let g:ctrlp_cmd = 'CtrlP'
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" FZF Configurations
" ==================
" Key mappings
" ============
" Enable :Files or :GFiles based on if .git/ exists or not
function! MainFZF()
if finddir(".git") ==# ".git"
" nmap <buffer> <silent> <C-p> :GFiles<CR>
execute "GFiles"
else
" nmap <buffer> <silent> <C-p> :Files<CR>
execute "Files"
endif
endfunction
nnoremap <C-p> :call MainFZF()<CR>
" Open FZF Window in the middle instead of bottom
let g:fzf_layout = { 'window' : { 'width' : 0.8, 'height' : 0.8 } }
" Reverse the list; gitfiles at top
let $FZF_DEFAULT_OPTS='--reverse'
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Gutentags configurations
" ========================
" Force update current tag file with current buffer
nnoremap <LocalLeader>g :GutentagsUpdate<CR>
" Update current tag file for whole project
" nnoremap <LocalLeader>g :GutentagsUpdate!<CR>
" Enable gutentags
let g:gutentags_enabled = 0
" For debugging purposes (:GutentagsToggleTrace)
let g:gutentags_define_advanced_commands = 1
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Open URLs in default browser
" ERROR: Not working-
" 1. when "URL" : Takes the latter " along with URL
" 2. when (URL) : Takes ) along with URL
" 3. when (URL). : Takes ). along with URL
" function! HandleURL()
" let s:url = join(split(matchstr(getline("."), '[a-z]*:\/\/[^ >,;]*'), "#"), "\\#")
" echo s:url
" if s:url != ""
" " silent exec "!xdg-open '".s:url."'"
" silent exec "!firefox --new-tab '".s:url."'"
" redraw!
" else
" echo "No URL found in line."
" endif
" endfunction
function! HandleURL()
let s:uri = matchstr(getline("."), '[a-z]*:\/\/[^ >,;()]*')
let s:uri = shellescape(s:uri, 1)
echom s:uri
if s:uri != ""
silent exec "!firefox --new-tab '".s:uri."'"
:redraw!
else
echo "No URL found in line."
endif
endfunction
" Scrape the visual-selected text in the buffer
" Return as a string
" Ack: https://stackoverflow.com/a/6271254/11038150
function! s:get_visual_selection()
" Why is this not a built-in Vim script function?!
let [line_start, column_start] = getpos("'<")[1:2]
let [line_end, column_end] = getpos("'>")[1:2]
let lines = getline(line_start, line_end)
if len(lines) == 0
return ''
endif
let lines[-1] = lines[-1][: column_end - (&selection == 'inclusive' ? 1 : 2)]
let lines[0] = lines[0][column_start - 1:]
return join(lines, "\n")
endfunction
" Search the visually-selected text in a new-tab of firefox via duckduckgo
function! VizSearchFF()
let s:keyword = s:get_visual_selection()
if s:keyword !~# "^https://"
silent exec "!firefox --new-tab 'https://www.google.com/search?q=".s:keyword."'"
redraw!
else
call HandleURL()
echo "Via VIZ"
endif
endfunction
nnoremap gx :call HandleURL()<cr>
vnoremap gx :call VizSearchFF()<cr>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Presentation and Creative Mode (for drawing diagrams and ASCII texts
" purposes
nmap <LocalLeader>b :.!toilet -w 200 -f term -F border<CR>
" check if a bash command exists or not
nmap <LocalLeader>f :.!toilet -w 200 <CR>
nmap <LocalLeader>b :.!toilet -w 200 -f term -F border<CR>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" TEST: Function for counting pattern occurence in a line
function! Count_Occurence(matchstr)
let curpos = getcurpos()
let curline = getline(curpos[1])
let colno = 0
let counter = 0
while colno < curpos[2]
if curline[colno] =~ a:matchstr
let counter += 1
endif
let colno += 1
endwhile
echo "Count is " . counter
endfunction
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" YouCompleteMe Configurations
" ============================
" Disable YCM for rust filetypes (using CoC)
let g:ycm_filetype_blacklist = {'rust': 1, 'erlang': 1}
" Jump to definitions
nnoremap <silent> gd :YcmCompleter GoToDefinition<CR>
" Jump to declarations
nnoremap <silent> <LocalLeader>gd :YcmCompleter GoToDeclaration<CR>
" Show all references
nnoremap <silent> gr :YcmCompleter GoToReferences<CR>
" Rename the literal
nnoremap <silent> <LocalLeader>rr :YcmCompleter RefactorRename<SPACE>
" Disable limit for maximum diagnostics to show
let g:ycm_max_diagnostics_to_display = 20
" clangd fully controlling code completion
" 0 : use clangd's caching and filtering algorithm
" TODO: Check for diffs
let g:ycm_clangd_uses_ycmd_caching = 0
" Using system-installed clangd, not YCM-bundled
let g:ycm_clangd_binary_path = exepath("clangd")
" Disable clangd for larger files
let g:disable_for_files_larger_than_kb = 2000
" Open GoTo* files into different buffers
let g:ycm_goto_buffer_command = 'same-buffer'
" Locate the global extra configurations files
" It will allow Ycm to pass LSP arguments to appropriate servers.
let g:ycm_global_ycm_extra_conf = '/home/neon/.config/youcompleteme-conf/ycm_extra_conf.py'
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" CoC Configurations
""""""""""""""""""""
" Separated all those configurations to not let it interfere with Ycm
autocmd Filetype rust,erlang runtime coc-conf.vim
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Airline configurations
" ======================
" Define dictionary to store symbols
if !exists('g:airline_symbols')
let g:airline_symbols = {}
endif
" Status bar color
let g:airline_theme='dark'
" Add symbols for customization
let g:airline_left_sep = ''
let g:airline_left_alt_sep = ''
let g:airline_right_sep = ''
let g:airline_right_alt_sep = ''
let g:airline_detect_modified=1
let g:airline_detect_paste=1
let g:airline_detect_crypt=1
let g:airline_detect_spell=1
let g:airline_inactive_collapse=1
let g:airline_inactive_alt_sep=1
let g:airline_symbols.branch = ''
let g:airline_symbols.readonly = ''
let g:airline_symbols.linenr = '☰'
let g:airline_symbols.maxlinenr = ''
let g:airline_symbols.dirty='⚡'
" Using powerline symbols
let g:airline_powerline_fonts = 1
" Few more options
let g:airline#extensions#tabline#enabled = 1
let g:airline#extensions#ycm#enabled = 1
let g:airline#extensions#ycm#error_symbol = 'E:'
let g:airline#extensions#ycm#warning_symbol = 'W:'
let g:airline#extensions#tabline#formatter = 'default'
" let g:airline#extensions#coc#enabled = 0
" let airline#extensions#coc#error_symbol = 'Error:'
" let airline#extensions#coc#warning_symbol = 'Warning:'
" let airline#extensions#coc#stl_format_err = '%E{[%e(#%fe)]}'
" let airline#extensions#coc#stl_format_warn = '%W{[%w(#%fw)]}'
let g:airline#extensions#lsp#progress_skip_time = 0
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Replace command
com -range=% -nargs=1 P exe "<line1>,<line2>!".<q-args> |y|sil u|echom @"
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" LLVM IR and related configurations
" ==================================
" TODO: