-
Notifications
You must be signed in to change notification settings - Fork 1
/
vimrc
1977 lines (1712 loc) · 61.5 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
" _
" __ __(_) _ __ ___ _ __ ___
" \ \ / /| || '_ ` _ \ | '__|/ __|
" \ V / | || | | | | || | | (__
" \_/ |_||_| |_| |_||_| \___|
"
" This vimrc {{{ ==============================================================
"@ Lukas Trumm, since 2014
" Source the vimrc file after saving it
augroup configuration
autocmd!
autocmd BufWritePost .vimrc,_vimrc,vimrc source $MYVIMRC
augroup END
" }}}
" Plugins {{{ =================================================================
call plug#begin()
" Code generation
Plug 'MarcWeber/vim-addon-mw-utils'
Plug 'garbas/vim-snipmate'
Plug 'tomtom/tlib_vim'
Plug 'honza/vim-snippets'
Plug 'lttr/sql_iabbr.vim'
Plug 'vim-scripts/loremipsum'
Plug 'vim-scripts/SyntaxComplete'
" Code style
" Plug 'Chiel92/vim-autoformat'
" Plug 'scrooloose/syntastic'
Plug 'editorconfig/editorconfig-vim'
" Plug 'maksimr/vim-jsbeautify'
Plug 'w0rp/ale'
" Documentation
Plug 'KabbAmine/zeavim.vim'
Plug 'chrisbra/unicode.vim'
Plug 'rhysd/devdocs.vim'
" Editing
Plug 'maxbrunsfeld/vim-yankstack'
Plug 'PeterRincker/vim-argumentative'
Plug 'AndrewRadev/splitjoin.vim'
Plug 'Raimondi/delimitMate'
Plug 'drmikehenry/vim-fontsize'
Plug 'godlygeek/tabular'
Plug 'coderifous/textobj-word-column.vim'
Plug '907th/vim-auto-save'
Plug 'michaeljsmith/vim-indent-object'
Plug 'vim-scripts/Yankitute'
Plug 'tommcdo/vim-exchange'
Plug 'tpope/vim-abolish'
Plug 'tpope/vim-characterize'
Plug 'tpope/vim-commentary'
Plug 'salsifis/vim-transpose'
Plug 'scrooloose/nerdcommenter'
Plug 'tpope/vim-repeat'
Plug 'tpope/vim-surround'
Plug 'vim-scripts/visSum.vim'
Plug 'vim-scripts/matchit.zip'
Plug 'terryma/vim-multiple-cursors' , { 'on': 'MultipleCursorsFind' }
Plug 'triglav/vim-visual-increment'
Plug 'tpope/vim-unimpaired'
Plug 'osyo-manga/vim-over'
Plug 'kubahorak/diacritic'
" Files
Plug 'ctrlpvim/ctrlp.vim'
Plug 'airblade/vim-rooter'
" Plug 'rking/ag.vim'
Plug 'vim-scripts/Rename'
Plug 'scrooloose/nerdtree'
Plug 'Xuyuanp/nerdtree-git-plugin'
Plug 'majutsushi/tagbar' , { 'on': 'TagbarToggle' }
Plug 'mbbill/undotree' , { 'on': 'UndotreeToggle' }
Plug 'tpope/vim-eunuch'
Plug 'airblade/vim-rooter'
Plug 'wting/gitsessions.vim'
" Html, xml, css
Plug 'othree/xml.vim'
Plug 'othree/html5.vim'
Plug 'Valloric/MatchTagAlways' , has('python') ? {} : { 'on' : [] }
Plug 'mattn/emmet-vim'
Plug 'jvanja/vim-bootstrap4-snippets'
Plug 'hail2u/vim-css3-syntax'
Plug 'groenewege/vim-less' , { 'for': 'less' }
Plug 'chrisbra/Colorizer'
" Javascript
Plug 'pangloss/vim-javascript'
Plug 'ternjs/tern_for_vim' , {'do': 'npm install'}
Plug 'othree/javascript-libraries-syntax.vim'
Plug 'arturbalabanov/vim-angular-template'
Plug 'Quramy/vim-js-pretty-template'
Plug 'elzr/vim-json'
Plug 'mvolkmann/vim-js-arrow-function'
" Plug 'webdesus/polymer-ide.vim', { 'do': 'npm install' }
Plug 'posva/vim-vue'
" Typescript
Plug 'Quramy/tsuquyomi'
Plug 'leafgarland/typescript-vim'
Plug 'magarcia/vim-angular2-snippets'
Plug 'bdauria/angular-cli.vim'
" PHP
Plug 'shawncplus/phpcomplete.vim' , { 'for': 'php' }
Plug 'StanAngeloff/php.vim' , { 'for': 'php' }
Plug 'vim-scripts/Nette' , { 'for': 'php' }
" Python
Plug 'klen/python-mode' , { 'for': 'python' }
" Tools
Plug 'metakirby5/codi.vim'
Plug 'janko-m/vim-test'
Plug 'vim-scripts/Shebang'
Plug 'fboender/bexec'
Plug 'glts/vim-magnum'
Plug 'glts/vim-radical'
Plug 'kannokanno/previm'
Plug 'qpkorr/vim-renamer'
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
Plug 'junegunn/fzf.vim'
Plug 'skywind3000/asyncrun.vim'
" Special file types
Plug 'chrisbra/csv.vim', { 'for': 'csvx' }
Plug 'dzeban/vim-log-syntax' , { 'for': 'log' }
Plug 'andreshazard/vim-freemarker' , { 'for': 'freemarker' }
Plug 'vobornik/vim-mql4' , { 'for': 'mql4' }
Plug 'vim-scripts/dbext.vim' , { 'for': 'sql' }
Plug 'vim-scripts/gnuplot.vim' , { 'for': 'gnuplot' }
Plug 'gabrielelana/vim-markdown' , { 'for': 'markdown' }
Plug 'blockloop/vim-swigjs', { 'for': 'html' }
Plug 'stephpy/vim-yaml', { 'for': 'yaml' }
Plug 'timcharper/textile.vim', { 'for': 'textile' }
" Version control
Plug 'gregsexton/gitv' , { 'on': 'Gitv' }
Plug 'tpope/vim-fugitive'
Plug 'airblade/vim-gitgutter'
" Window management
Plug 'milkypostman/vim-togglelist'
Plug 'junegunn/goyo.vim'
Plug 'Shougo/vimproc.vim'
Plug 'vim-voom/VOoM'
Plug 'moll/vim-bbye'
Plug 'sjl/clam.vim'
Plug 'tyru/open-browser.vim'
Plug 'tyru/restart.vim'
Plug 'tpope/vim-dispatch'
call plug#end()
" }}}
" General settings {{{ ========================================================
set confirm " Less errors, more questions
set backspace=indent,eol,start " Allow backspase in insert mode
set autoread " Relaod files changed outside Vim
set nrformats =alpha " Think about all formats as decimal
set history =500 " Keep 200 items in history of Ex commands
" Message abbreviations, truncate file messages, dont warn if existing swap files,
" hide the welcome screen, truncate other long messages
set shortmess =atAIT
set nostartofline " Don't jump to first character when paging
set number " Line numbers before lines
set iskeyword+=- " Count strings joined by dashes as words
set noshelltemp " Should avoid some cmd windows for external commands
set modeline " Make sure modelines are read
" ===== Buffers =====
set hidden " Allow buffer switching without saving
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 diffopt+=vertical " Use vertical layout when using vim as mergetool
" ===== Directories ======
set backup " Make backups
if has('unix')
set backupdir =~/.vim/backups " List of directory names for backup files
set directory =~/.vim/backups " List of directory names for swap files
set undodir =~/.vim/undos " List of directory names for undo files
else
set backupdir =~/vimfiles/backups " List of directory names for backup files
set directory =~/vimfiles/backups " List of directory names for swap files
set undodir =~/vimfiles/undos " List of directory names for undo files
endif
set undofile " Automatically saves undo history to an undo file
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
set writebackup " Make a backup before overwriting a file
set tags =./.tags; " Find tags file in parent dirs (;) starting in current dir (./)
" ===== Folding =====
set foldmethod =marker
" ===== Language and encoding =====
set encoding =utf-8
" ===== Lines =====
set linespace =1 " Vertical space between lines (in pixels, 1 = default on win)
set scrolloff =1 " Let one line above and bellow
set sidescroll=1
set sidescrolloff=15
set nojoinspaces " Prevents inserting two spaces after punctuation on a join (J)
set display =lastline " Display as much as possible from the last (wrapped) line on the screen
set formatoptions -=o " Do not generally insert comment leader after 'o'
set formatoptions +=j " Remove comment leader when joining lines
set formatoptions +=l " Long lines remains long in insert mode
set formatoptions +=n " Recognize numbered lists
set formatoptions +=r " Automatically insert comment leader after Enter
set formatoptions +=w " Trailing white space indicates a paragraph continues
set formatoptions +=1 " Don't break line after one-letter word
" ===== Search =====
set incsearch " Highlight during typing (=incremental searching)
set ignorecase " Search case-insensitive
set smartcase " ...except upper-case included
set wildmenu " Show list instead of just completing
" ===== Tabs and indentation =====
set tabstop =4 " Number of spaces that <Tab> counts for
set softtabstop =4 " Tabs and Backspaces feels like <Tab>
set shiftwidth =4 " Number of spaces to use for each step of indent
set shiftround " Round the size of indentation (using < and >) to shiftwidth
set virtualedit ="" " Do not move the cursor behind last char
" Following are not needed after vim-sleuth plugin is installed
set autoindent " Copy indent from current line when starting a new line
set copyindent " Autoindent the new line
set smarttab " Inserts or deletes blanks according to tab settings
set cindent " Apply indentation rules for c-like languages
set expandtab " Force spaces over tabs, also with :retab
" ===== Wrapping =====
set textwidth =0 " Maximum width of text that is being inserted (0 = no hard wrap)
set linebreak " Dont wrap words
if exists('&breakindent')
set breakindent " Soft wrapped lines will continue visually indented (since vim 7.4.x)
endif
" ===== Mouse =====
set mouse=a " Enable the use of mouse in terminal
" Leave the insert mode without waiting for another hotkey,
" because <Esc> is used to simulate <Alt> in some terminals.
if ! has('gui_running')
set ttimeout ttimeoutlen=10
augroup FastEscape
autocmd!
au InsertEnter * set timeoutlen=0
au InsertLeave * set timeoutlen=1000
augroup END
endif
" }}}
" Appearance {{{ ==============================================================
" ===== Language =====
if has('unix')
language en_US.UTF-8
else
language us
endif
" ===== Cursor =====
set guicursor+=a:blinkon0 " Disable blinking cursor in normal mode
" Change cursor shape in different modes in terminal
if has('unix')
let &t_SI = "\<Esc>[6 q"
let &t_SR = "\<Esc>[4 q"
let &t_EI = "\<Esc>[2 q"
endif
" ===== Font =====
if has('unix')
" Font for vim-devicons
set guifont=DejaVuSansMonoForPowerline\ Nerd\ Font\ 12
else
" Best Windows font
set guifont=Consolas:h12
endif
" ===== GUI adjustments =====
set guioptions-=b " Hide horizontal (bottom) scrollbar
set guioptions-=e " Text based tabs
set guioptions-=l " Hide left vertical scrollbar
set guioptions-=L " Hide left scrollbar even when there is vertical split window
set guioptions-=m " Remove menu bar
set guioptions-=R " Hide right scrollbar even when there is vertical split window
set guioptions-=T " Remove toolbar
set guitablabel=%f " File name in tab
" Toggle horizontal scrollbar
" <coW> corresponds to <cow> for toggle wrap
nnoremap <silent> coW :call ToggleFlag('guioptions', 'b')<CR>
" ===== Status line =====
set noruler " No useful info in ruler for me
set laststatus =2 " Always show statusline
" Left side
set statusline = " Reset of the statusline
set statusline +=\ %<%f " Tail of the filename
set statusline +=\ %m " Modified flag
set statusline +=\ %r " Read only flag
" Insert current git branch name, 7 chars from commit in case of detached HEAD
set statusline +=\ %{exists('g:loaded_fugitive')?fugitive#head(7):''}
" Separator
set statusline +=\ %= " Left/right separator
" Right side
set statusline +=\ \|\ %{&ft} " Filetype (neither %y nor %Y does fit)
set statusline +=\ \|\ %{&fenc} " File encoding
set statusline +=\ \|\ %{strpart(&ff,0,1)} " File format
set statusline +=\ \|\ %l:%c " Total lines and virtual column number
set statusline +=\ \|\ %P " Percentage
set statusline +=\ " Right margin (one space)
" ===== Syntax highlighting =====
syntax enable
set background =light
if !has('gui_running')
set t_Co=256
endif
"colorscheme solarized
set synmaxcol =500 " Max column in which to search for syntax items (better performance)
" ===== Whitespace =====
set listchars=tab:»\ ,trail:•,extends:#,nbsp:. " Highlight problematic whitespace
" ===== Fonts customization =====
" Row numbers
if (&background == 'light')
hi LineNr guifg=#c2c0ba ctermfg=250
endif
" }}}
" Completion {{{ ==============================================================
" inoremap <expr> <C-Space> pumvisible() \|\| &omnifunc == '' ?
" \ "\<lt>C-n>" :
" \ "\<lt>C-x>\<lt>C-o><C-r>=pumvisible() ?" .
" \ "\"\\<lt>C-n>\\<lt>C-p>\\<lt>C-n>\" :" .
" \ "\" \\<lt>bs>\\<lt>C-n>\"\<CR>"
inoremap <C-Space> <C-x><C-o>
imap <C-@> <C-Space>
" function to call when Ctrl-X Ctrl-O pressed in Insert mode
" if has("autocmd") && exists("+omnifunc")
" autocmd Filetype *
" \ if &omnifunc == "" |
" \ setlocal omnifunc=syntaxcomplete#Complete |
" \ endif
" endif
" Show menu when there is more then one item to complete
set completeopt=menu,preview
" Make <Tab> select the currently selected choice, same like <CR>
" If not in completion mode, call snippets expanding function
imap <expr> <Tab> pumvisible() ? "\<C-y>" : "<Plug>snipMateNextOrTrigger"
" inoremap <expr> <CR> pumvisible() ? "\<C-y>" : "\<CR>"
" Compatibility with IDEA
inoremap <A-/> <c-n><Down>
inoremap <A-?> <c-p><Down>
" Close preview window
autocmd CompleteDone * pclose
" }}}
" Global shortcuts {{{ ========================================================
" Initialize Yankstack plugin first
call yankstack#setup()
" ===== MapLeaders =====
" Set leader keys to ensure their assignment
" <Leader> for global shortcuts, <LocalLeader> for more specific and local usage
let mapleader = ','
let maplocalleader = "\<Space>"
"
" TEST
"
" Translate english word
nnoremap <Leader>tr :silent :OpenBrowser
\ https://translate.google.com/?source=osdd#en/cs/
\<C-r><C-w><CR>
nnoremap <A-t> vip:TransposeWords<CR>
nnoremap T" vip:s/"//g<CR>vip:TransposeWords<CR>
nnoremap T' vip:s/"//g<CR>vip:TransposeWords<CR>
" ===== Change indentation =====
" nnoremap <A-S-H> <<
" nnoremap <A-S-L> >>
" vnoremap <A-S-H> <gv
" vnoremap <A-S-L> >gv
" if ! has('gui_running')
" nnoremap <Esc>H <<
" nnoremap <Esc>L >>
" vnoremap <Esc>H <gv
" vnoremap <Esc>L >gv
" endif
" Maintain Visual Mode after shifting > and <
vnoremap < <gv
vnoremap > >gv
" ===== Command line =====
" Expand %% to path of current buffer in command mode
cnoremap <expr> %% getcmdtype() == ':' ? expand('%:h').'/' : '%%'
" ===== Consistency =====
" Make the behaviour of Y consistent with D and C
" (do the action from here to the end of line)
nnoremap Y y$
" ===== Cut, Copy and Paste =====
" copy selection
vnoremap <C-c> "+y
" copy whole document
nnoremap <C-c>a m`ggVG"*y``
" copy row
nnoremap <C-S-c> "+yy
nnoremap <C-c>r "+yy
" copy word
nnoremap <C-c>w m`viw"+y``
" copy WORD
nnoremap <C-c>W m`viW"+y``
" paste
nnoremap <C-V> "+p
" paste from insert mode
inoremap <C-V> <Esc>"+p
" paste over in visual mode
vnoremap <C-V> d"+gP
" Replace current word with yanked or deleted text (stamping)
nnoremap s "_diwPb
" Don't yank the contents of an overwritten selection (reyank the original content)
" Yankstack plugin i superior (you can paste previously yanked text)
" xnoremap p "_dP
" Yankstack
nmap <A-p> <Plug>yankstack_substitute_older_paste
nmap <A-n> <Plug>yankstack_substitute_newer_paste
" if ! has('gui_running')
" nmap <Esc>p <Plug>yankstack_substitute_older_paste
" nmap <Esc>n <Plug>yankstack_substitute_newer_paste
" endif
" ===== Lint =====
nmap <C-l> :ALEToggle<CR>
" ===== Fix (format) =====
nmap <C-f> :ALEFix<CR>
" ===== Execute (run) part of buffer =====
nnoremap <Leader>E :call ExecuteCurrentLine('bash -c')<CR>
" ===== Exiting =====
" Quit buffer without closing the window (plugin Bbye)
nnoremap Q :Bdelete<CR>
" Quit window
nnoremap <leader>q :q<CR>
" <C-z> minimizes gvim on Windows, which I dont like
" nmap <C-z> <Esc>
" Close preview window more easily
nnoremap <S-Esc> :silent! pclose <Bar> cclose <Bar> lclose <Bar> NERDTreeClose<CR>
" ===== Headings =====
" Make commented heading from current line, using Commentary plugin (no 'noremap')
nmap <LocalLeader>+ O<ESC>65i=<ESC>gccjo<ESC>65i=<ESC>gccyiwk:center 64<CR>0Pjj
nmap <LocalLeader>- Oi<Esc>gcclDjgccwvUoi<Esc>gcclDj
nmap <LocalLeader>_ I<space><ESC>A<space><ESC>05i=<ESC>$5a=<ESC>gcc
" ===== Mouse buttons =====
" Set right mouse button to do paste
nnoremap <RightMouse> "*p
inoremap <RightMouse> <C-r>*
cnoremap <RightMouse> <C-r>*
" ===== Opening =====
" Open current document in browser (save it before)
nnoremap <leader>o :w<CR>:OpenInChrome<CR>
" ===== Open and reload $MYVIMRC =====
nnoremap <leader>V :split $MYVIMRC<CR>
nnoremap <A-s> :split $MYVIMRC<CR>
nnoremap <leader>VV :source $MYVIMRC<CR>
" ===== Plugin toggles =====
nnoremap <A-1> :NERDTreeFind<CR>
" nnoremap <Esc>1 :NERDTreeFind<CR>
nnoremap <A-+> :NERDTreeFind<CR>
" nnoremap <Esc>+ :NERDTreeFind<CR>
nnoremap <leader>u :UndotreeToggle<CR>
nnoremap <leader>G :Goyo<CR>
" ===== Programming shortcuts =====
" Switch end of line character
nnoremap <LocalLeader>; m`:s/;\?$/\=submatch(0) == ';' ? '' : ';'/<CR>``
nnoremap <LocalLeader>: m`:s/:\?$/\=submatch(0) == ':' ? '' : ':'/<CR>``
nnoremap <LocalLeader>, m`:s/,\?$/\=submatch(0) == ',' ? '' : ','/<CR>``
" ===== Saving buffer =====
" Use ctrl+s for saving, also in Insert mode (from mswin.vim)
noremap <C-s> :update<CR>
vnoremap <C-s> <C-C>:update<CR>
inoremap <C-s> <Esc>:update<CR>
nnoremap coS :AutoSaveToggle<CR>
command! E normal :silent w<CR>:silent e<CR>
" ===== Searching and replacing =====
" Highlight current word and all same words (or selections)
" Case sensitive
nnoremap gr mmyiw/\C\<<C-r>"\><CR>:set hls<CR>`m
vnoremap gr y/\C<C-r>"<CR><C-o>:set hls<CR>gvo
" Case insensitive
nnoremap gR mmyiw/\c\<<C-r>"\><CR>:set hls<CR>`m
vnoremap gR y/\c<C-r>"<CR><C-o>:set hls<CR>gvo
" Change current word (or selection) and then every following one
" Case sensitive
nnoremap gy yiw/\C\<<C-r>"\><CR><C-o>:set hls<CR>cgn
vnoremap gy y/\C<C-r>"<CR><C-o>:set hls<CR>cgn
" Case insensitive
nnoremap gY yiw/\c\<<C-r>"\><CR><C-o>:set hls<CR>cgn
vnoremap gY y/\c<C-r>"<CR><C-o>:set hls<CR>cgn
" Go substitute (case sensitive)
vnoremap gs y:set hls<CR>/\C<C-r>"<CR>``:%s/<C-r>"//g<Left><Left>
" Go substitute word (case sensitive)
nnoremap gs :set hls<CR>:%s/\C\<<C-r><C-w>\>//g<Left><Left>
" " Go substitute (case insensitive)
" vnoremap gS y:set hls<CR>/\c<C-r>"<CR>``:%s/<C-r>"//g<Left><Left>
" " Go substitute word (case insensitive)
" nnoremap gS :set hls<CR>:%s/\c\<<C-r><C-w>\>//g<Left><Left>
" Go substitute
vnoremap gs y:set hls<CR>/<C-r>"<CR>``:%s/<C-r>"//g<Left><Left>
" Go count occurances
noremap gC m`:%s///gn<CR>``
" Go find from clipboard
noremap gB /<C-r>*<CR>:set hls<CR>:echo "Search from clipboard for: ".@/<CR>
" Go find from yank register
noremap g/ /<C-r>"<CR>:set hls<CR>:echo "Search from yank for: ".@/<CR>
" Go find last search pattern but as a whole word
nnoremap g> /\<<C-r>/\><CR>
if executable('ag')
set grepprg=ag\ --nogroup\ --nocolor
endif
" Per digit increment
nnoremap g<C-a> s<C-r>=<C-r>"+1<CR><Esc>
" Project wide search
" nnoremap ??? :Ag<Space>
" vnoremap ??? :<C-u>Ag<Space><C-r>*
" Enable alt+letter shortcuts
" Source: https://stackoverflow.com/a/10216459
let c='a'
while c <= 'z'
exec "set <A-".c.">=\e".c
exec "imap \e".c." <A-".c.">"
let c = nr2char(1+char2nr(c))
endw
" set timeout ttimeoutlen=50
nnoremap <A-i> :Lines<CR>
" Interactive replace
nnoremap <M-S-R> :OverCommandLine<CR>%s/
" ===== Swaping =====
" Source http://vim.wikia.com/wiki/Swapping_characters,_words_and_lines
" Push current word after next one
nnoremap <silent> gp "_yiw:s/\(\%#\w\+\)\(\_W\+\)\(\w\+\)/\3\2\1/<CR><c-o>/\w\+\_W\+<CR>:nohls<CR>
" Push current word before previous
nnoremap <silent> gP "_yiw?\w\+\_W\+\%#<CR>:s/\(\%#\w\+\)\(\_W\+\)\(\w\+\)/\3\2\1/<CR><c-o>:nohls<CR>
" ===== Bubble lines up and down =====
" Source http://vimrcfu.com/snippet/110
nnoremap <A-j> :m .+1<CR>==
nnoremap <A-k> :m .-2<CR>==
inoremap <A-j> <Esc>:m .+1<CR>==gi
inoremap <A-k> <Esc>:m .-2<CR>==g
vnoremap <A-j> :m '>+1<CR>gv=gv
vnoremap <A-k> :m '<-2<CR>gv=gv
" if ! has('gui_running')
" nnoremap <Esc>J :m .+1<CR>==
" nnoremap <Esc>K :m .-2<CR>==
" inoremap <Esc>J <Esc>:m .+1<CR>==gi
" inoremap <Esc>K <Esc>:m .-2<CR>==g
" vnoremap <Esc>J :m '>+1<CR>gv=gv
" vnoremap <Esc>K :m '<-2<CR>gv=gv
" endif
" Selects the text that was entered during the last insert mode usage
nnoremap gV `[v`]
" ===== Strings =====
" Surround current word
nnoremap <LocalLeader>" m`viw<esc>a"<esc>hbi"<esc>lel``
nnoremap <LocalLeader>' m`viw<esc>a'<esc>hbi'<esc>lel``
" Surround character with space
nnoremap g<Space> i<Space><Esc>la<Space><Esc>h
" Toggle between single and double quotes
nnoremap g' m`:s#['"]#\={"'":'"','"':"'"}[submatch(0)]#g<CR>``:set nohls<CR>
vnoremap g' m`:s#['"]#\={"'":'"','"':"'"}[submatch(0)]#g<CR>``:set nohls<CR>
" Toggle between backslashes and forward slashes
noremap <silent> g\ :ToggleSlash<CR>
" Toggle leading dash
noremap g- m`:s#^-\?\ *#\=submatch(0) == '- ' ? '' : '- '#g<CR>``
" ===== Function arguments =====
nmap ,[ <Plug>Argumentative_Prev
nmap ,] <Plug>Argumentative_Next
xmap ,[ <Plug>Argumentative_XPrev
xmap ,] <Plug>Argumentative_XNext
nmap ,< <Plug>Argumentative_MoveLeft
nmap ,> <Plug>Argumentative_MoveRight
xmap ia <Plug>Argumentative_InnerTextObject
xmap aa <Plug>Argumentative_OuterTextObject
omap ia <Plug>Argumentative_OpPendingInnerTextObject
omap aa <Plug>Argumentative_OpPendingOuterTextObject
" ===== Windows and Buffers =====
" Set working dir to current file dir, only for current window
nnoremap <leader>. :lcd %:p:h<CR>:echo "CWD changed to ".expand('%:p:h')<CR>
" Create new file in the directory next to the opened file
map <leader>n :e <C-R>=expand("%:p:h") . "/" <CR>
" Open previous buffer
noremap <C-\> :vsplit<CR>:bp<CR>
noremap <A-\> :split<CR>:bp<CR>
" Changing size of windows
nnoremap <C-Right> :vertical resize +2<CR>
nnoremap <C-Left> :vertical resize -2<CR>
nnoremap <C-Up> :resize +2<CR>
nnoremap <C-Down> :resize -2<CR>
" Set middle button to close tab
nnoremap <MiddleMouse> :tabclose<CR>
" ===== Moving in buffer =====
" Move commands acting on display lines
noremap j gj
noremap gj j
noremap k gk
noremap gk k
" ===== Moving in windows =====
" Cycling windows
nnoremap <Tab> <C-W>w
nnoremap <S-Tab> <C-W>W
" Alt+LeftArrow to go back (also with side mouse button)
nnoremap <A-Left> ``
" Jump to left or right window
" nmap <A-l> <C-w>l
" nmap <A-h> <C-w>h
" nmap <A-j> <C-w>j
" nmap <A-k> <C-w>k
" if ! has('gui_running')
" nmap <Esc>l <C-w>l
" nmap <Esc>h <C-w>h
" nmap <Esc>j <C-w>j
" nmap <Esc>k <C-w>k
" endif
" Move screen 10 characters left or right in wrap mode
nnoremap gh 40zh
nnoremap gl 40zl
" Jump around methods
nnoremap <C-j> ]m^
"nnoremap <C-k> [m^
" Hide every except current window
nnoremap <C-S-F12> :only<CR>
nnoremap <C-F12> :echo 'outline'<CR>
" ===== Wrap mode =====
" change wrap and set or unset bottom scroll bar
nnoremap <expr> <leader>w ':set wrap! go'.'-+'[&wrap]."=b\r"
" ===== Location and quickfix windows =====
let g:toggle_list_no_mappings=1
nmap <script> <silent> coa :call ToggleLocationList()<CR>
nmap <script> <silent> coq :call ToggleQuickfixList()<CR>
" ===== Diff =====
nmap <F7> ]c
nmap <S-F7> [c
function! RangerExplorer()
exec "silent !ranger --choosefile=/tmp/vim_ranger_current_file " . expand("%:p:h")
if filereadable('/tmp/vim_ranger_current_file')
exec 'edit ' . system('cat /tmp/vim_ranger_current_file')
call system('rm /tmp/vim_ranger_current_file')
endif
redraw!
endfun
map <Leader>x :call RangerExplorer()<CR>
" }}}
" Appearance shortcuts {{{ ====================================================
" ===== Font size =====
if has('gui_running')
nnoremap <C-kMinus> :let &guifont = substitute(&guifont, ':h\(\d\+\)', '\=":h" . (submatch(1) - 1)', '')<CR>
nnoremap <C-kPlus> :let &guifont = substitute(&guifont, ':h\(\d\+\)', '\=":h" . (submatch(1) + 1)', '')<CR>
endif
" ===== Highlighting =====
" Show highlight groups under cursor
noremap <F10> :echo "hi<" . synIDattr(synID(line("."),col("."),1),"name") . '> trans<'
\ . synIDattr(synID(line("."),col("."),0),"name") . "> lo<"
\ . synIDattr(synIDtrans(synID(line("."),col("."),1)),"name") . "> fgcolor<"
\ . synIDattr(synIDtrans(synID(line("."),col("."),1)),"fg") . ">"<CR>
" }}}
" General commands {{{ ========================================================
" ===== Bufferize =====
" Print output of MORE viewer into buffer
command! -nargs=* -complete=command Bufferize call s:Bufferize(<q-args>)
" Put output of a command into current buffer
command! -nargs=* -complete=command Echo call s:Echo(<q-args>)
" ===== Closing =====
" Closes all buffers except the active one
command! Bonly :call CloseAllBuffersButActive()
" ===== Diff =====
" Vertical diff
command! Dv :vertical diffsplit
" Diff all opened
command! Da :windo diffthis
" Diff off all opened
command! Do :windo diffoff
" ===== Extract matches =====
" Extract the matches of last search from current buffer
command! Extract :%Yankitute//&/g
" Extract matching lines into new buffer (http://vim.wikia.com/wiki/VimTip1063)
command! -nargs=? Filter let @a='' | execute 'g/<args>/y A' | new | setlocal bt=nofile | put! a
" ===== Lists =====
" Creates Perl style list definition from paragraph of items on lines
command! -nargs=* Tolist call MakeListFromLines(<q-args>)
command! -nargs=* Tolistclear call MakeClearListFromLines(<q-args>)
" Reverse from the list to lines
command! Tolines :call MakeLinesFromList()
command! Tolinesclear :call MakeClearLinesFromList()
" ===== Open buffer in =====
" Open current document in browser (save it before)
command! OpenInFirefox :call OpenCurrentDocumentInBrowser('firefox')
command! OpenInChrome :call OpenCurrentDocumentInBrowser('chrome')
command! OpenInVivaldi :call OpenCurrentDocumentInBrowser('vivaldi')
if has('win32')
let g:openbrowser_browser_commands = [
\ {'name': 'rundll32',
\ 'args': 'rundll32 url.dll,FileProtocolHandler {use_vimproc ? uri : uri_noesc}'},
\ {'name': 'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe',
\ 'args': ['start', '{browser}', '{uri}']}
\]
let g:openbrowser_use_vimproc=0
endif
" ===== Repeated lines =====
command! -range=% HighlightRepeats <line1>,<line2>call HighlightRepeats()
command! UnHighlight syn clear Repeat
" ===== Strips tags from buffer =====
command! StripTags call StripTags()
" ===== Strip trailing whitespaces =====
command! StripTrailingWhitespace :call StripTrailingWhitespace()
command! STW :call StripTrailingWhitespace()
" ===== XML and Xpath =====
" Rewrite the buffer with xpath matches only
command! -nargs=1 Xpath :call Xpath(<args>)
command! XMLNewLines call XMLNewLines()
command! XMLSimplify :silent call XMLSimplify()
" }}}
" Filetype specific commands {{{ ==============================================
" Common shortcuts
" <leader>c = compile
" <leader>e = run current line
" <leader>E = run current line with output in split window
" <leader>r = run buffer or selection
" <leader>R = run buffer or selection with output in split window
" <leader>t = run test
" <leader>R = run test with output in split window
" <leader>k = check style
" <leader>f = format file
" <C-CR> = run current block or line
" <c-b> = go to declaration
nnoremap <F1> :DevDocsUnderCursor<CR>
" nnoremap <c-h> K
nnoremap <F2> :cnext<CR>
nnoremap <S-F2> :cprevious<CR>
nnoremap <F3> :lnext<CR>
nnoremap <S-F3> :lprevious<CR>
" ===== Misc filetypes =====
augroup GLOBAL
autocmd!
" Cursor on last editing place in every opened file
autocmd BufReadPost * normal `"
augroup END
augroup EDITING
autocmd!
" Make it so that a curly brace automatically inserts an indented line
autocmd FileType css,perl,php,java,html inoremap {<CR> {<CR>}<Esc>O
augroup END
augroup CSS
autocmd FileType css set omnifunc=csscomplete#CompleteCSS
autocmd BufRead,BufNewFile *.css :ColorSwapFgBg
augroup END
augroup DOSBATCH
autocmd!
autocmd FileType dosbatch set formatoptions -=o
" Run dosbatch bat file
autocmd FileType dosbatch nnoremap <C-CR> ^y$:!<C-r>"<CR>
autocmd FileType dosbatch nnoremap <buffer> <leader>r :w<CR>:Clam %:p<CR>gg<C-w>w
augroup END
augroup HTML
autocmd!
autocmd BufRead,BufNewFile *.cshtml set filetype=html
autocmd FileType html,xml setlocal tabstop=2
autocmd FileType html,xml setlocal softtabstop=2
autocmd FileType html,xml setlocal shiftwidth=2
autocmd FileType html,xml setlocal smartindent
autocmd FileType html nnoremap <C-b> :call JumpToCSS()<CR>
" previous tag on same indentation level
autocmd FileType html,xml nnoremap <C-k> ?^\s\{<C-r>=indent(".")<CR>}\S\+<CR>nww
" next tag on same indentation level
autocmd FileType html,xml nnoremap <C-j> /^\s\{<C-r>=indent(".")<CR>}\S\+<CR>ww
" Given <tag>|</tag> when <CR> then jump to next line
autocmd FileType html,xml inoremap <expr> <CR> Expander()
" Comp
autocmd FileType html,xhtml setlocal omnifunc=htmlcomplete#CompleteTags
augroup END
augroup GNUPLOT
autocmd!
" Compile gnuplot graph
autocmd FileType gnuplot nnoremap <buffer> <leader>c :w<CR>:silent !cmd /c gnuplot -p %<CR>
autocmd FileType gnuplot setlocal commentstring=#\ %s
" Set filetype automatically
autocmd BufRead,BufNewFile *.plt set filetype=gnuplot
augroup END
augroup JAVA
autocmd!
autocmd BufRead,BufNewFile *.jshell set filetype=java
autocmd BufRead,BufNewFile *.jsh set filetype=java
autocmd Filetype java set makeprg=javac\ -cp\ \".;*\"\ %
autocmd Filetype java set errorformat=%A%f:%l:\ %m,%-Z%p^,%-C%.%#
autocmd Filetype java nnoremap <buffer> <leader>c :call MyMake()<CR>
autocmd Filetype java nnoremap <buffer> <leader>r :call MakeAndRun('java -cp ".;*"', '')<CR>
autocmd Filetype java nnoremap <buffer> <leader>R :call MakeAndRunClam('java -cp ".;*"', '')<CR>
augroup END
augroup JAVASCRIPT
autocmd!
autocmd FileType javascript,json setlocal tabstop=2
autocmd FileType javascript,json setlocal softtabstop=2
autocmd FileType javascript,json setlocal shiftwidth=2
autocmd Filetype javascript nnoremap <C-h> :call JSDoc()<CR>
autocmd Filetype javascript vnoremap <C-h> :call JSDoc()<CR>
autocmd Filetype javascript command! -nargs=* -complete=command JSDoc call JSDoc(<q-args>)
autocmd Filetype javascript nnoremap <C-j> j/=\? \?fun<CR>:set nohls<CR>:let @/ = ""<CR>0
autocmd Filetype javascript nnoremap <C-k> /=\? \?fun<CR>N:set nohls<CR>:let @/ = ""<CR>0
autocmd Filetype javascript nnoremap <leader>e :call ExecuteCurrentLine('node -e')<CR>
autocmd Filetype javascript nnoremap <leader>r :call MyRun('node')<CR>
autocmd Filetype javascript vnoremap <leader>r <Esc>:call ExecuteVisualSelection('node -e')<CR>
autocmd FileType javascript nnoremap <leader>R :call MyRunClam('node')<CR>
autocmd FileType javascript vnoremap <leader>R <Esc>:call ExecuteVisualSelectionWithOutput('node')<CR>
autocmd FileType javascript nnoremap <leader>t :!npm test --silent<CR>
autocmd FileType javascript nnoremap <leader>T :!npm test --silent --recursive<CR>
autocmd FileType javascript setlocal omnifunc=javascriptcomplete#CompleteJS
augroup END
augroup TYPESCRIPT
au!
autocmd FileType typescript call SetupFiletype_TypeScript()
augroup END
fun! SetupFiletype_TypeScript()
setlocal tabstop=2
setlocal softtabstop=2
setlocal shiftwidth=2
setlocal makeprg=tsc\ --target=es5\ $*\ %
JsPreTmpl html
nnoremap <buffer> <leader>r :call MakeAndRun('node', 'js')<CR>
nnoremap <buffer> <leader>R :call MakeAndRunClam('node', 'js')<CR>
nnoremap <buffer> <leader>c :call MyMake()<CR>
nnoremap <buffer> <C-g> :TsuSearch<Space>
nnoremap <buffer> <C-b> :TsuDefinition<CR>
nnoremap <buffer> <C-S-G> :TsuReferences<CR>
nnoremap <buffer> <A-F7> :TsuReferences<CR>
nnoremap <buffer> <Esc><F7> :TsuReferences<CR>
nnoremap <buffer> <S-F6> :TsuquyomiRenameSymbol<CR><C-r><C-w>
nnoremap <buffer> <C-h> : <C-u>echo tsuquyomi#hint()<CR>
endfun
augroup JSON
autocmd!
autocmd Filetype json nnoremap <leader>f :%!python -m json.tool<CR>
augroup END
augroup JIRA
autocmd!
" Set filetype automatically
autocmd BufRead,BufNewFile *.jira setlocal filetype=jira
augroup END
" Create Jira style aligned table from tab separated items of one paragraph
" First line will have double | (pipe) characters as separators
command! TTabToJira normal
\ vip:s/\t/|/g<CR>
\ vip:s/^/|\ /<CR>
\ vip:s/$/\ |/<CR>
\ vip:Tabularize/|<CR>
\ {j:s/|\ \?/||/g<CR>
" Create Jira style table from MySQL console output
command! TMysqlToJira normal vap:g/^+/d<CR>kvipo<ESC>:s/\ \?|/||/g<CR>
augroup MARKDOWN
autocmd!
autocmd FileType modula2 setlocal ft =markdown
autocmd FileType markdown nnoremap <C-j> /^#<CR>
autocmd FileType markdown nnoremap <C-k> ?^#<CR>
autocmd FileType markdown setlocal formatoptions=jlnr1
autocmd FileType markdown setlocal comments=b:*,b:+,n:>,b:-
autocmd FileType markdown command! Outline :Voom markdown
" From dash separated heading to spaces and capital letter
autocmd FileType markdown nnoremap <LocalLeader>h :s/-/\ /g<CR>~h
" Prefix # heading
autocmd FileType markdown nnoremap <LocalLeader>0 m`:s/^\(#*\)\ \?//<CR>``
" Underline H1
autocmd FileType markdown nnoremap <LocalLeader>1 yypVr=<Esc>
autocmd FileType markdown nnoremap <LocalLeader>2 m`:s/^\(#*\)\ \?/##\ /<CR>``
autocmd FileType markdown nnoremap <LocalLeader>3 m`:s/^\(#*\)\ \?/###\ /<CR>``
autocmd FileType markdown nnoremap <LocalLeader>4 m`:s/^\(#*\)\ \?/####\ /<CR>``
" bold
autocmd FileType markdown nnoremap <LocalLeader>b viw<Esc>`>a**<Esc>`<i**<Esc>f*;
autocmd FileType markdown vnoremap <LocalLeader>b <Esc>`>a**<Esc>`<i**<Esc>f*;
" italics
autocmd FileType markdown nnoremap <LocalLeader>i viw<Esc>`>a_<Esc>`<i_<Esc>f_
autocmd FileType markdown vnoremap <LocalLeader>i <Esc>`>a_<Esc>`<i_<Esc>f_
" inline code
autocmd FileType markdown nnoremap <LocalLeader>` viw<Esc>`>a`<Esc>`<i`<Esc>f`
autocmd FileType markdown vnoremap <LocalLeader>` <Esc>`>a`<Esc>`<i`<Esc>f`
" fenced code block
autocmd FileType markdown nnoremap <LocalLeader>9 vip<Esc>`<O```<Esc>`>o```<Esc>j
autocmd FileType markdown vnoremap <LocalLeader>9 <Esc>`<O```<Esc>`>o```<Esc>j
" quoutes
autocmd FileType markdown nnoremap <LocalLeader>> vip<C-q>0I><space><Esc>
autocmd FileType markdown vnoremap <LocalLeader>> <C-q>0I><space><Esc>
" unordered list