about summary refs log tree commit diff
path: root/configs/shared/.config/nvim/init.vim
blob: 57cfe7ea6a20510cf60faa320e86384ace6d3c49 (plain) (blame)
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
" -- BEGIN: Vundle config --
set nocompatible              " be iMproved, required
filetype off                  " required

" set the runtime path to include Vundle and initialize
" share Vundle between vim and neovim
set rtp+=~/.vim/bundle/Vundle.vim
set rtp+=~/.config/nvim/bundle/Vundle.vim
call vundle#begin()
" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')

" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'

" Rust IDE features
Plugin 'racer-rust/vim-racer'

set hidden
let g:racer_experimental_completer = 1
autocmd FileType rust nmap         gd <Plug>(rust-def)
autocmd FileType rust nmap         gs <Plug>(rust-def-split)
autocmd FileType rust nmap         gx <Plug>(rust-def-vertical)
autocmd FileType rust nmap <leader>gd <Plug>(rust-doc)

Plugin 'xolox/vim-misc'

" The following are examples of different formats supported.
" Keep Plugin commands between vundle#begin/end.

" Displays git information in airline.
Plugin 'tpope/vim-fugitive'

" easier file navigation
Plugin 'tpope/vim-vinegar'

" Displays git-tracked C*UD ops within gutter.
Plugin 'airblade/vim-gitgutter'

" Fuzzy-finder
Plugin 'kien/ctrlp.vim'

" Grep file contents
Plugin 'mileszs/ack.vim'

" Syntax and other light-weight suppor for a variety of languages
Plugin 'sheerun/vim-polyglot'

" Themes
Plugin 'deviantfero/wpgtk.vim'
Plugin 'rainglow/vim'


" Executes shell commands and pipes output into new Vim buffer.
Plugin 'sjl/clam.vim'

" Multiple cursors for simultaneous edits.
" NOTE: use <C-n> to run miltiple cursors not <C-d>
Plugin 'terryma/vim-multiple-cursors'

" Visualize buffers
Plugin 'vim-airline/vim-airline'
Plugin 'vim-airline/vim-airline-themes'

" Visually align assignments
Plugin 'godlygeek/tabular'

" Visually Highlight and comment code.
Plugin 'tpope/vim-commentary'

" Macros for quotes, parens, etc.
Plugin 'tpope/vim-surround'

" Allows Plugins to be repeated with `.` character
Plugin 'tpope/vim-repeat'

" Pairs of mappings
Plugin 'tpope/vim-unimpaired'

" LISPs support
Plugin 'guns/vim-sexp'
Plugin 'tpope/vim-sexp-mappings-for-regular-people'
let g:sexp_enable_insert_mode_mappings = 0
let g:sexp_filetypes = ''

" Seamlessly navigate Vim and Tmux with similar bindings.
Plugin 'christoomey/vim-tmux-navigator'

" Async `:make` for code linting etc.
Plugin 'neomake/neomake'

" Better buffer mgt than CtrlP
Plugin 'yegappan/mru'

Plugin 'zanglg/nova.vim'

" Emulates Emacs's Helm Swoop search
Plugin 'pelodelfuego/vim-swoop'

" Transparent encryption + decryption
Plugin 'jamessan/vim-gnupg'

" Javascript auto-formatting
" Plugin 'prettier/vim-prettier', {
"   \ 'do': 'yarn install',
  " \ 'for': ['javascript', 'typescript', 'css', 'less', 'scss', 'json', 'graphql', 'markdown'] }

" Support Org mode
Plugin 'jceb/vim-orgmode'

" Autocompletion
Plugin 'junegunn/fzf'

" Text objects made easy
Plugin 'kana/vim-textobj-user'

" Elixir text objects
Plugin 'andyl/vim-textobj-elixir'

" Making HTML editing faster
Plugin 'mattn/emmet-vim'

" Snippets for all languages
Plugin 'honza/vim-snippets'

" Automatic bracket insertion
Plugin 'jiangmiao/auto-pairs'

" Linting & error warnings
Plugin 'vim-syntastic/syntastic'

" Angular.js support
Plugin 'burnettk/vim-angular'

" Asynchronous Linting Engine
Plugin 'w0rp/ale'

call vundle#end()            " required
filetype plugin indent on    " required
" Put your non-Plugin stuff after this line
" -- END: Vundle config --

" Changes <leader> to <space> character.
let mapleader = " "


" Highlight column width
set textwidth=80
set colorcolumn=+0

" autoreload a file when it changes on disk
set autoread

" default to case-insensitive searching
set ignorecase

" JSX configuration
let g:jsx_ext_required = 0


autocmd FileType reason nnoremap <buffer> gd :call LanguageClient_textDocument_definition()<CR>
autocmd FileType reason nnoremap <buffer> gf :call LanguageClient_textDocument_formatting()<CR>
autocmd FileType reason nnoremap <buffer> gh :call LanguageClient_textDocument_hover()<CR>
autocmd FileType reason nnoremap <buffer> gr :call LanguageClient_textDocument_rename()<CR>

" Replace <CR> with G for faster navigation
nnoremap <CR> G
onoremap <CR> G
vnoremap <CR> G

" Mirror ZLE KBD
inoremap <M-'> :echo "Working"<CR>

" Syntastic configuration
set statusline+=%#warningmsg#
set statusline+=%{SyntasticStatuslineFlag()}
set statusline+=%*

let g:syntastic_always_populate_loc_list = 1
let g:syntastic_auto_loc_list = 1
let g:syntastic_check_on_open = 1
let g:syntastic_check_on_wq = 0
" let g:syntastic_javascript_checkers = ['eslint']
let g:syntastic_javascript_eslint_generic = 1
" this is a hack to prevent a false negative
" https://github.com/vim-syntastic/syntastic/issues/1692
" let g:syntastic_javascript_eslint_exec = '/bin/ls'
" let g:syntastic_javascript_eslint_exe = 'npx eslint'
" let g:syntastic_javascript_eslint_args = '-f compact'

" javascript autocompletion
" autocmd FileType javascript setlocal omnifunc=javascriptcomplete#CompleteJS
" autocmd FileType javascript nnoremap <buffer> gf :Prettier<CR>

" Maximize the current window
" Similar to Tmux mapping alt-z in my tmux.conf
nnoremap t% :tab sp<CR>

" Allow C-g to act like C-c the way it does in Emacs
cnoremap <C-g> <C-c>

" Prettier configuration
" let g:prettier#exec_cmd_async = 1
" force Prettier to run on files even without the @format pragma
" let g:prettier#autoformat = 0


" Basic settings
" Thin cursor on INSERT mode
if has('nvim')
  let $NVIM_TUI_ENABLE_CURSOR_SHAPE = 1
endif

set number
set nowrap
set tabstop=2
set expandtab
set shiftwidth=2
set background=dark

syntax enable
colorscheme peacock

" Vim in terminal cannot have a different font from the one set within your
" terminal. However, this setting will set the font for the GUI version.
if has('gui_running')
  set guifont=Operator\ Mono:h12
endif

if has('termguicolors')
  set termguicolors
endif

if &term =~# '^screen'
  let &t_8f = "\<Esc>[38;2;%lu;%lu;%lum"
  let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum"
endif

set history=1000
set undolevels=1000

set t_Co=255

" Support italics
highlight Comment cterm=italic


" quickly edit popular configuration files
nnoremap <leader>ev :vsplit $MYVIMRC<CR>
nnoremap <leader>ee :vsplit ~/.emacs.d/init.el<CR>
nnoremap <leader>ez :vsplit ~/.zshrc<CR>
nnoremap <leader>ea :vsplit ~/aliases.zsh<CR>
nnoremap <leader>ef :vsplit ~/functions.zsh<CR>
nnoremap <leader>el :vsplit ~/variables.zsh<CR>
nnoremap <leader>ex :vsplit ~/.Xresources<CR>

" quickly source your vimrc
nnoremap <leader>sv :source $MYVIMRC<CR>

" quickly edit your snippets
nnoremap <leader>es :vsplit<CR>:edit ~/.vim/bundle/vim-snippets/snippets/reason.snippets<CR>


" Auto resize window splits
autocmd VimResized * wincmd =


" Neomake Settings
autocmd! BufWritePost * Neomake

" Elixir linting
let g:neomake_elixir_credo_maker = {
      \ 'exe': 'mix',
      \ 'args': ['credo', 'list', '%:p', '--format=oneline'],
      \ 'errorformat':
      \   '%W[F] %. %f:%l:%c %m,' .
      \   '%W[F] %. %f:%l %m,' .
      \   '%W[R] %. %f:%l:%c %m,' .
      \   '%W[R] %. %f:%l %m,' .
      \   '%I[C] %. %f:%l:%c %m,' .
      \   '%I[C] %. %f:%l %m,' .
      \   '%-Z%.%#'
      \ }


let g:neomake_elixir_enabled_makers = ['mix', 'credo']

augroup my_error_signs
  au!
  autocmd ColorScheme * hi NeomakeErrorSign ctermfg=203 guifg=#ff5f5f
  autocmd ColorScheme * hi NeomakeWarningSign ctermfg=209 guifg=#ffaf00
  autocmd ColorScheme * hi NeomakeInfoSign ctermfg=183 guifg=#dfafff
  autocmd ColorScheme * hi NeomakeMessageSign ctermfg=27 guifg=#0087ff
augroup END


" templates
if has("autocmd")
  autocmd BufNewFile *.c  0r ~/.config/nvim/templates/boilerplate.c
  autocmd BufNewFile *.rs 0r ~/.config/nvim/templates/boilerplate.rs
endif

let g:neomake_error_sign = {
            \ 'text': '>>',
            \ 'texthl': 'NeoMakeErrorSign',
            \ }

let g:neomake_warning_sign = {
            \ 'text': '>>',
            \ 'texthl': 'NeoMakeWarningSign',
            \ }

let g:neomake_info_sign = {
            \ 'text': '>>',
            \ 'texthl': 'NeoMakeInfoSign',
            \ }

let g:neomake_message_sign = {
            \ 'text': '>>',
            \ 'texthl': 'NeoMakeMessageSign',
            \ }

function! <SID>LocationPrevious()
  try
    lprev
  catch /^Vim\%((\a\+)\)\=:E553/
    llast
  endtry
endfunction

function! <SID>LocationNext()
  try
    lnext
  catch /^Vim\%((\a\+)\)\=:E553/
    lfirst
  endtry
endfunction

nnoremap <Leader>[ :call <SID>LocationPrevious()<CR>
nnoremap <Leader>] :call <SID>LocationNext()<CR>


" Alchemist settings
let g:alchemist#elixir_erlang_src = '/usr/local/share/src'


" Airline Settings
" Enables the list of buffers.
let g:airline#extensions#tabline#enabled = 0

" Buffer numbers alongside files
let g:airline#extensions#tabline#buffer_nr_show = 0

" Shows the filename only.
let g:airline#extensions#tabline#fnamemod = ':t'

" Allow glyphs in airline
let g:airline_powerline_fonts = 1

" Change Airline theme
let g:airline_theme = 'hybrid'


" Vim-Swoop Settings
" Edits colorscheme
let g:swoopHighlight = ["hi! link SwoopBufferLineHi Warning", "hi! link SwoopPatternHi Error"]


" Jump to buffers.
nmap <F1> :1b<CR>
nmap <F2> :2b<CR>
nmap <F3> :3b<CR>
nmap <F4> :4b<CR>
nmap <F5> :5b<CR>
nmap <F6> :6b<CR>
nmap <F7> :7b<CR>
nmap <F8> :8b<CR>
nmap <F9> :9b<CR>


" It's the twenty-first century...no swaps.
set noswapfile


" Allow visual tab completion in command mode
set wildmenu


" Show Vim commands as they're being input.
set showcmd


" Code folding
" set foldmethod=indent
" set foldnestmax=10
" set nofoldenable
" set foldlevel=4


" emulate ci" and ci' behavior
nnoremap ci( f(%ci(
nnoremap ci[ f[%ci[


" extend functionality of <C-e> & <C-y> scrolling
nnoremap <C-e> <C-e>j
vnoremap <C-e> <C-e>j
nnoremap <C-y> <C-y>k
vnoremap <C-y> <C-y>k


" Opens all folds within the buffer
" nnoremap ZZ zR

" Closes all folds within the buffer
" nnoremap zz zM

" Opens all folds beneath the cursor
" NOTE: j is the character to go down
" nnoremap zJ zO

" Opens single fold beneath the cursor
" NOTE: j is the character to go down
" nnoremap zj zo

" Opens single fold beneath the cursor
" NOTE: k is the character to go down
" nnoremap zK zC

" Opens single fold beneath the cursor
" NOTE: k is the character to go down
" nnoremap zk zc


" Save shortcut
nnoremap <C-s> :w<CR>


" Switch to MRU'd buffer
nnoremap <leader><leader> <C-^>


" Alternative MRU to CtrlP MRU
nnoremap <leader>b :MRU<CR>


" Supports mouse interaction.
set mouse=a


" Highlights matches during a search.
set hlsearch

" Clear highlight
noremap <silent> <leader>h :nohlsearch<bar>:echo<CR>


" backspace settings
set backspace=2
set backspace=indent,eol,start


" Javascript specific variables
let g:javascript_plugin_jsdoc = 1

" GlobalListchars
set list
set listchars=tab:··,trail:·,nbsp:·


" Keeps everything concealed at all times. Even when cursor is on the word.
set conceallevel=1
set concealcursor=nvic


" map jk to <Esc>
inoremap jk <Esc>


" Hybrid mode for Vim
inoremap <C-a> <Esc>I
inoremap <C-e> <Esc>A

inoremap <M-b> <S-Left>
inoremap <M-f> <S-Right>

inoremap <C-b> <Left>
inoremap <C-f> <Right>
inoremap <C-p> <Up>
inoremap <C-n> <Down>

" temporarily disable <C-p> in normal mode so it doesn't attempt to index all of
" Google3.
nnoremap <C-p> :echo "You are attempting to index all of Google3. Aborting..."<CR>

" tab maintenence
nnoremap <C-t> :tabnew<CR>
nnoremap <C-w> :tabclose<CR>
nnoremap <Tab> :tabnext<CR>
nnoremap <S-Tab> :tabprevious<CR>

" Manage Vertical and Horizontal splits
nnoremap sl <Esc>:vs<CR><C-w>l
nnoremap sh <Esc>:vs<CR>
nnoremap sj <Esc>:sp<CR><C-w>j
nnoremap sk <Esc>:sp<CR>


" Delete (i.e. "close") the currently opened buffer
" TODO: unless it's a split window, which should be :q
nnoremap <leader>q :bdelete<CR>


" Set CtrlP runtime path
set runtimepath^=~/.vim/bundle/ctrlp.vim


" Pane movement
let g:tmux_navigator_no_mappings = 1

nnoremap <silent> <M-h> :TmuxNavigateLeft<CR>
nnoremap <silent> <M-j> :TmuxNavigateDown<CR>
nnoremap <silent> <M-k> :TmuxNavigateUp<CR>
nnoremap <silent> <M-l> :TmuxNavigateRight<CR>
nnoremap <silent> <M-q> :q<CR>

" make Y do what is intuitive given:
"   D: deletes until EOL
"   C: changes until EOL
"   Y: (should) yank until EOL
nnoremap Y y$


" scrolling and maintaing mouse position
" nnoremap <C-j> j<C-e>
" nnoremap <C-k> k<C-y>


" remap redo key that is eclipsed by `rotate` currently
nnoremap U :redo<CR>


" Define highlighting groups
" NOTE: The ANSII aliases for colors will change when iTerm2 settings are
" changed.
highlight InterestingWord1 ctermbg=Magenta ctermfg=Black
highlight InterestingWord2 ctermbg=Blue ctermfg=Black

" h1 highlighting
nnoremap <silent> <leader>1 :execute '2match InterestingWord1 /\<<c-r><c-w>\>/'<CR>
nnoremap <silent> <leader>x1 :execute '2match none'<CR>
vnoremap <silent> <leader>1 :execute '2match InterestingWord1 /\<<c-r><c-w>\>/'<CR>

" h2 highlighting
nnoremap <silent> <leader>2 :execute '3match InterestingWord2 /\<<c-r><c-w>\>/'<CR>
nnoremap <silent> <leader>x2 :execute '3match none'<CR>

"clear all highlighted groups
nnoremap <silent> <leader>xx :execute '2match none'<CR> :execute '3match none'<CR> hh


" pasteboard copy & paste
set clipboard+=unnamedplus


" Manage 80 char line limits
highlight OverLength1 ctermbg=Magenta ctermfg=Black
highlight OverLength2 ctermbg=LightMagenta ctermfg=Black
highlight OverLength3 ctermbg=White ctermfg=Black
" match OverLength3 /\%81v.\+/
match OverLength2 /\%91v.\+/
" match OverLength3 /\%101v.\+/

nnoremap <leader>w :w<CR>


" Resize split to 10,20,...,100 chars
" Uncomment the next lines for support at those sizes.
" These bindings interfere with the highlight groups, however.
" Increases the width of a vertical split.
" nnoremap <leader>1 :vertical resize 10<CR>
" nnoremap <leader>2 :vertical resize 20<CR>
nnoremap <leader>3 :vertical resize 30<CR>
nnoremap <leader>4 :vertical resize 40<CR>
nnoremap <leader>5 :vertical resize 50<CR>
nnoremap <leader>6 :vertical resize 60<CR>
nnoremap <leader>7 :vertical resize 70<CR>
nnoremap <leader>8 :vertical resize 80<CR>
nnoremap <leader>9 :vertical resize 90<CR>
nnoremap <leader>0 :vertical resize 100<CR>


" Increases the height of a horizontal split.
nnoremap <leader>v1 :resize 5<CR>
nnoremap <leader>v2 :resize 10<CR>
nnoremap <leader>v3 :resize 15<CR>
nnoremap <leader>v4 :resize 20<CR>
nnoremap <leader>v5 :resize 25<CR>
nnoremap <leader>v6 :resize 30<CR>
nnoremap <leader>v7 :resize 35<CR>
nnoremap <leader>v8 :resize 40<CR>
nnoremap <leader>v9 :resize 45<CR>
nnoremap <leader>v0 :resize 50<CR>


" BOL and EOL
nnoremap H ^
vnoremap H ^
nnoremap L $
vnoremap L $


" Search for visually selected text
vnoremap // y/<C-r>"<CR>N


" trim trailing whitespace on save
" Are there any file type where I wouldn't want this?
autocmd BufWritePre *.{js,py,tpl,less,html,ex,exs,txt,hs,java,rs,ml} :%s/\s\+$//e


" Use .gitignore file to populate Ctrl-P
let g:ctrlp_user_command = ['.git', 'cd %s && git ls-files . -co --exclude-standard', 'find %s -type f']


" Ignores dirs and files
let g:ctrlp_custom_ignore = {
  \ 'dir':  'node_modules',
  \ 'file': '\v\.(exe|dll|png|jpg|jpeg)$'
\}


" WIP: Run elixir tests on that line
" TODO: only register binding in *.exs? file extensions
nnoremap <leader>t :call ExTestToggle()<CR>


" Jumps from an Elixir module file to an Elixir test file.
fun! ExTestToggle()
  if expand('%:e') == "ex"

    let test_file_name = expand('%:t:r') . "_test.exs"
    let test_file_dir = substitute(expand('%:p:h'), "/lib/", "/test/", "")
    let full_test_path = join([test_file_dir, test_file_name], "/")

    e `=full_test_path`

  elseif match(expand('%:t'), "_test.exs") != -1

    let test_file_name = expand('%:t:r')
    let offset_amt = strlen(test_file_name) - strlen("_test")
    let module_file_name = strpart(test_file_name, 0, offset_amt) . ".ex"
    let module_file_dir = substitute(expand('%:p:h'), "/test/", "/lib/", "")
    let full_module_path = join([module_file_dir, module_file_name], "/")

    e `=full_module_path`

  endif
endfun


" Creates intermediate directories and file to match current buffer's filepath
fun! CreateNonExistingDirsAndFile()
  ! echo "Creating directory..." && mkdir -p %:p:h && echo "Created directory." && echo "Creating file..." && touch %:t:p && echo "Created file."

  " Write the buffer to the recently created file.
  w
endfun