-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy path.vimrc
1124 lines (842 loc) · 28.9 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
set nocompatible
"===============================================================================
" vim-plug
"===============================================================================
call plug#begin('~/.vim/plugged')
Plug 'Shougo/vimproc.vim', { 'do': 'make' }
" Fuzzy search
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
Plug 'junegunn/fzf.vim'
" Code completion
" Plug 'Valloric/YouCompleteMe', { 'on': [] }
" Snippets
" Plug 'SirVer/ultisnips', { 'on': [] }
" Plug 'honza/vim-snippets'
" Marks
" Plug 'airblade/vim-gitgutter'
" Comments
Plug 'scrooloose/nerdcommenter'
" Navigation
Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' }
Plug 'ton/vim-bufsurf'
" Syntax checker
Plug 'Chiel92/vim-autoformat'
Plug 'sbdchd/neoformat'
Plug 'hynek/vim-python-pep8-indent'
Plug 'fisadev/vim-isort'
Plug 'w0rp/ale'
" Shell
Plug 'thinca/vim-quickrun'
" Git
Plug 'tpope/vim-fugitive'
Plug 'tpope/vim-rhubarb'
Plug 'junegunn/gv.vim'
Plug 'mattn/webapi-vim'
Plug 'mattn/gist-vim'
" Motions
Plug 'rhysd/clever-f.vim'
" Plug 'easymotion/vim-easymotion'
" Plug 'justinmk/vim-sneak'
" Text Objects
Plug 'tpope/vim-surround'
Plug 'tpope/vim-repeat'
Plug 'kana/vim-textobj-user'
" Plug 'kana/vim-textobj-entire' " ae, ie
Plug 'kana/vim-textobj-line' " al, il
Plug 'terryma/vim-expand-region'
" Tags
" Plug 'xolox/vim-misc'
" Plug 'xolox/vim-easytags'
" Color themems
Plug 'junegunn/seoul256.vim'
" Misc
Plug 'kchmck/vim-coffee-script'
Plug 'leafgarland/typescript-vim'
Plug 'mtth/scratch.vim'
" Plug 'mhinz/vim-startify'
Plug 'terryma/vim-smooth-scroll'
Plug 'terryma/vim-multiple-cursors'
Plug 'hashivim/vim-terraform'
" Plug 'jiangmiao/auto-pairs'
Plug 'vimwiki/vimwiki', { 'branch': 'dev' }
Plug 'metakirby5/codi.vim'
Plug 'junegunn/vim-peekaboo'
Plug 'junegunn/goyo.vim'
call plug#end()
filetype plugin indent on
syntax enable
runtime macros/matchit.vim
"===============================================================================
" Local Settings
" ===============================================================================
try
source ~/.vimrc.local
catch
endtry
"===============================================================================
" General Settings
"===============================================================================
" Set augroup
augroup MyAutoCmd
autocmd!
augroup END
syntax on
set lazyredraw
set ttyfast
" Solid line for vsplit separator
set fcs=vert:│
" Don't show the intro
set shortmess+=I
" Turn on the mouse in all modes
set mouse=a
" Give one virtual space at end of line
set virtualedit=onemore
" Turn on line number
set number
" Always splits to the right and below
set splitright
set splitbelow
" Boost performance of rendering long lines
set synmaxcol=300
" Colorscheme
" 256bit terminal
set t_Co=256
let g:seoul256_background = 234
colorscheme seoul256
" Sets how many lines of history vim has to remember
set history=1000
" Set to auto read when a file is changed from the outside
set autoread
" Set to auto write file
set autowriteall
" Display unprintable chars
set list
set listchars=tab:▸\ ,extends:❯,precedes:❮,nbsp:␣
set showbreak=↪
" listchar=trail is not as flexible, use the below to highlight trailing
" whitespace
highlight ExtraWhitespace ctermbg=red guibg=red
match ExtraWhitespace /\s\+$/
" Minimal number of screen lines to keep above and below the cursor
set scrolloff=10
" How many lines to scroll at a time, make scrolling appears faster
set scrolljump=5
" Min width of the number column to the left
set numberwidth=1
" Open all folds initially
set foldmethod=indent
set foldlevelstart=99
" No need to show mode
set noshowmode
" Auto complete setting
set completeopt=longest,menuone
set wildmode=list:longest,full
set wildmenu "turn on wild menu
set wildignore=*.o,*.obj,*~ "stuff to ignore when tab completing
set wildignore+=*DS_Store*
set wildignore+=vendor/rails/**
set wildignore+=vendor/cache/**
set wildignore+=*.gem
set wildignore+=log/**
set wildignore+=tmp/**
set wildignore+=*.png,*.jpg,*.gif
set wildignore+=*.so,*.swp,*.zip,*/.Trash/**,*.pdf,*.dmg,*/Library/**,*/.rbenv/**
set wildignore+=*/.nx/**,*.app
" Allow changing buffer without saving it first
set hidden
" Set backspace config
set backspace=eol,start,indent
" Case insensitive search
set ignorecase
set smartcase
" Set sensible heights for splits
" set winheight=50
" Make search act like search in modern browsers
set incsearch
" Make regex a little easier to type
set magic
" Don't show matching brackets
set noshowmatch
" Show incomplete commands
set showcmd
" Turn off sound
set vb
set t_vb=
" Always show the statusline
set laststatus=2
" Explicitly set encoding to utf-8
set encoding=utf-8
" Column width indicator
set colorcolumn=+1
" Lower the delay of escaping out of other modes
" keycode times out fast, mapping times out in a bit more time
set timeout timeoutlen=1000 ttimeout ttimeoutlen=1
" Reload vimrc when edited
" autocmd MyAutoCmd BufWritePost .vimrc,_vimrc,vimrc,.gvimrc,_gvimrc,gvimrc
" \ so $MYVIMRC | if has('gui_running') | source $MYGVIMRC | endif | AirlineRefresh
autocmd MyAutoCmd BufWritePost .vimrc,_vimrc,vimrc,.gvimrc,_gvimrc,gvimrc
\ so $MYVIMRC | if has('gui_running') | source $MYGVIMRC | endif
try
lang en_us
catch
endtry
" Turn backup off
set nobackup
set nowritebackup
set noswapfile
" Tab settings
set expandtab
set shiftwidth=2
set tabstop=8
set softtabstop=2
set smarttab
" Text display settings
set linebreak
set textwidth=120
set autoindent
set nowrap
set whichwrap+=h,l,<,>,[,]
" Writes to the unnamed register also writes to the * and + registers. This
" makes it easy to interact with the system clipboard
if has ('unnamedplus')
set clipboard=unnamedplus
else
set clipboard=unnamed
endif
" Use a low updatetime. This is used by CursorHold
set updatetime=1000
" I like my word boundary to be a little bigger than the default
" FIXME Apparently this affects html indenting. Figure out what the problem is
" set iskeyword+=<,>,[,],:,-,`,!
" set iskeyword-=_
" Cursor settings. This makes terminal vim sooo much nicer!
" Tmux will only forward escape sequences to the terminal if surrounded by a DCS
" sequence
if exists('$TMUX')
let &t_SI = "\<Esc>Ptmux;\<Esc>\<Esc>]50;CursorShape=1\x7\<Esc>\\"
let &t_EI = "\<Esc>Ptmux;\<Esc>\<Esc>]50;CursorShape=0\x7\<Esc>\\"
else
let &t_SI = "\<Esc>]50;CursorShape=1\x7"
let &t_EI = "\<Esc>]50;CursorShape=0\x7"
endif
" Diff options
set diffopt=filler,vertical
" Disable viminfo, causes startup and shutdown to take longer
set viminfo='10,<0,s0,h,/100,:100,@0
"===============================================================================
" Leader Key Mappings
"===============================================================================
" Map leader and localleader key to comma
let mapleader = ","
let g:mapleader = ","
let maplocalleader = ","
let g:maplocalleader = ","
" <Leader>1: Toggle between paste mode
nnoremap <silent> <Leader>1 :set paste!<cr>
" <Leader>2: TODO
" <Leader>tab: TODO
" <Leader>q: Quit all, very useful in vimdiff
nnoremap <Leader>q :qa<cr>
" <Leader>w: TODO
" <Leader>e: Fast editing of the .vimrc
nnoremap <Leader>e :e! ~/.vimrc<cr>
" <Leader>r: TODO
" <Leader>t: TODO
" <Leader>y: TODO
" <Leader>u: TODO
" <Leader>o: TODO
" <Leader>p: TODO
" <Leader>a: TODO
nnoremap <Leader>a :lopen<CR>
" <Leader>s: TODO
" <Leader>d: TODO
" <Leader>f: Autoformat
nnoremap <silent> <Leader>f :Autoformat<CR>
" <Leader>g: Fugitive shortcuts
" <Leader>z: TODO
" <Leader>x: TODO
" <Leader>c*: NERDCommenter mappings
" <Leader>cd: Switch to the directory of the open buffer
nnoremap <Leader>cd :cd %:p:h<cr>:pwd<cr>
" <Leader>v: TODO
" <Leader>b: TODO
" <Leader>n: NERDTreeFind
nnoremap <silent> <Leader>n :NERDTreeFind<cr> :wincmd p<cr>
" <Leader>m: Maximize current split
nnoremap <Leader>m <C-w>_<C-w><Bar>
" <Leader><space>: TODO
" <Leader>,: Switch to previous split
nnoremap <Leader>, <C-w>p
"===============================================================================
" Command-line Mode Key Mappings
"===============================================================================
" Bash like keys for the command line. These resemble personal zsh mappings
cnoremap <c-a> <home>
cnoremap <c-e> <end>
" Ctrl-[hl]: Move left/right by word
cnoremap <c-h> <s-left>
cnoremap <c-l> <s-right>
cnoremap <c-j> <down>
cnoremap <c-k> <up>
cnoremap <c-f> <left>
cnoremap <c-g> <right>
" Ctrl-v: Paste
cnoremap <c-v> <c-r>"
" w!!: Writes using sudo
cnoremap w!! w !sudo tee % >/dev/null
autocmd MyAutoCmd CmdwinEnter : map <buffer> <cr> <cr>
"===============================================================================
" Normal Mode Key Mappings
"===============================================================================
" q: record macros
" w: Move word forward
" e: Move to end of word
" r: Replace single character
" t: Find till
" y: Yank. Last yank is always stored in register 0. So paste with "0p if you did a delete after the yank
" u: Undo
" i: Insert before cursor
" o: Insert line below cursor
" p: Paste
nnoremap p gp
" [: Many functions
" ]: Many functions
" \: Toggle comment
nmap \ <Leader>c<space>
" a: Insert after cursor
" s: EasyMotion
" d: Delete. Access it from register "" or "1-9
" f: Clever-f
" g: Many functions
" gp to visually select pasted text
nnoremap <expr> gp '`[' . strpart(getregtype(), 0, 1) . '`]'
" h: Left
" j: Down
" k: Up
" l: Right
" ;: Command mode
noremap ; :
" ': Go to mark
" z: Many functions
" x: Delete char
" c: Change into the blackhole register to not clobber the last yank
nnoremap c "_c
" v: Visual mode
" b: Move word backward
" n: Next, keep search matches in the middle of the window
nnoremap n nzzzv
" m: Marks
" ,: Leader
" .: Repeat last command
" /" Search
" Up Down Left Right move pane
nnoremap <up> <c-w>k
nnoremap <down> <c-w>j
nnoremap <left> <c-w>h
nnoremap <right> <c-w>l
" Enter: Highlight cursor location
" nnoremap <silent> <cr> :call CursorPing()<CR>
" Backspace: Toggle search highlight
nnoremap <bs> :set hlsearch! hlsearch?<cr>
" Tab: Same as <Ctrl-i> on the command line
" Space: Scratch
nnoremap <space> :Scratch<CR>
"===============================================================================
" Normal Mode Shift Key Mappings
"===============================================================================
" Shift-Tab: NERDTree
nnoremap <silent> <S-Tab> :NERDTreeToggle<CR>
" Shift-q: Closes the window
nnoremap Q :q!<cr>
" Shift-w: Move to start of next word
" Shift-e: Move to end of word forward
" Shift-r: Reindent entire file
nnoremap R mqHmwgg=G`wzt`q
" Shift-t: Finds till backwards
" Shift-y: Remove join lines to this, Y looks like a join of two lines into one
noremap Y J
" Shift-u: Redos since 'u' undos
nnoremap U :redo<cr>
" Shift-i: Insert at beginning of line
" Shift-o: Insert line above
" Shift-p: Paste above line
" Shift-[: Beginning of paragraph
" Shift-]: End of paragraph
" Shift--(_): Quick horizontal splits
nnoremap _ :sp<cr>
" Shift-\(|): Quick vertical splits
nnoremap <bar> :vsp<cr>
" Shift-a: Insert at end of line
" Shift-s: Split and return to normal mode
nnoremap S i<cr><esc>
" Shift-d: Deletes til the end of line
" Shift-f: Finds backwards
" Shift-g: Go to end of file
" Shift-h: Go to beginning of line.
noremap H ^
" Shift-j: expand-region
map K <Plug>(expand_region_expand)
" Shift-k: shrink-region
map J <Plug>(expand_region_shrink)
" Shift-l: Go to end of line
noremap L g_
" :: TODO
" Shift-'("): Handles registers
" Shift-z: Bufsurf back
nnoremap <silent> Z :BufSurfBack<CR>
" Shift-z: Bufsurf forward
nnoremap <silent> X :BufSurfForward<CR>
" Shift-c: Deletes rest of line and go to insert mode
" Shift-v: Visual line mode
" Shift-b: Move word backward (TODO Replaced by <C-H>, maybe remap?)
" Shift-n: Find next occurrence backward
nnoremap N Nzzzv
" Shift-m: Move cursor to mid screen (TODO Remap since I don't ever use this)
nmap <silent> M <Plug>(ale_next_wrap)
" <: Indent left
" >: Indent right
" ?: Search backwards
" +/-: Increment number
nnoremap + <c-a>
nnoremap - <c-x>
"===============================================================================
" Normal Mode Ctrl Key Mappings
"===============================================================================
" Ctrl-q: Visual block mode
" Ctrl-w: Window management
" Ctrl-e: TODO
" Ctrl-r: Show command history
nmap <c-r> :History:<CR>
" Ctrl-t: Go to opposite tag
nmap <c-t> %
" Ctrl-y: (Scroll up. Ctrl-k is much more effective TODO Remap)
" Ctrl-u: Scroll half a screen up smoothly
noremap <silent> <c-u> :call smooth_scroll#up(&scroll, 5, 1)<CR>
" Ctrl-i: Go forward in the jumplist, also realigns screen. See mapping for
nnoremap <c-i> <c-i>zzzv
" Ctrl-o: Go back in the jumplist, also realign the screen
nnoremap <c-o> <c-o>zzzv
" Ctrl-p: Recent files
nnoremap <c-p> :History<CR>
" Ctrl-[: Esc
" Ctrl-]: Go forward in tag stack
" Ctrl-\: Quick outline
nmap <silent> <c-\> :BTags<CR>
" Ctrl-a: All buffers
nnoremap <c-a> :Buffers<CR>
" Ctrl-s: Save
nmap <c-s> :w!<CR>
" Ctrl-d: Scroll half a screen down smoothly
noremap <silent> <c-d> :call smooth_scroll#down(&scroll, 5, 1)<CR>
" Ctrl-f: fzf
nnoremap <c-f> :Ag
" Ctrl-g: GitFiles
nmap <c-g> :GitFiles<CR>
" Ctrl-h: Move word back. Consistent with zsh
noremap <c-h> B
inoremap <c-h> <c-o>B
" Ctrl-j: Scroll + move down through the file
" noremap <c-j> 5<c-e>5j
noremap <c-j> 5<c-e>
" Ctrl-k: Scroll + move up through the file
" noremap <c-k> 5<c-y>5k
noremap <c-k> 5<c-y>
" Ctrl-l: Move word forward. Consistent with zsh
noremap <c-l> W
inoremap <c-l> <c-o>W
" Ctrl-;: Vim can't map this
" Ctrl-': Vim can't map this
" Ctrl-z: This is the command key for tmux
" Ctrl-x: Cycle through the splits. I don't ever use enough splits to justify
" wasting 4 very easy to hit keys for them.
nnoremap <c-x> <c-w>w
" Ctrl-c: FZF commands
nnoremap <c-c> :Commands<CR>
" Ctrl-v: Paste (works with system clipboard due to clipboard setting earlier)
nnoremap <c-v> p
" Ctrl-b: Go to tag
nnoremap <c-b> <c-]>
" Ctrl-n: Next cursor in MultiCursor mode
" Ctrl-m: Same as Enter
" Ctrl-,: Vim can't map this
" Ctrl-.: Vim can't map this
" Ctrl-/: Vim can't map this
" Ctrl-Space: FZF files
nnoremap <NUL> :Files<CR>
"===============================================================================
" Insert Mode Ctrl Key Mappings
"===============================================================================
" Ctrl-q: Quoted insert. Useful for doing key binding
" Ctrl-w: Delete previous word, create undo point
inoremap <c-w> <c-g>u<c-w>
" Ctrl-e: Go to end of line
inoremap <c-e> <esc>A
" Ctrl-r: Insert register
" Ctrl-t: Indent shiftwidth
" Ctrl-y: Insert char above cursor
" TODO: When do I ever use this?
" Ctrl-u: Delete til beginning of line, create undo point
inoremap <c-u> <c-g>u<c-u>
" Ctrl-i: Tab
" Ctrl-o: Execute one normal mode command
" Ctrl-p: Auto complete previous
" TODO: When do I ever use this?
" Ctrl-a: Go to begin of line
inoremap <c-a> <esc>I
" Ctrl-s: Save
inoremap <c-s> <esc>:w<CR>
" Ctrl-d: Unindent shiftwidth
" Ctrl-f: Move cursor left
inoremap <c-f> <Left>
" Ctrl-g: Move cursor right
silent! iunmap <c-g>s
silent! iunmap <c-g>S
inoremap <c-g> <Right>
" Ctrl-h: Move word left
inoremap <c-h> <c-o>B
" Ctrl-j: Move cursor up
inoremap <expr> <c-j> pumvisible() ? "\<C-e>\<Down>" : "\<Down>"
" Ctrl-k: Move cursor up
inoremap <expr> <c-k> pumvisible() ? "\<C-e>\<Up>" : "\<Up>"
" Ctrl-l: Move word right
inoremap <c-l> <c-o>W
" Ctrl-z: This is the command key for tmux
" Ctrl-x: Delete char under cursor. (If we simply use x, it wouldn't delete
" newline chars
" inoremap <c-x> <right><c-o>X
" Ctrl-c: Inserts line below
inoremap <c-c> <c-o>o
" Ctrl-v: Paste. For some reason, <c-o> is not creating an undo point in the
" mapping
inoremap <c-v> <c-g>u<c-o>gP
" Ctrl-b: TODO
" Ctrl-n: Auto complete next
" Ctrl-m: Same as Enter
" Ctrl-space: YCM
" Ctrl-/: Undo
inoremap <c-_> <c-o>u
"===============================================================================
" Visual Mode Ctrl Key Mappings
"===============================================================================
" Ctrl-c: Copy (works with system clipboard due to clipboard setting)
vnoremap <c-c> y`]
" Ctrl-r: Easier search and replace
vnoremap <c-r> "hy:%s/<c-r>h//gc<left><left><left>
" Ctrl-s: Easier substitue
vnoremap <c-s> :s/\%V//g<left><left><left>
" Ctrl-f: Find highlight word with FZF
vnoremap <c-f> "hy:Ag <c-r>h<cr>
"===============================================================================
" Normal Mode Meta/Alt Key Mappings
"===============================================================================
" Fix alt key keycodes. Using keycodes instead of escape sequence for mapping will use ttimeout instead of timeout,
" which means pressing escape will not cause a delay.
let c='a'
while c <= 'z'
exec "set <A-".c.">=\e".c
exec "set <A-".toupper(c).">=\e".toupper(c)
let c = nr2char(1+char2nr(c))
endw
" Alt-a: Select all
nnoremap <silent> <A-a> :keepjumps normal ggVG<CR>
" Alt-s: isort and format
nnoremap <silent> <A-s> :Isort<CR>:Neoformat<CR>
" Alt-h: tmux
" Alt-j: Move current line down
nnoremap <silent> <A-j> mz:m+<cr>`z==
" Alt-k: Move current line up
nnoremap <silent> <A-k> mz:m-2<cr>`z==
" Alt-l: tmux
" Alt-Shift-j: Duplicate line down
nnoremap <silent> <A-J> mzyyp`zj
" Alt-Shift-k: Duplicate line up
nnoremap <silent> <A-K> mzyyp`z
" Alt-o: Jump back in the changelist
nnoremap <A-o> g;
" Alt-i: Jump forward in the changelist
nnoremap <A-i> g,
" Alt-n: tmux
"===============================================================================
" Insert Mode Meta/Alt Key Mappings
"===============================================================================
" Alt-j: Move current line down
" imap <A-j> <esc><m-j>a
" Alt-k: Move current line down
" imap <A-k> <esc><m-k>a
"===============================================================================
" Visual Mode Meta/Alt Key Mappings
"===============================================================================
" Alt-j: Move selections down
vnoremap <A-j> :m'>+<cr>`<my`>mzgv`yo`z
" Alt-k: Move selections up
vnoremap <A-k> :m'<-2<cr>`>my`<mzgv`yo`z
"===============================================================================
" Space Key Mappings
"===============================================================================
"===============================================================================
" Visual Mode Key Mappings
"===============================================================================
" y: Yank and go to end of selection
xnoremap y y`]
" p: Paste in visual mode should not replace the default register with the
" deleted text
xnoremap p "_dP
" J/K: Move visual block
vnoremap <c-j> :m '>+1<CR>gv=gv
vnoremap <c-k> :m '<-2<CR>gv=gv
" \: Toggle comment
xmap \ <Leader>c<space>
" Enter: Highlight visual selections
xnoremap <silent> <CR> y:let @/ = @"<cr>:set hlsearch<cr>
" Backspace: Delete selected and go into insert mode
xnoremap <bs> c
" Space: QuickRun
xnoremap <Space> :QuickRun<CR>
" <|>: Reselect visual block after indent
xnoremap < <gv
xnoremap > >gv
" .: repeats the last command on every line
xnoremap . :normal.<cr>
" @: repeats macro on every line
xnoremap @ :normal@
" Tab: Indent
xmap <c-i> >
" shift-tab: unindent
xmap <s-tab> <
"===============================================================================
" Operator Pending Mode Key Mappings
"===============================================================================
"===============================================================================
" Autocommands
"===============================================================================
function! CursorPing()
set cursorline cursorcolumn
redraw
sleep 200m
set nocursorline nocursorcolumn
endfunction
" q quits in certain page types. Don't map esc, that interferes with mouse input
autocmd MyAutoCmd FileType help,quickrun
\ if (!&modifiable || &ft==#'quickrun') |
\ nnoremap <silent> <buffer> q :q<cr>|
\ nnoremap <silent> <buffer> <esc><esc> :q<cr>|
\ endif
autocmd MyAutoCmd FileType qf nnoremap <silent> <buffer> q :q<CR>
" json = javascript syntax highlight
autocmd MyAutoCmd FileType json setlocal syntax=javascript
" Diff mode settings
" au MyAutoCmd FilterWritePre * if &diff | exe 'nnoremap <c-p> [c' | exe 'nnoremap <c-n> ]c' | endif
" Quickfix
autocmd MyAutoCmd FileType qf call AdjustWindowHeight(3, 50)
function! AdjustWindowHeight(minheight, maxheight)
exe max([min([line("$"), a:maxheight]), a:minheight]) . "wincmd _"
endfunction
"===============================================================================
" NERDTree
"===============================================================================
let NERDTreeShowBookmarks=1
let NERDTreeShowHidden=1
let NERDTreeIgnore=['\~$', '\.swp$', '\.git', '\.hg', '\.svn', '\.bzr', '\.pyc', '__pycache__', '\.cache', '\.idea']
autocmd MyAutoCmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif
"===============================================================================
" NERDCommenter
"===============================================================================
" Add spaces after comment delimiters by default
let g:NERDSpaceDelims = 1
" Use compact syntax for prettified multi-line comments
let g:NERDCompactSexyComs = 1
" Align line-wise comment delimiters flush left instead of following code indentation
let g:NERDDefaultAlign = 'left'
" Allow commenting and inverting empty lines (useful when commenting a region)
let g:NERDCommentEmptyLines = 1
" Enable trimming of trailing whitespace when uncommenting
let g:NERDTrimTrailingWhitespace = 1
"===============================================================================
" ALE
"===============================================================================
let g:ale_linters = {
\ 'javascript': ['eslint'],
\ 'python': ['flake8'],
\}
let g:ale_python_flake8_executable = 'python'
let g:ale_python_flake8_options = '-m flake8 --ignore=E501'
"===============================================================================
" Fugitive
"===============================================================================
nnoremap <Leader>gb :Gblame<cr>
nnoremap <Leader>gc :Gcommit<cr>
nnoremap <Leader>gd :Gdiff<cr>
nnoremap <Leader>gp :Git push<cr>
nnoremap <Leader>gr :Gremove<cr>
nnoremap <Leader>gs :Gstatus<cr>
nnoremap <Leader>gw :Gwrite<cr>
" Quickly stage, commit, and push the current file. Useful for editing .vimrc
nnoremap <Leader>gg :Gwrite<cr>:Gcommit -m 'update'<cr>:Git push<cr>
"===============================================================================
" QuickRun
"===============================================================================
" let g:quickrun_config = {}
" let g:quickrun_config['*'] = {
" \ 'runner/vimproc/updatetime' : 100,
" \ 'outputter' : 'buffer',
" \ 'runner' : 'vimproc',
" \ 'running_mark' : 'バン(∩`・ω・)バンバンバンバン゙ン',
" \ 'into' : 1,
" \ 'runmode' : 'async:remote:vimproc'
" \}
" QuickRun triggers markdown preview
" let g:quickrun_config.markdown = {
" \ 'runner': 'vimscript',
" \ 'command': ':InstantMarkdownPreview',
" \ 'exec': '%C',
" \ 'outputter': 'null'
" \}
"===============================================================================
" Markdown
"===============================================================================
" These are ammended on top of the existing markdown settings from
" tpope/vim-markdown
autocmd MyAutoCmd FileType markdown call s:markdown_settings()
function! s:markdown_settings()
" Auto insert bullet when constructing lists
setlocal comments=b:-
setlocal formatoptions+=ro
setlocal wrap
setlocal tw=0
inoremap <buffer> <Tab> <C-t>
" Since completion is off, reassign tab and shift-tab to indent and unindent
" in insert mode
inoremap <buffer> <S-Tab> <C-d>
" Make the delete key in insert mode delete the bullet point in 1 keystroke
inoremap <silent> <buffer> <bs> <C-r>=<SID>markdown_delete_key()<CR>
endfunction
function! s:markdown_delete_key()
if getline(".") =~ '^\s*- $'
return "\<bs>\<bs>"
else
return "\<bs>"
endif
endfunction
"===============================================================================
" Go
"===============================================================================
autocmd MyAutoCmd FileType go
\ setlocal nolist |
\ setlocal softtabstop=8 |
\ setlocal shiftwidth=8 |
\ setlocal noexpandtab
"===============================================================================
" Python
"===============================================================================
autocmd MyAutoCmd FileType python
\ setlocal softtabstop=4 |
\ setlocal shiftwidth=4 |
\ setlocal tabstop=4 |
\ setlocal textwidth=140