-
Notifications
You must be signed in to change notification settings - Fork 0
/
.vimrc.plug
766 lines (630 loc) · 23 KB
/
.vimrc.plug
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
" .vimrc
" Author: Nadeem Shabir
" Source: https://github.com/kiyanwang/dotfiles/.vimrc
" This now uses vim-plug to manage plugins
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => VIM - PLUG
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" This will load and install vim-plug if it isn't already installed.
" Load vim-plug
if empty(glob("~/.vim/autoload/plug.vim"))
execute '!curl -fLo ~/.vim/autoload/plug.vim https://raw.github.com/junegunn/vim-plug/master/plug.vim'
endif
call plug#begin('~/.vim/plugged')
Plug 'tpope/vim-fugitive'
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'junegunn/fzf.vim'
Plug 'rking/ag.vim'
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
Plug 'ryanoasis/vim-devicons'
Plug 'airblade/vim-gitgutter'
Plug 'thaerkh/vim-workspace'
Plug 'mhinz/vim-startify'
Plug 'blindFS/vim-taskwarrior'
Plug 'MattesGroeger/vim-bookmarks'
Plug 'SirVer/ultisnips'
Plug 'bogado/file-line'
Plug 'tpope/vim-abolish'
Plug 'godlygeek/tabular'
Plug 'pearofducks/ansible-vim'
Plug 'editorconfig/editorconfig-vim'
Plug 'rbgrouleff/bclose.vim'
Plug 'Raimondi/delimitMate'
Plug 'rhysd/devdocs.vim'
Plug 'gregsexton/gitv'
Plug 'sjl/gundo.vim'
Plug 'robbles/logstash.vim'
Plug 'scrooloose/nerdcommenter'
Plug 'moll/vim-node'
Plug 'sumpygump/php-documentor-vim'
Plug 'vim-syntastic/syntastic'
Plug 'mtscout6/syntastic-local-eslint.vim'
Plug 'wincent/terminus'
Plug 'Quramy/tsuquyomi'
Plug 'leafgarland/typescript-vim'
Plug 'duggiefresh/vim-easydir'
Plug 'easymotion/vim-easymotion'
Plug 'pangloss/vim-javascript'
Plug 'Quramy/vim-js-pretty-template'
Plug 'heavenshell/vim-jsdoc'
Plug 'elzr/vim-json'
Plug 'adoy/vim-php-refactoring-toolbox'
Plug 'prettier/vim-prettier'
Plug 'rodjek/vim-puppet'
Plug 'henrik/vim-qargs'
Plug 'honza/vim-snippets'
Plug 'tpope/vim-surround'
Plug 'dhruvasagar/vim-table-mode'
Plug 'derekprior/vim-trimmer'
Plug 'Shougo/vimproc.vim'
Plug 'HerringtonDarkholme/yats.vim'
Plug 'kkoomen/vim-doge'
Plug 'vimwiki/vimwiki'
Plug 'neoclide/coc.nvim', {'branch': 'release'}
Plug 'liuchengxu/vista.vim'
Plug 'sheerun/vim-polyglot'
Plug 'rhysd/git-messenger.vim'
Plug 'segeljakt/vim-silicon'
Plug 'stsewd/fzf-checkout.vim'
Plug 'pechorin/any-jump.vim'
Plug 'szw/vim-maximizer'
Plug 'nvim-lua/plenary.nvim'
Plug 'nvim-telescope/telescope.nvim'
Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'}
Plug 'preservim/tagbar'
Plug 'mg979/vim-visual-multi', {'branch': 'master'}
" Add plugins to &runtimepath
call plug#end()
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => General
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" how many lines of history VIM should remember
set history=500
" set shell=/bin/sh
" save information about files I open
set viminfo='100,n$HOME/.vim/files/info/viminfo
" turn of filetype while i load pathogen then
" reactivate it
filetype off
filetype indent plugin on
" nocompatible should be a noop but better safe than sorry
set nocompatible
" set me leader to be comma
let mapleader=","
let g:mapleader=","
" i prefer this for saving, faster than typing :w
nmap <leader>w :w!<cr>
" Hide, dont close buffers
set hidden
" Set how the backspace key should work
set backspace=indent,eol,start
" Set the title of the vim window to the open file
set title
" Enable mouse support
set mouse=a
" Show a status line on all windows
set laststatus=2
" added to control keywords was having problems with puppet
set iskeyword=-,:,@,48-57,_,192-255
" Use f2 to toggle paste mode
set pastetoggle=<F2>
highlight Normal ctermbg=none guibg=none
highlight NonText ctermbg=none guibg=none guifg=none ctermfg=none
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => VIM user interface tweaks
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" enable 256 color support
set t_Co=256
if (has("termguicolors"))
set t_8f=\[[38;2;%lu;%lu;%lum
set t_8b=\[[48;2;%lu;%lu;%lum
set termguicolors
endif
" use solarized dark theme
" colorscheme spacemacs-theme
" colorscheme iceberg
colorscheme deep-space
set background=dark
" Always use powerline font in MacVim
set guifont=Source\ Code\ Pro\ for\ Powerline:h14
"set guifont=SauceCodePro\ Nerd\ Font:h14
" enable syntax highlighting
syntax on
" Fixes syntax highlighting issues, its a little slower
" this way but more accurate, i can live with that
autocmd BufEnter * :syntax sync fromstart
" Turn on the wildmenu
set wildmenu
" Ignore vcs files
set wildignore+=.git\*,.hg\*,.svn\*
" use utf-8 file encodings
set encoding=utf-8
" Always have 5 lines of context before/after the current line
set scrolloff=5
" Always show the current position
set ruler
" Highligh the current line
set cursorline
" Ignore case when searching
set ignorecase
" When searching try to be smart about cases
set smartcase
" Highlight search results
set hlsearch
" Make it easier navigate search results and highlight as you type
set incsearch
" Dont redraw when executing macros (for performance)
set lazyredraw
" Show matching brackets when cursor is over one
set showmatch
" How many tenths of a second to blink when matching brackets
set mat=2
" Turn off annoying sound on errors
set noerrorbells
set visualbell
set t_vb=
set tm=500
" Add a bit of extra margin to the left
set foldcolumn=1
set nofoldenable
" Show the current command im typing
set showcmd
" Show the current mode im in (normal, visual, insert etc.)
set showmode
" indicates a fast terminal connection improves redraw performance
set ttyfast
" Display linenumbers but use relative numbering
set number
set relativenumber
" Make my vim clipboard work with TMUX
set clipboard=unnamed
if $TMUX == ''
set clipboard+=unnamed
endif
" Automatically equalise splits when vim is resized
autocmd VimResized * wincmd =
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Text, tab and indents
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" automatically indent new lines
set autoindent
" default ident to 2 spaces
set expandtab
set smarttab
set shiftwidth=2
set tabstop=2
set softtabstop=2
" javascript 2 spaces
autocmd Filetype javascript setlocal ts=2 sw=2 sts=0 expandtab
" php 4 spaces
autocmd Filetype php setlocal ts=4 sw=4 sts=0 expandtab
" Linebreak on 80 chars
set linebreak
set textwidth=80
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Files, backups, undo
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" I prefer to turn backups off since everything is in git
set nobackup
set nowb
set noswapfile
" Dont ask me if I want to load changed files. Answer is always yes
set autoread
" Set up standard file types and encodings
set fileencodings=utf-8,iso-8859-1
set fileformats=unix,mac,dos
" Explicitly associated extensions with filetypes
au BufNewFile,BufFilePre,BufRead *.md set filetype=markdown
au FileType puppet setlocal isk+=:
au BufReadPost *.eyaml set syntax=yaml
"au BufNewFile,BufRead *.yaml set filetype=yaml.ansible
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Moving around, tabs, windows and buffers
" """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" map jj to the ESC key
inoremap jj <ESC>
" in tmux navigate naturally btw vim and tmux windows/panes
nnoremap <c-j> <c-w>j
nnoremap <c-k> <c-w>k
nnoremap <c-h> <c-w>h
nnoremap <c-l> <c-w>l
" move vertically by visual line
nnoremap j gj
nnoremap k gk
" shortcut for moving btw open buffers
nnoremap <leader>. :bn<CR> " next buffer
nnoremap <leader>, :bp<CR> " previous buffer
" switch to previously opened buffer and close the one we just
" switched away from (does the equivelant of :bd but without destroying
" my split window)
nmap <leader>bd :b#<bar>bd#<CR>
" Bi-directional find motion
" " Jump to anywhere you want with minimal keystrokes, with just one key
" binding.
" " `s{char}{label}`
nmap s <Plug>(easymotion-s)
" " or
" " `s{char}{char}{label}`
" " Need one more keystroke, but on average, it may be more comfortable.
nmap s <Plug>(easymotion-s2)
let g:EasyMotion_do_mapping = 0 " Disable default mappings
" " Turn on case insensitive feature
let g:EasyMotion_smartcase = 1
"
" " JK motions: Line motions
map <Leader>j <Plug>(easymotion-j)
map <Leader>k <Plug>(easymotion-k)
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Plugin Configuration
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" AIRLINE STATUS LINE
let g:airline_theme='base16_spacemacs'
let g:airline_powerline_fonts = 1
let g:airline#extensions#tabline#enabled = 1
if !exists('g:airline_symbols')
let g:airline_symbols = {}
endif
" unicode symbols
let g:airline_left_sep = '»'
let g:airline_left_sep = '▶'
let g:airline_right_sep = '«'
let g:airline_right_sep = '◀'
let g:airline_symbols.linenr = '␊'
let g:airline_symbols.linenr = ''
let g:airline_symbols.linenr = '¶'
let g:airline_symbols.branch = '⎇'
let g:airline_symbols.paste = 'ρ'
let g:airline_symbols.paste = 'Þ'
let g:airline_symbols.paste = '∥'
let g:airline_symbols.whitespace = 'Ξ'
" airline symbols
let g:airline_left_sep = ''
let g:airline_left_alt_sep = ''
let g:airline_right_sep = ''
let g:airline_right_alt_sep = ''
let g:airline_symbols.branch = ''
let g:airline_symbols.readonly = ''
let g:airline_symbols.linenr = ''
" SILVER SEARCHER
let g:ag_prg="ag --vimgrep"
" TELESCOPE
nnoremap <leader>ff <cmd>Telescope find_files<cr>
nnoremap <leader>fg <cmd>Telescope live_grep<cr>
nnoremap <leader>fb <cmd>Telescope buffers<cr>
nnoremap <leader>fh <cmd>Telescope help_tags<cr>
" FZF
" nnoremap <C-p> :GFiles<CR>
" nnoremap <Leader>pf :Files<CR>
" let g:fzf_layout = { 'window': { 'width': 0.8, 'height': 0.8 } }
" let $FZF_DEFAULT_OPTS="--reverse"
"
nnoremap // :BLines<CR>
nnoremap ?? :Rg<CR>
" Turn off PHP Folding
let g:DisableAutoPHPFolding = 1
let g:DisablePHPFolds = 1
" ULTISNIPS
let g:UltiSnipsExpandTrigger="<tab>"
let g:UltiSnipsJumpForwardTrigger="<c-b>"
let g:UltiSnipsJumpBackwardTrigger="<c-z>"
let g:UltiSnipsEditSplit="vertical"
let g:UltiSnipsListSnippets="<c-l>"
" SYNTASTIC
" let g:syntastic_always_populate_loc_list = 1
" let g:syntastic_auto_loc_list = 1
" eslint should be installed local to the project along with
" any plugins that are needed
let g:syntastic_javascript_checkers = ['eslint']
let g:syntastic_typescript_checkers = ['tslint']
let g:syntastic_check_on_open = 1
let g:syntastic_check_on_wq = 0
let g:syntastic_puppet_puppetlint_args = "--no-80chars-check"
"let g:syntastic_php_checkers = ['php']
"let g:syntastic_php_checkers = ['php', 'phpcs']
"let g:syntastic_php_phpcs_exec = ['./vendor/bin/phpcs']
"let g:syntastic_php_phpcs_args = ['-s -p --severity=3 --standard=./tests/Standards/TARL --extensions=php']
" Point syntastic checker at locally installed `standard` if it exists.
if executable('node_modules/.bin/tslint')
let g:syntastic_typescript_tslint_exec = 'node_modules/.bin/tslint'
endif
" TASK-WARRIOR
let g:task_rc_override='rc.defaultwidth=180'
let g:task_default_prompt=['due', 'project', 'priority', 'description', 'mystatus', 'tag', 'depends']
let g:task_readonly = 0
" JS-DOC
let g:jsdoc_allow_input_prompt = 1
" DEV-ICONS
let g:WebDevIconsOS = 'Darwin'
" STARTIFY
let g:startify_custom_header = [
\ ' ██████╗ ██╗ ██╗██╗██╗ ██╗ █████╗ ███╗ ██╗██╗ ██╗ █████╗ ███╗ ██╗ ██████╗ ',
\ '██╔═══██╗██║ ██╔╝██║╚██╗ ██╔╝██╔══██╗████╗ ██║██║ ██║██╔══██╗████╗ ██║██╔════╝ ',
\ '██║██╗██║█████╔╝ ██║ ╚████╔╝ ███████║██╔██╗ ██║██║ █╗ ██║███████║██╔██╗ ██║██║ ███╗',
\ '██║██║██║██╔═██╗ ██║ ╚██╔╝ ██╔══██║██║╚██╗██║██║███╗██║██╔══██║██║╚██╗██║██║ ██║',
\ '╚█║████╔╝██║ ██╗██║ ██║ ██║ ██║██║ ╚████║╚███╔███╔╝██║ ██║██║ ╚████║╚██████╔╝',
\ ' ╚╝╚═══╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝ ╚═╝╚═╝ ╚═══╝ ╚══╝╚══╝ ╚═╝ ╚═╝╚═╝ ╚═══╝ ╚═════╝ ',
\ ]
let g:startify_files_number = 5
let g:startify_session_autoload = 1
let g:startify_session_persistence = 1
let g:startify_skiplist = [
\ 'COMMIT_EDITMSG',
\ '\.git/*',
\ '/opt/local/share/nvim/runtime/doc/*',
\ ]
let g:startify_commands = [
\ {'t': ['Tasks', ':TW']},
\ ]
let g:startify_session_dir = '~/.vim/session'
" VIM-PRETTIER
" let g:prettier#autoformat = 0
" autocmd BufWritePre *.js,*.jsx,*.mjs,*.ts,*.tsx,*.css,*.less,*.scss,*.json,*.graphql,*.md PrettierAsync
" Vista
let g:vista#renderer#enable_icon = 1
let g:vista_default_executive = 'coc'
let g:vista_icon_indent = ["→", "├─▸ "]
let g:vista#renderer#icons = {
\ "function": "⨍",
\ "method": "⨍",
\ "variable": "𝒙",
\ "property": "𝝅",
\ }
let g:vista_executive_for = {
\ 'php': 'coc',
\ }
nnoremap <leader>vt :Vista coc<CR>
" SILICON (code screenshots)
let g:silicon = {
\ 'theme': 'Dracula',
\ 'font': 'Hack',
\ 'background': '#AAAAFF',
\ 'shadow-color': '#555555',
\ 'line-pad': 2,
\ 'pad-horiz': 80,
\ 'pad-vert': 100,
\ 'shadow-blur-radius': 0,
\ 'shadow-offset-x': 0,
\ 'shadow-offset-y': 0,
\ 'line-number': v:true,
\ 'round-corner': v:true,
\ 'window-controls': v:true,
\ 'output': '~/Downloads/code_screenshots/silicon-{time:%Y-%m-%d-%H%M%S}.png',
\ }
" VIM CoC
" TextEdit might fail if hidden is not set.
set hidden
" Some servers have issues with backup files, see #649.
set nobackup
set nowritebackup
" Give more space for displaying messages.
set cmdheight=2
" Having longer updatetime (default is 4000 ms = 4 s) leads to noticeable
" delays and poor user experience.
set updatetime=300
" Don't pass messages to |ins-completion-menu|.
set shortmess+=c
" Always show the signcolumn, otherwise it would shift the text each time
" diagnostics appear/become resolved.
set signcolumn=yes
" Use tab for trigger completion with characters ahead and navigate.
" NOTE: Use command ':verbose imap <tab>' to make sure tab is not mapped by
" other plugin before putting this into your config.
inoremap <silent><expr> <TAB>
\ pumvisible() ? "\<C-n>" :
\ <SID>check_back_space() ? "\<TAB>" :
\ coc#refresh()
inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"
function! s:check_back_space() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~# '\s'
endfunction
" Use <c-space> to trigger completion.
inoremap <silent><expr> <c-space> coc#refresh()
" Use <cr> to confirm completion, `<C-g>u` means break undo chain at current
" position. Coc only does snippet and additional edit on confirm.
" <cr> could be remapped by other vim plugin, try `:verbose imap <CR>`.
if exists('*complete_info')
inoremap <expr> <cr> complete_info()["selected"] != "-1" ? "\<C-y>" : "\<C-g>u\<CR>"
else
inoremap <expr> <cr> pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>"
endif
" Use `[g` and `]g` to navigate diagnostics
nmap <silent> [g <Plug>(coc-diagnostic-prev)
nmap <silent> ]g <Plug>(coc-diagnostic-next)
" GoTo code navigation.
nmap <silent> gd <Plug>(coc-definition)
nmap <silent> gy <Plug>(coc-type-definition)
nmap <silent> gi <Plug>(coc-implementation)
nmap <silent> gr <Plug>(coc-references)
" Use K to show documentation in preview window.
nnoremap <silent> K :call <SID>show_documentation()<CR>
function! s:show_documentation()
if (index(['vim','help'], &filetype) >= 0)
execute 'h '.expand('<cword>')
else
call CocAction('doHover')
endif
endfunction
" Highlight the symbol and its references when holding the cursor.
autocmd CursorHold * silent call CocActionAsync('highlight')
" Symbol renaming.
nmap <leader>rn <Plug>(coc-rename)
" Formatting selected code.
xmap <leader>f <Plug>(coc-format-selected)
nmap <leader>f <Plug>(coc-format-selected)
augroup mygroup
autocmd!
" Setup formatexpr specified filetype(s).
autocmd FileType typescript,json setl formatexpr=CocAction('formatSelected')
" Update signature help on jump placeholder.
autocmd User CocJumpPlaceholder call CocActionAsync('showSignatureHelp')
augroup end
" Applying codeAction to the selected region.
" Example: `<leader>aap` for current paragraph
xmap <leader>a <Plug>(coc-codeaction-selected)
nmap <leader>a <Plug>(coc-codeaction-selected)
" Remap keys for applying codeAction to the current line.
nmap <leader>ac <Plug>(coc-codeaction)
" Apply AutoFix to problem on the current line.
nmap <leader>qf <Plug>(coc-fix-current)
" Map function and class text objects
" NOTE: Requires 'textDocument.documentSymbol' support from the language server.
xmap if <Plug>(coc-funcobj-i)
omap if <Plug>(coc-funcobj-i)
xmap af <Plug>(coc-funcobj-a)
omap af <Plug>(coc-funcobj-a)
xmap ic <Plug>(coc-classobj-i)
omap ic <Plug>(coc-classobj-i)
xmap ac <Plug>(coc-classobj-a)
omap ac <Plug>(coc-classobj-a)
" Use CTRL-S for selections ranges.
" Requires 'textDocument/selectionRange' support of LS, ex: coc-tsserver
nmap <silent> <C-s> <Plug>(coc-range-select)
xmap <silent> <C-s> <Plug>(coc-range-select)
" Add `:Format` command to format current buffer.
command! -nargs=0 Format :call CocAction('format')
" Add `:Fold` command to fold current buffer.
command! -nargs=? Fold :call CocAction('fold', <f-args>)
" Add `:OR` command for organize imports of the current buffer.
command! -nargs=0 OR :call CocAction('runCommand', 'editor.action.organizeImport')
" Add (Neo)Vim's native statusline support.
" NOTE: Please see `:h coc-status` for integrations with external plugins that
" provide custom statusline: lightline.vim, vim-airline.
set statusline^=%{coc#status()}%{get(b:,'coc_current_function','')}
" Mappings using CoCList:
" Show all diagnostics.
nnoremap <silent> <space>a :<C-u>CocList diagnostics<cr>
" Manage extensions.
nnoremap <silent> <space>e :<C-u>CocList extensions<cr>
" Show commands.
nnoremap <silent> <space>c :<C-u>CocList commands<cr>
" Find symbol of current document.
nnoremap <silent> <space>o :<C-u>CocList outline<cr>
" Search workspace symbols.
nnoremap <silent> <space>s :<C-u>CocList -I symbols<cr>
" Do default action for next item.
nnoremap <silent> <space>j :<C-u>CocNext<CR>
" Do default action for previous item.
nnoremap <silent> <space>k :<C-u>CocPrev<CR>
" Resume latest coc list.
nnoremap <silent> <space>p :<C-u>CocListResume<CR>
" Project wide search, which we can use to replace across
" the entire project
nnoremap <leader>prw :CocSearch <C-R>=expand("<cword>")<CR><CR>
" Explorer
nmap <leader>n :CocCommand explorer<CR>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Custom Mappings / Shortcuts etc.
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" integration with the boxes utility
" ( installed via port install boxes )
vmap <leader>mc !boxes -d shell -s 80 -a c<CR>
nmap <leader>mc !!boxes -d shell -s 80 -a c <CR>
vmap <leader>xc !boxes -d shell -r<CR>
nmap <leader>xc !!boxes -d shell -r<CR>
" stop highlighting a search
nnoremap <leader><space> :nohlsearch<CR>
" Quick edit .vimrc
nnoremap <leader>ev :e $MYVIMRC<CR> " quick edit .vimrc
" Reload .vimrc
nnoremap <leader>sv :so $MYVIMRC<CR> " reload .vimrc
" Toggles GUNDO view
nnoremap <leader>gt :GundoToggle<CR> " toggles Gundo
" fugitive mappings
nnoremap <leader>gs :Git<CR>
" Toggle the tagbar view
nnoremap <leader>tb :TagbarToggle<CR>
" Force the filetype to ansible manually
nnoremap <leader>fa :set filetype=ansible<CR>
" set working directory to current file
nnoremap <leader>cd :cd %:p:h<CR>:pwd<CR>
" remove all trailing whitespace from the file
nnoremap <leader>wws :let _s=@/<Bar>:%s/\s\+$//e<Bar>:let @/=_s<Bar>:nohl<CR>
" closes all buffers that aren't currently visible in
" window/split/tab
nnoremap <leader>bc :call CloseAllHiddenBuffers()<CR>
" search devdocs for term under cursor
nmap <leader>kk <Plug>(devdocs-under-cursor)
" prompts for an input which is used to replace all
" occurances of the current word
nmap <leader>r :call Replace()<CR>
" adds a date time formatted error_log line for debugging
nmap <leader>ee oerror_log(date('d.m.Y h:i:s') ."\t" . "", 3, '/tmp/nad.txt');<ESC>21hi
" removes all error_logs from current file
nmap <leader>ed :g/error_log/d<CR>
" Move a line of text using ALT+[jk]
" or a selected block of text
" in OSX cant map the ALT key so used this
" workaround: http://stackoverflow.com/questions/7501092/can-i-map-alt-key-in-vim
nnoremap ∆ :m .+1<CR>==
nnoremap ˚ :m .-2<CR>==
inoremap ∆ <Esc>:m .+1<CR>==gi
inoremap ˚ <Esc>:m .-2<CR>==gi
vnoremap ∆ :m '>+1<CR>gv=gv
vnoremap ˚ :m '<-2<CR>gv=gv
" Workaround to update gitgutter when we do a commit through fugitive
autocmd BufWritePost * GitGutterAll
" Appends current date to the open buffer
function! Today()
let today = strftime("%A %d\/%m\/%Y")
exe "normal a". today
endfunction
command! Today :call Today()
" Show current buffer in NerdTree
" map <leader>ff :NERDTreeFind<CR>
" Open and close lazygit
noremap <leader>gg :tab term lazygit<CR>
func! s:buf_compare(b1, b2) abort
let b1_visible = -1 == index(tabpagebuflist(), a:b1)
let b2_visible = -1 == index(tabpagebuflist(), a:b2)
"prefer loaded and NON-visible buffers
if bufloaded(a:b1)
if bufloaded(a:b2)
return b2_visible ? !b1_visible : -1
endif
return 0
endif
return !bufloaded(a:b2) ? 0 : 1
endf
" Close all buffers that aren't currently being
" displayed in a window/split/tab
function! CloseAllHiddenBuffers()
" list of *all* buffer numbers including hidden ones
let l:buffers = filter(range(1, bufnr('$')),
\ 'buflisted(v:val)
\ && ("" ==# getbufvar(v:val, "&buftype") || "help" ==# getbufvar(v:val, "&buftype"))
\ ')
call sort(l:buffers, '<sid>buf_compare')
" what tab page are we in?
let l:currentTab = tabpagenr()
try
" go through all tab pages
let l:tab = 0
while l:tab < tabpagenr('$')
let l:tab += 1
" go through all windows
let l:win = 0
while l:win < winnr('$')
let l:win += 1
" whatever buffer is in this window in this tab, remove it from
" l:buffers list
let l:thisbuf = winbufnr(l:win)
call remove(l:buffers, index(l:buffers, l:thisbuf))
endwhile
endwhile
" if there are any buffers left, delete them
if len(l:buffers)
execute 'bwipeout' join(l:buffers)
endif
finally
" go back to our original tab page
execute 'tabnext' l:currentTab
endtry
endfunction
" Search for <cword> and replace with input()
function! Replace()
let s:word = input("Replace " . expand('<cword>') . " with:")
:exe '%s/\<' . expand('<cword>') . '\>/' . s:word . '/ge'
:unlet! s:word
endfun