-
Notifications
You must be signed in to change notification settings - Fork 0
/
.vimrc
1710 lines (1469 loc) · 62.2 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
" Modeline and Notes {
" vim: set sw=4 ts=4 sts=4 et tw=78 foldmarker={,} foldlevel=0 foldmethod=marker spell:
"
" __ _ _____ _
" ___ _ __ / _/ |___ / __ __(_)_ __ ___
" / __| '_ \| |_| | |_ \ _____\ \ / /| | '_ ` _ \
" \__ \ |_) | _| |___) |_____|\ V / | | | | | | |
" |___/ .__/|_| |_|____/ \_/ |_|_| |_| |_|
" |_|
"
" This is the personal .vimrc file of Steve Francia.
" While much of it is beneficial for general use, I would
" recommend picking out the parts you want and understand.
"
" You can find me at http://vimde.com
"
" Copyright 2014 Steve Francia
"
" Licensed under the Apache License, Version 2.0 (the "License");
" you may not use this file except in compliance with the License.
" You may obtain a copy of the License at
"
" http://www.apache.org/licenses/LICENSE-2.0
"
" Unless required by applicable law or agreed to in writing, software
" distributed under the License is distributed on an "AS IS" BASIS,
" WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
" See the License for the specific language governing permissions and
" limitations under the License.
" }
" Environment {
" Identify platform {
silent function! OSX()
return has('macunix')
endfunction
silent function! LINUX()
return has('unix') && !has('macunix') && !has('win32unix')
endfunction
silent function! WINDOWS()
return (has('win32') || has('win64'))
endfunction
" }
" Basics {
set nocompatible " Must be first line
if !WINDOWS()
set shell=/bin/sh
endif
" }
" Windows Compatible {
" On Windows, also use '.vim' instead of 'vimfiles'; this makes synchronization
" across (heterogeneous) systems easier.
if WINDOWS()
set runtimepath=$HOME/.vim,$VIM/vimfiles,$VIMRUNTIME,$VIM/vimfiles/after,$HOME/.vim/after
endif
" }
" Arrow Key Fix {
" https://github.com/vimde/vimde-vim/issues/780
if &term[:4] == "xterm" || &term[:5] == 'screen' || &term[:3] == 'rxvt'
inoremap <silent> <C-[>OC <RIGHT>
endif
" }
" }
" provider for neovim {
" :help provider
" to make vim load faster without detecting providers
" must be put before loading plugins
" disable python provider check
let g:python_host_skip_check = 1
let g:python_host3_skip_check = 1
let g:python_host_prog = 'python' " using pyenv as version manager
let g:python3_host_prog = 'python' " using pyenv as version manager
let g:loaded_ruby_provider = 0
" set clipboard
function! IsWSL()
if has("unix")
let lines = readfile("/proc/version")
if lines[0] =~ "microsoft"
" echo "WINDOWS SUBSYSTEM LINUX!"
return 1
endif
endif
return 0
endfunction
if exists('$TMUX')
let g:clipboard = {
\ 'name': 'myClipboard',
\ 'copy': {
\ '+': 'tmux load-buffer -',
\ '*': 'tmux load-buffer -',
\ },
\ 'paste': {
\ '+': 'tmux save-buffer -',
\ '*': 'tmux save-buffer -',
\ },
\ 'cache_enabled': 1,
\ }
elseif IsWSL()
" WSL yank support
let s:clip = '/mnt/c/Windows/System32/clip.exe' " change this path according to your mount point
if executable(s:clip)
augroup WSLYank
autocmd!
autocmd TextYankPost * if v:event.operator ==# 'y' | call system(s:clip, @0) | endif
augroup END
endif
" may still need to remove xclip from Linux to work.
let g:clipboard = {
\ 'name': 'WslClipboard',
\ 'copy': {
\ '+': 'clip.exe',
\ '*': 'clip.exe',
\ },
\ 'paste': {
\ '+': 'powershell.exe -c [Console]::Out.Write($(Get-Clipboard -Raw).tostring().replace("`r", ""))',
\ '*': 'powershell.exe -c [Console]::Out.Write($(Get-Clipboard -Raw).tostring().replace("`r", ""))',
\ },
\ 'cache_enabled': 0,
\ }
endif
" }
" Use before config if available {
if filereadable(expand("~/.vimrc.before"))
source ~/.vimde/.vimrc.before
endif
" }
" Use bundles config {
if filereadable(expand("~/.vimde/.vimrc.bundles"))
source ~/.vimde/.vimrc.bundles
endif
" }
" General {
set background=dark " Assume a dark background
" Allow to trigger background
function! ToggleBG()
let s:tbg = &background
" Inversion
if s:tbg == "dark"
set background=light
else
set background=dark
endif
endfunction
noremap <leader>bg :call ToggleBG()<CR>
" if !has('gui')
"set term=$TERM " Make arrow and other keys work
" endif
filetype plugin indent on " Automatically detect file types.
syntax on " Syntax highlighting
set mouse=a " Automatically enable mouse usage
set mouse=n " no mouse when editing
set mousehide " Hide the mouse cursor while typing
set encoding=UTF-8
scriptencoding utf-8
set fileencodings=ucs-bom,utf-8,cp936,gb18030,big5,euc-jp,euc-kr,latin1
set fileformat=unix
" or use vim -b to open file in binary mode
set fileformats=unix "'fileformats' option is global and specifies which file formats will be tried when Vim reads a file
if has('clipboard')
if has('unnamedplus') " When possible use + register for copy-paste
set clipboard=unnamed,unnamedplus
else " On mac and Windows, use * register for copy-paste
set clipboard=unnamed
endif
endif
" syntax settings, to mitigate some performance issue with large files
set cursorline!
set lazyredraw
set synmaxcol=128
syntax sync minlines=256
" Most prefer to automatically switch to the current file directory when
" a new buffer is opened; to prevent this behavior, add the following to
" your .vimrc.before.local file:
" let g:vimde_no_autochdir = 1
if !exists('g:vimde_no_autochdir')
autocmd BufEnter * if bufname("") !~ "^\[A-Za-z0-9\]*://" | lcd %:p:h | endif
" Always switch to the current file directory
endif
"set autowrite " Automatically write a file when leaving a modified buffer
set shortmess+=filmnrxoOtT " Abbrev. of messages (avoids 'hit enter')
set viewoptions=folds,options,cursor,unix,slash " Better Unix / Windows compatibility
set virtualedit=onemore " Allow for cursor beyond last character
set history=1000 " Store a ton of history (default is 20)
set spell " Spell checking on
set hidden " Allow buffer switching without saving
set iskeyword-=. " '.' is an end of word designator
set iskeyword-=# " '#' is an end of word designator
set iskeyword-=- " '-' is an end of word designator
" Spelling errors are higlighted using SpellBad highlighting group
" set spell checking highlight styles after alternating color scheme or
" background
hi clear SpellBad
hi SpellBad cterm=underline
"disable autoread/auto reloading but enable auto check
set noautoread
" Check for file modifications automatically
" (current buffer only).
augroup autoCheckTime
au!
au CursorHold,FocusGained,BufEnter * checktime
augroup end
" Use :NoAutoChecktime to disable it (uses b:autochecktime)
fun! AutoCheckTime()
" only check timestamp for normal files
if &buftype != '' | return | endif
if ! exists('b:autochecktime') || b:autochecktime
checktime %
let b:autochecktime = 1
endif
endfun
command! NoAutoChecktime let b:autochecktime=0
" Instead of reverting the cursor to the last position in the buffer, we
" set it to the first line when editing a git commit message
au FileType gitcommit au! BufEnter COMMIT_EDITMSG call setpos('.', [0, 1, 1, 0])
" http://vim.wikia.com/wiki/Restore_cursor_to_file_position_in_previous_editing_session
" Restore cursor to file position in previous editing session
" To disable this, add the following to your .vimrc.before.local file:
" let g:vimde_no_restore_cursor = 1
if !exists('g:vimde_no_restore_cursor')
function! ResCur()
if line("'\"") <= line("$")
silent! normal! g`"
return 1
endif
endfunction
augroup resCur
autocmd!
autocmd BufWinEnter * call ResCur()
augroup END
endif
" Setting up the directories {
set backup " Backups are nice ...
if has('persistent_undo')
set undofile " So is persistent undo ...
set undolevels=1000 " Maximum number of changes that can be undone
set undoreload=10000 " Maximum number lines to save for undo on a buffer reload
endif
" To disable views add the following to your .vimrc.before.local file:
" let g:vimde_no_views = 1
if !exists('g:vimde_no_views')
" Add exclusions to mkview and loadview
" eg: *.*, svn-commit.tmp
let g:skipview_files = [
\ '\[example pattern\]'
\ ]
endif
" }
"NeoVim handles ESC keys as alt+key, set this to solve the problem
if has('nvim')
set ttimeoutlen=0
set ttimeout
endif
" }
" Vim UI {
"Use 24-bit (true-color) mode in Vim/Neovim when outside tmux.
"If you're using tmux version 2.2 or later, you can remove the outermost $TMUX check and use tmux's 24-bit color support
"(see < http://sunaku.github.io/tmux-24bit-color.html#usage > for more information.)
if (empty($TMUX) || 1)
if (has("nvim"))
"For Neovim 0.1.3 and 0.1.4 < https://github.com/neovim/neovim/pull/2198 >
"set t_8f=[38;2;%lu;%lu;%lum " Needed in tmux
"set t_8b=[48;2;%lu;%lu;%lum " Ditto
let $NVIM_TUI_ENABLE_TRUE_COLOR = 1
endif
endif
"For Neovim > 0.1.5 and Vim > patch 7.4.1799 < https://github.com/vim/vim/commit/61be73bb0f965a895bfb064ea3e55476ac175162 >
"Based on Vim patch 7.4.1770 (`guicolors` option) < https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd >
" < https://github.com/neovim/neovim/wiki/Following-HEAD#20160511 >
set t_8f=[38;2;%lu;%lu;%lum " Needed in tmux
set t_8b=[48;2;%lu;%lu;%lum " Ditto
if (has("termguicolors"))
set termguicolors
endif
if (has("nvim"))
" not needed anymore?
"let $NVIM_TUI_ENABLE_CURSOR_SHAPE = 1
endif
" To enable mode shapes, "Cursor" highlight, and blinking:
set guicursor=n-v-c:block,i-ci-ve:ver25,r-cr:hor20,o:hor50
\,a:blinkwait700-blinkoff400-blinkon250-Cursor/lCursor
\,sm:block-blinkwait175-blinkoff150-blinkon175
set cursorline " Highlight current line
set cursorcolumn " Highlight current column
set tabpagemax=15 " Only show 15 tabs
set showmode " Display the current mode
highlight clear SignColumn " SignColumn should match background
highlight clear LineNr " Current line number row will have same background color in relative mode
"highlight clear CursorLineNr " Remove highlight color from current line number
highlight clear SignColumn " SignColumn should match background
highlight clear VertSplit " SignColumn should match background
if has('cmdline_info')
set ruler " Show the ruler
set rulerformat=%30(%=\:b%n%y%m%r%w\ %l,%c%V\ %P%) " A ruler on steroids
set showcmd " Show partial commands in status line and
" Selected characters/lines in visual mode
endif
if has('statusline')
set laststatus=2
" Broken down into easily includeable segments
set statusline=%<%f\ " Filename
set statusline+=%w%h%m%r " Options
if !exists('g:override_vimde_bundles')
set statusline+=%{fugitive#statusline()} " Git Hotness
endif
set statusline+=\ [%{&ff}/%Y] " Filetype
set statusline+=\ [%{getcwd()}] " Current dir
set statusline+=%=%-14.(%l,%c%V%)\ %p%% " Right aligned file nav info
" count of search occurrences
" FIXME: visual % will not work
function! SearchCount()
let keyString=@/
let pos=getpos('.')
try
" validate input
if keyString =~ '^$' " empty string
return '0' . '/' . '0'
endif
if keyString =~ '^\\$'
return '0/0'
endif
let nth="0 matches on 0 lines"
let cnt="0 matches on 0 lines"
redir => nth
silent exe '0,.s/' . keyString . '//gne'
redir => cnt
silent exe '%s/' . keyString . '//ne'
redir END
" post check
if !exists('nth') " undefined, empty string from stdout
echo "nth doesn't exist yet!"
return '0' . '/' . '0'
endif
if !exists('cnt') " empty string
return '0' . '/' . '0'
endif
" regular expression matching, \v for magic(extended regex)
return matchstr(nth, '\v\d+') . '/' . matchstr(cnt, '\v\d+')
finally
call setpos('.', pos)
endtry
endfunction
set statusline+=[%{SearchCount()}] " Nth of N when searching
endif
set backspace=indent,eol,start " Backspace for dummies
set linespace=0 " No extra spaces between rows
set number " Line numbers on
set showmatch " Show matching brackets/parenthesis
set incsearch " Find as you type search
set hlsearch " Highlight search terms
set winminheight=0 " Windows can be 0 line high
set ignorecase " Case insensitive search
set smartcase " Case sensitive when uc present
set wildmenu " Show list instead of just completing
set wildmode=list:longest,full " Command <Tab> completion, list matches, then longest common part, then all.
set whichwrap=b,s,h,l,<,>,[,] " Backspace and cursor keys wrap too
set scrolljump=5 " Lines to scroll when cursor leaves screen
set scrolloff=3 " Minimum lines to keep above and below cursor
set foldenable " Auto fold code
set foldmethod=indent
set foldlevel=9
"list feature can be used to reveal hidden characters
set nolist
"type unicode characters: press <ctrl-v>u, followed by its unicode number
set listchars=tab:›\ ,trail:•,extends:#,nbsp:. " Highlight problematic whitespace
" set listchars=tab:¦\ ,trail:•,extends:#,nbsp:. " Highlight problematic whitespace
"et listchars=tab:▸\ ,trail:•,eol:¬,extends:#,nbsp:. " Highlight problematic whitespace
" set listchars=tab:\ ,trail:,eol:$,extends:#,nbsp: " Highlight problematic whitespace
"Invisible character colors, but it's overriden by colorscheme plugins
" highlight NonText guifg=#4a4a59 " let it be managed by color scheme
" highlight SpecialKey guifg=#4a4a59
set concealcursor=n
" }
" Formatting {
set nowrap " Do not wrap long lines
set wrap " wrap long lines
set autoindent " Indent at the same level of the previous line
set shiftwidth=4 " Use indents of 4 spaces
set smartindent
set smarttab "
" set noexpandtab " Tabs are spaces, not tabs
set tabstop=4 " An indentation every four columns
set softtabstop=4 " Let backspace delete indent
set nojoinspaces " Prevents inserting two spaces after punctuation on a join (J)
set splitright " Puts new vsplit windows to the right of the current
set splitbelow " Puts new split windows to the bottom of the current
"set matchpairs+=<:> " Match, to be used with %
set pastetoggle=<F12> " pastetoggle (sane indentation on pastes)
"set comments=sl:/*,mb:*,elx:*/ " auto format comment blocks
" Remove trailing whitespaces and ^M chars
" To disable the stripping of whitespace, add the following to your
" .vimrc.before.local file:
" let g:vimde_keep_trailing_whitespace = 1
autocmd FileType c,cpp,java,go,php,javascript,puppet,python,rust,twig,xml,yml,perl,sql autocmd BufWritePre <buffer> if !exists('g:vimde_keep_trailing_whitespace') | call StripTrailingWhitespace() | endif
autocmd FileType c,cpp,objc,objcpp setlocal expandtab shiftwidth=4 tabstop=4 softtabstop=4
autocmd FileType haskell,puppet,ruby,yml,helm,javascript,jsx,javascript.jsx,html,xhtml,xml,css,json setlocal expandtab shiftwidth=2 tabstop=2 softtabstop=2
"autocmd FileType go autocmd BufWritePre <buffer> Fmt
autocmd BufNewFile,BufRead *.html.twig set filetype=html.twig
" preceding line best in a plugin but here for now.
autocmd BufNewFile,BufRead *.coffee set filetype=coffee
" Workaround vim-commentary for Haskell
autocmd FileType haskell setlocal commentstring=--\ %s
" Workaround broken colour highlighting in Haskell
autocmd FileType haskell,rust setlocal nospell
" Note: this could be override by vim-autoformat plugin
"au FileType python setlocal formatprg=autopep8\ -\ --aggressive\ --aggressive\ --ignore\ E302
au FileType javascript setlocal formatprg=esformatter
" }
" Key (re)Mappings {
" http://vim.wikia.com/wiki/Replace_a_builtin_command_using_cabbrev{
" map :e to :E, :cabbrev e <c-r>=(getcmdtype()==':' && getcmdpos()==1 ? 'E' : 'e')<CR>
function! CommandCabbr(abbreviation, expansion)
execute 'cabbrev ' . a:abbreviation . ' <c-r>=getcmdpos() == 1 && getcmdtype() == ":" ? "' . a:expansion . '" : "' . a:abbreviation . '"<CR>'
endfunction
command! -nargs=+ CommandCabbr call CommandCabbr(<f-args>)
" Use it on itself to define a simpler abbreviation for itself.
CommandCabbr alias CommandCabbr
" }
" The default leader is '\', but many people prefer ',' as it's in a standard
" location. To override this behavior and set it back to '\' (or any other
" character) add the following to your .vimrc.before.local file:
" let g:vimde_leader='\'
if !exists('g:vimde_leader')
let mapleader = ','
else
let mapleader=g:vimde_leader
endif
if !exists('g:vimde_localleader')
let maplocalleader = '_'
else
let maplocalleader=g:vimde_localleader
endif
" The default mappings for editing and applying the vimde configuration
" are <leader>ev and <leader>sv respectively. Change them to your preference
" by adding the following to your .vimrc.before.local file:
" let g:vimde_edit_config_mapping='<leader>ec'
" let g:vimde_apply_config_mapping='<leader>sc'
if !exists('g:vimde_edit_config_mapping')
let s:vimde_edit_config_mapping = '<leader>ev'
else
let s:vimde_edit_config_mapping = g:vimde_edit_config_mapping
endif
if !exists('g:vimde_apply_config_mapping')
let s:vimde_apply_config_mapping = '<leader>sv'
else
let s:vimde_apply_config_mapping = g:vimde_apply_config_mapping
endif
" Easier moving in tabs and windows
" The lines conflict with the default digraph mapping of <C-K>
" If you prefer that functionality, add the following to your
" .vimrc.before.local file:
" let g:vimde_no_easyWindows = 1
if !exists('g:vimde_no_easyWindows')
"map <C-J> <C-W>j<C-W>_
"map <C-K> <C-W>k<C-W>_
"map <C-L> <C-W>l<C-W>_
"map <C-H> <C-W>h<C-W>_
map <C-J> <C-W>j
map <C-K> <C-W>k
map <C-L> <C-W>l
map <C-H> <C-W>h
endif
" Wrapped lines goes down/up to next row, rather than next line in file.
noremap j gj
noremap k gk
" selecte last changed text
"nnoremap <expr> gp `[v`]
nnoremap <expr> gp '`[' . strpart(getregtype(), 0, 1) . '`]'
" End/Start of line motion keys act relative to row/wrap width in the
" presence of `:set wrap`, and relative to line for `:set nowrap`.
" Default vim behaviour is to act relative to text line in both cases
" If you prefer the default behaviour, add the following to your
" .vimrc.before.local file:
" let g:vimde_no_wrapRelMotion = 1
if !exists('g:vimde_no_wrapRelMotion')
" Same for 0, home, end, etc
function! WrapRelativeMotion(key, ...)
let vis_sel=""
if a:0
let vis_sel="gv"
endif
if &wrap
execute "normal!" vis_sel . "g" . a:key
else
execute "normal!" vis_sel . a:key
endif
endfunction
" Map g* keys in Normal, Operator-pending, and Visual+select
noremap $ :call WrapRelativeMotion("$")<CR>
noremap <End> :call WrapRelativeMotion("$")<CR>
noremap 0 :call WrapRelativeMotion("0")<CR>
noremap <Home> :call WrapRelativeMotion("0")<CR>
noremap ^ :call WrapRelativeMotion("^")<CR>
" Overwrite the operator pending $/<End> mappings from above
" to force inclusive motion with :execute normal!
onoremap $ v:call WrapRelativeMotion("$")<CR>
onoremap <End> v:call WrapRelativeMotion("$")<CR>
" Overwrite the Visual+select mode mappings from above
" to ensure the correct vis_sel flag is passed to function
vnoremap $ :<C-U>call WrapRelativeMotion("$", 1)<CR>
vnoremap <End> :<C-U>call WrapRelativeMotion("$", 1)<CR>
vnoremap 0 :<C-U>call WrapRelativeMotion("0", 1)<CR>
vnoremap <Home> :<C-U>call WrapRelativeMotion("0", 1)<CR>
vnoremap ^ :<C-U>call WrapRelativeMotion("^", 1)<CR>
vnoremap H <Nop>
nnoremap H h
endif
" The following two lines conflict with moving to top and
" bottom of the screen
" If you prefer that functionality, add the following to your
" .vimrc.before.local file:
" let g:vimde_no_fastTabs = 1
if !exists('g:vimde_no_fastTabs')
nmap <M-h> gT
nmap <M-l> gt
nmap <M-t> :tabnew<CR>
nmap <M-w> :tabclose<CR>
"nmap <M-S-t> :tabnew#<CR>
"nnoremap <S-PageUp> :tabmove -1<CR>
"nnoremap <S-PageDown> :tabmove +1<CR>
nnoremap <M-H> :tabmove -1<CR> " <M-H> is <M-S-H>
nnoremap <M-L> :tabmove +1<CR>
endif
" fast tabs
nnoremap <S-Tab> :tabprevious<CR>
nnoremap <Tab> :tabnext<CR> " go to
" Stupid shift key fixes
if !exists('g:vimde_no_keyfixes')
if has("user_commands")
command! -bang -nargs=* -complete=file E e<bang> <args>
command! -bang -nargs=* -complete=file W w<bang> <args>
command! -bang -nargs=* -complete=file Wq wq<bang> <args>
command! -bang -nargs=* -complete=file WQ wq<bang> <args>
command! -bang Wa wa<bang>
command! -bang WA wa<bang>
command! -bang Q q<bang>
command! -bang QA qa<bang>
command! -bang Qa qa<bang>
endif
cmap Tabe tabe
endif
" Yank/copy and paste {
"Paste in visual mode without copying
"xnoremap p pgvy
" use '"_', the blackhole register, see ':help "_'
" delete without yanking
"vnoremap <leader>d "_d
"nnoremap <leader>d "_d
" replace visually selected text without copying it: delete into black hole register, then paste
vnoremap p "_dP
" }
" Yank from the cursor to the end of the line, to be consistent with C and D.
nnoremap Y y$
" Code folding options
nmap <leader>f0 :set foldlevel=0<CR>
nmap <leader>f1 :set foldlevel=1<CR>
nmap <leader>f2 :set foldlevel=2<CR>
nmap <leader>f3 :set foldlevel=3<CR>
nmap <leader>f4 :set foldlevel=4<CR>
nmap <leader>f5 :set foldlevel=5<CR>
nmap <leader>f6 :set foldlevel=6<CR>
nmap <leader>f7 :set foldlevel=7<CR>
nmap <leader>f8 :set foldlevel=8<CR>
nmap <leader>f9 :set foldlevel=9<CR>
" easier search {
" search for visually selected text, http://vim.wikia.com/wiki/Search_for_visually_selected_text
vnoremap // y/\V<C-r>=escape(@",'/\')<CR><CR>
" search within range, http://vim.wikia.com/wiki/Search_only_over_a_visual_range
vnoremap / <Esc>/\%><C-R>=line("'<")-1<CR>l\%<<C-R>=line("'>")+1<CR>l
vnoremap ? <Esc>?\%><C-R>=line("'<")-1<CR>l\%<<C-R>=line("'>")+1<CR>l
" Permanent very magic mode, like POSIX regular expression, see :help magic
" http://vim.wikia.com/wiki/Simplifying_regular_expressions_using_magic_and_no-magic
" Refer to https://github.com/vim-scripts/Enchanted-Vim
nnoremap / /\v
nnoremap ? ?\v
"vnoremap / y/\v<C-R>"<CR>
"vnoremap ? y?\v<C-R>"<CR>
"cnoremap %s/ %smagic/
cnoremap %s/ %s/\v
"cnoremap '<,'>s/ '<,'>s/\v " doesn't work
cnoremap \>s/ \>smagic/
nnoremap :g/ :g/\v
nnoremap :g// :g//
" }
" record: to apply the recorded macro over visually selected lines,
" map visual at {
vnoremap @ :<C-u>call ExecuteMacroOverVisualRange()<CR>
function! ExecuteMacroOverVisualRange()
echo "@".getcmdline()
execute ":'<,'>normal @".nr2char(getchar())
endfunction
" }
" Most prefer to toggle search highlighting rather than clear the current
" search results. To clear search highlighting rather than toggle it on
" and off, add the following to your .vimrc.before.local file:
" let g:vimde_clear_search_highlight = 1
if exists('g:vimde_clear_search_highlight')
nmap <silent> <leader>/ :nohlsearch<CR>
else
nmap <silent> <leader>/ :set invhlsearch<CR>
endif
" Find merge conflict markers
map <leader>fc /\v^[<\|=>]{7}( .*\|$)<CR>
" Shortcuts
" Change Working Directory to that of the current file
"cmap cwd lcd %:p:h
command Cwd lcd %:p:h "
"cmap cd. lcd %:p:h
command Ccp let @+ = expand("%:p") " Copy current File full Path into unnamedplus register
command Ccn let @+ = expand("%") " just filename
" relative path
" :let @+ = expand("%")
" WSL(Windows subsystem for Linux) support
if system('uname -r') =~ "Microsoft"
command! Ccp call system(s:clip, expand("%:p")) " command! to override previously defined commands
command! Ccn call system(s:clip, expand("%:t")) " command! to override previously defined commands
endif
" Visual shifting (does not exit Visual mode)
vnoremap < <gv
vnoremap > >gv
" Allow using the repeat operator with a visual selection (!)
" http://stackoverflow.com/a/8064607/127816
vnoremap . :normal .<CR>
" For when you forget to sudo.. Really Write the file.
cmap w!! w !sudo tee % >/dev/null
cmap w\ w " ignore accidentally pressing \ when hitting <Enter>
" Some helpers to edit mode
" http://vimcasts.org/e/14
cnoremap %% <C-R>=fnameescape(expand('%:h')).'/'<cr>
map <leader>ew :e %%
map <leader>es :sp %%
map <leader>ev :vsp %%
map <leader>et :tabe %%
" Adjust viewports to the same size
map <Leader>= <C-w>=
" Map <Leader>ff to display all lines with keyword under cursor
" and ask which one to jump to
"nmap <Leader>ff [I:let nr = input("Which one: ")<Bar>exe "normal " . nr ."[\t"<CR>
" Easier horizontal scrolling
map zl zL
map zh zH
" Easier formatting
nnoremap <silent> <leader>q gwip
" nnoremap <silent> <leader>m :%s/\r//g<CR>
nnoremap <silent> <leader>m :%s///g<CR>
" change square brackets [] to curly brackets {}
" vnoremap <silent> <leader>b :'<,'>s/\[/{/g | '<,'>s/]/}/g<CR>
" map to multiple :commands: use pipe with <bar>
" do multiple substitution in visual block: substitute, gv to se
vnoremap <silent> <leader>{ :s/\[/{/g<CR> gv :s/]/}/g<CR>
" FIXME: below doesn't work as expected
vnoremap <silent> <leader>[ :s/{/[/g<CR> gv :s/}/]/g<CR>
" FIXME: Revert this f70be548
" fullscreen mode for GVIM and Terminal, need 'wmctrl' in you PATH
map <silent> <F11> :call system("wmctrl -ir " . v:windowid . " -b toggle,fullscreen")<CR>
"autocmd FileType text,help,vim nnoremap <C-]> :tjump<CR>
" universal INSERT MODE editting key mappings to be compatible with editors
" Ctrl-S to save in insert mode
imap <c-s> <Esc>:w<CR>a
" Map Ctrl-A -> Start of line, Ctrl-E -> End of line
imap <C-a> <Home>
"inoremap <C-a> <C-U>call WrapRelativeMotion("^", 1)<CR>
imap <C-e> <End>
" redo, undo in insert mode
inoremap <C-Z> <Esc>ua
"inoremap <C-Z> <Esc>:undo<CR>a
inoremap <C-R> <Esc>:redo<CR>a
"digraphs alphsubs ---------------------- {
execute "digraphs as " . 0x2090
execute "digraphs es " . 0x2091
execute "digraphs hs " . 0x2095
execute "digraphs is " . 0x1D62
execute "digraphs js " . 0x2C7C
execute "digraphs ks " . 0x2096
execute "digraphs ls " . 0x2097
execute "digraphs ms " . 0x2098
execute "digraphs ns " . 0x2099
execute "digraphs os " . 0x2092
execute "digraphs ps " . 0x209A
execute "digraphs rs " . 0x1D63
execute "digraphs ss " . 0x209B
execute "digraphs ts " . 0x209C
execute "digraphs us " . 0x1D64
execute "digraphs vs " . 0x1D65
execute "digraphs xs " . 0x2093
"}
" base64.
" https://stackoverflow.com/questions/7845671/how-to-execute-base64-decode-on-selected-text-in-vim
" {
" :'<,'>!base64 -d -
" :'<,'>!python -m base64 -d
nnoremap <leader>bd :%!base64 -d -<CR>
nnoremap <leader>be :%!base64 -<CR>
" vnoremap <leader>64 y:echo system('base64 --decode', @")<cr>")
" }
" JSON {
" format with Linux jq::%!jq --tab -S . %
" Or, format with python -m json.tool
nmap <leader>jf <Esc>:%!python -m json.tool<CR><Esc>:set filetype=json<CR>
let g:vim_json_syntax_conceal = 0
" }
" }
" }
" Plugins {
" fzf.vim: fuzzy finder {
if isdirectory(expand("~/.vim/bundle/fzf.vim"))
if !count(g:vimde_bundle_groups, 'telescope.nvim')
nnoremap <c-M-p> :Files<cr>
nmap <leader>lf :Files<CR>
" " list files
nnoremap <c-p> :GFiles<cr>
nmap <leader>lg :GFiles<CR>
" " list buffers
nnoremap <C-M-b> :Buffers<cr>
CommandCabbr buffers Buffers
nmap <leader>lb :Buffers<CR>
nmap <leader>ls :Buffers<CR>
CommandCabbr ls Buffers
endif
" list windows
nmap <leader>lw :Windows<CR>
CommandCabbr history History
endif
" }
" coc.nvim {
" Conquer of Completion, language server leveraging VSCode plugins
if count(g:vimde_bundle_groups, 'coc.nvim')
if filereadable(expand("~/.vimde/conf.d/.vimrc.coc.nvim"))
source ~/.vimde/conf.d/.vimrc.coc.nvim
endif
if filereadable(expand("~/.vimde/conf.d/.vimrc.coc-snippets"))
source ~/.vimde/conf.d/.vimrc.coc-snippets
endif
endif
" }
" fuzzy finder telescope {
if has('nvim-0.5.0')
if filereadable(expand("~/.vimde/conf.d/.vimrc.telescope.nvim"))
source ~/.vimde/conf.d/.vimrc.telescope.nvim
endif
endif
" }
" nvim-treesitter {
if has('nvim-0.5.0')
if filereadable(expand("~/.vimde/conf.d/.vimrc.nvim-treesitter"))
source ~/.vimde/conf.d/.vimrc.nvim-treesitter
endif
endif
" }
if filereadable(expand("~/.vimde/conf.d/.vimrc.code_runner.nvim"))
source ~/.vimde/conf.d/.vimrc.code_runner.nvim
endif
" nerdcommenter {
let NERDSpaceDelims=1
let g:NERDCustomDelimiters = {
\ 'javascript': { 'left': '// ', 'leftAlt': '/* ', 'rightAlt': '*/' },
\ 'javascript.jsx': { 'left': '// ', 'leftAlt': '/* ', 'rightAlt': '*/' },
\ 'jsx': { 'left': '// ', 'leftAlt': '/* ', 'rightAlt': '*/' },
\ }
" nmap <C-/> <plug>NERDCommenterToggle
if OSX()
" Do Mac stuff here
"map <D-/> <Esc><plug>NERDCommenterToggle<CR>i
"imap <D-/> <Esc><plug>NERDCommenterToggle<CR>i
"imap <C-/> <Esc><plug>NERDCommenterToggle<CR>i
endif
" }
"General Programming {
if count(g:vimde_bundle_groups, 'programming')
" sideways.vim, deprecated in favor of treesitter
if !has('nvim-0.5.0')
nnoremap <, :SidewaysLeft<cr>
nnoremap >. :SidewaysRight<cr>
endif
endif
"}
" competitive programming {
let g:cph_chdir = "~/code/dsa/oj/codeforces"
let g:cpp_compile_command = "clang++ -pedantic -std=c++17 -Wall -Wextra -Werror=uninitialized -Werror=return-type -Werror=shadow -Werror=narrowing -Werror=conversion -Wno-sign-conversion -Werror=float-equal -Werror=parentheses -Wformat=2 -Wcast-qual -Wcast-align -Wlogical-op -Wshift-overflow=2 -Wduplicated-cond -O2 -ggdb -fno-omit-frame-pointer -fsanitize=address,undefined,float-divide-by-zero,unsigned-integer-overflow,implicit-conversion,local-bounds -Wl,-z,stack-size=268435456 -o cpp.out solution.cpp"
" }
" TextObj Sentence {
if count(g:vimde_bundle_groups, 'writing')
augroup textobj_sentence
autocmd!
autocmd FileType markdown call textobj#sentence#init()
autocmd FileType textile call textobj#sentence#init()
autocmd FileType text call textobj#sentence#init()
augroup END
endif
" }
" TextObj Quote {
if count(g:vimde_bundle_groups, 'writing')
augroup textobj_quote
autocmd!
autocmd FileType markdown call textobj#quote#init()
autocmd FileType textile call textobj#quote#init()
autocmd FileType text call textobj#quote#init({'educate': 0})
augroup END
endif
" }
" vim-autoformat {
"vim-autoformat, deprecated in favor of treesitter
"noremap <F3> :Autoformat<CR>
if !has('nvim-0.5.0')
noremap <F7> :Autoformat<CR>
"au BufWrite * :Autoformat
let g:formatter_yapf_style = 'pep8'
endif
" }
" PIV {
if isdirectory(expand("~/.vim/bundle/PIV"))
let g:DisableAutoPHPFolding = 0
let g:PIVAutoClose = 0
endif
" }
" Misc {
if isdirectory(expand("~/.vim/bundle/nerdtree"))
let g:NERDShutUp=1
endif
" if isdirectory(expand("~/.vim/bundle/matchit.zip"))
" let b:match_ignorecase = 1
" endif
" }
" OmniComplete {
" To disable omni complete, add the following to your .vimrc.before.local file:
" let g:vimde_no_omni_complete = 1
if !exists('g:vimde_no_omni_complete')
if has("autocmd") && exists("+omnifunc")
autocmd Filetype *
\if &omnifunc == "" |
\setlocal omnifunc=syntaxcomplete#Complete |
\endif
endif
" Some convenient mappings
"inoremap <expr> <Esc> pumvisible() ? "\<C-e>" : "\<Esc>"
if exists('g:vimde_map_cr_omni_complete')
inoremap <expr> <CR> pumvisible() ? "\<C-y>" : "\<CR>"
endif
inoremap <expr> <Down> pumvisible() ? "\<C-n>" : "\<Down>"
inoremap <expr> <Up> pumvisible() ? "\<C-p>" : "\<Up>"
inoremap <expr> <C-d> pumvisible() ? "\<PageDown>\<C-p>\<C-n>" : "\<C-d>"
inoremap <expr> <C-u> pumvisible() ? "\<PageUp>\<C-p>\<C-n>" : "\<C-u>"
" Automatically open and close the popup menu / preview window
au CursorMovedI,InsertLeave * if pumvisible() == 0|silent! pclose|endif
set completeopt=menu,preview,longest
endif
" }
" Ctags {
set tags=./tags;/,~/.vimtags
" Make tags placed in .git/tags file available in all levels of a repository
let gitroot = substitute(system('git rev-parse --show-toplevel'), '[\n\r]', '', 'g')
if gitroot != ''
let &tags = &tags . ',' . gitroot . '/.git/tags'
endif
" }
" AutoCloseTag {
" Make it so AutoCloseTag works for xml and xhtml files as well
au FileType xhtml,xml ru ftplugin/html/autoclosetag.vim
nmap <Leader>ac <Plug>ToggleAutoCloseMappings
" }
" SnipMate {
" Setting the author var
" }
if has('nvim-0.5.0')
Plug 'kyazdani42/nvim-tree.lua'"
lua << EOF
require("nvim-tree.main")
EOF
endif