-
Notifications
You must be signed in to change notification settings - Fork 0
/
.vimrc
490 lines (391 loc) · 14.3 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
" .vimrc
" Author: Nadeem Shabir
" Source: https://github.com/kiyanwang/dotfiles/.vimrc
" Installed plugins: see bootstraph.sh which needs to be run
" at the moment this uses Pathogen, will probably change
" this some point.
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => 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
execute pathogen#infect()
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>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => VIM user interface tweaks
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" enable 256 color support
set t_Co=256
if (has("termguicolors"))
set termguicolors
endif
" use solarized dark theme
" colorscheme solarized8_dark
colorscheme spacemacs-theme
set background=dark
" Always use powerline font in MacVim
set guifont=Source\ Code\ Pro\ for\ Powerline: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
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" DEOPLETE
let g:deoplete#enable_at_startup = 0
let g:deoplete#enable_smart_case = 1
let g:deoplete#enable_ignore_case = 1
let g:deoplete#auto_complete_start_length = 0
let g:auto_complete_start_length = 0
let g:deoplete#enable_refresh_always = 1
let g:deoplete#enable_debug = 1
let g:deoplete#enable_profile = 1
" AIRLINE STATUS LINE
let g:airline_theme='base16_spacemacs'
let g:airline_powerline_fonts = 1
let g:airline#extensions#tabline#enabled = 1
" SILVER SEARCHER
let g:ag_prg="ag --vimgrep"
" CTRL-P
let g:ctrlp_match_window = 'bottom,order:ttb'
let g:ctrlp_switch_buffer = 0
let g:ctrlp_working_path_mode = 'ra'
let g:ctrlp_show_hidden = 1
" make sure ctrlp uses silver searcher (much much faster)
let g:ctrlp_user_command = 'ag %s -l --nocolor --hidden --ignore=".git" -g ""'
" NERDTREE
" Make sure NERDTree lists hidden files
let g:NERDTreeShowHidden=1
let g:NERDTreeIgnore=['.git']
let g:NERDTreeMinimalUI=1
let g:NERDTreeDirArrows=1
" Use ctrl-n to activate nerdtree
map <leader>n :NERDTreeToggle<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
" MULTIPLE CURSORS
let g:multi_cursor_next_key='<C-n>'
let g:multi_cursor_prev_key='<C-p>'
let g:multi_cursor_skip_key='<C-x>'
let g:multi_cursor_quit_key='<Esc>'
" 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']},
\ ]
" VIM-PRETTIER
" let g:prettier#autoformat = 0
" autocmd BufWritePre *.js,*.jsx,*.mjs,*.ts,*.tsx,*.css,*.less,*.scss,*.json,*.graphql,*.md PrettierAsync
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => 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 :Gstatus<CR>
nnoremap <leader>gc :Gcommit<CR>
nnoremap <leader>gb :Gbrowse<CR>
nnoremap <leader>gpu :Gpush<CR>
" Toggle the tagbar view
nnoremap <leader>tt :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>ws :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>
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