forked from kristijanhusak/neovim-config
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.vim
executable file
·492 lines (411 loc) · 20.7 KB
/
init.vim
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
" ================ Plugins ==================== {{{
if exists('*minpac#init')
call minpac#init()
" Manually loaded plugins
call minpac#add('k-takata/minpac', {'type': 'opt'})
" Auto loaded plugins
call minpac#add('Shougo/deoplete.nvim')
call minpac#add('Shougo/neosnippet')
call minpac#add('w0rp/ale', { 'do': '!npm install -g prettier' })
call minpac#add('Raimondi/delimitMate')
call minpac#add('manasthakur/vim-commentor')
call minpac#add('tpope/vim-surround')
call minpac#add('tpope/vim-repeat')
call minpac#add('tpope/vim-fugitive')
call minpac#add('AndrewRadev/splitjoin.vim')
call minpac#add('airblade/vim-gitgutter')
call minpac#add('sheerun/vim-polyglot')
call minpac#add('mattn/emmet-vim')
call minpac#add('dyng/ctrlsf.vim')
call minpac#add('junegunn/fzf', { 'do': '!./install --all && ln -s $(pwd) ~/.fzf'})
call minpac#add('junegunn/fzf.vim')
call minpac#add('ludovicchabant/vim-gutentags')
call minpac#add('phpactor/phpactor', { 'do': '!composer install' })
call minpac#add('kristijanhusak/vim-js-file-import')
call minpac#add('kristijanhusak/vim-dirvish-git')
call minpac#add('kristijanhusak/deoplete-phpactor')
call minpac#add('vimwiki/vimwiki')
call minpac#add('editorconfig/editorconfig-vim')
call minpac#add('morhetz/gruvbox')
call minpac#add('justinmk/vim-dirvish')
call minpac#add('andymass/vim-matchup')
call minpac#add('haya14busa/vim-asterisk')
call minpac#add('osyo-manga/vim-anzu')
call minpac#add('autozimu/LanguageClient-neovim', { 'do': '!bash install.sh' })
call minpac#add('soywod/vim-keepeye')
call minpac#add('wellle/targets.vim')
endif
command! PackUpdate packadd minpac | source $MYVIMRC | call minpac#update()
command! PackClean packadd minpac | source $MYVIMRC | call minpac#clean()
"}}}
" ================ General Config ==================== {{{
let g:loaded_netrwPlugin = 1 "Do not load netrw so Dirvish can be autoloaded
let g:loaded_matchit = 1 "Do not load matchit, use matchup plugin
let g:mapleader = ',' "Change leader to a comma
let g:gruvbox_italic = 1 "Enable italics in Gruvbox colorscheme
let g:gruvbox_invert_selection = 0 "Do not invert selection in Gruvbox colorscheme
let g:gruvbox_sign_column = 'bg0' "Use default bg color in sign column
set termguicolors
set title "change the terminal's title
set number "Line numbers are good
set relativenumber "Show numbers relative to current line
set history=500 "Store lots of :cmdline history
set showcmd "Show incomplete cmds down the bottom
set noshowmode "Hide showmode because of the powerline plugin
set gdefault "Set global flag for search and replace
set guicursor=a:blinkon500-blinkwait500-blinkoff500 "Set cursor blinking rate
set cursorline "Highlight current line
set smartcase "Smart case search if there is uppercase
set ignorecase "case insensitive search
set mouse=a "Enable mouse usage
set showmatch "Highlight matching bracket
set nostartofline "Jump to first non-blank character
set timeoutlen=1000 ttimeoutlen=0 "Reduce Command timeout for faster escape and O
set fileencoding=utf-8 "Set utf-8 encoding on write
set wrap "Enable word wrap
set linebreak "Wrap lines at convenient points
set listchars=tab:\ \ ,trail:· "Set trails for tabs and spaces
set list "Enable listchars
set lazyredraw "Do not redraw on registers and macros
set background=dark "Set background to dark
set hidden "Hide buffers in background
set conceallevel=2 concealcursor=i "neosnippets conceal marker
set splitright "Set up new vertical splits positions
set splitbelow "Set up new horizontal splits positions
set path+=** "Allow recursive search
set inccommand=nosplit "Show substitute changes immidiately in separate split
set fillchars+=vert:\│ "Make vertical split separator full line
set pumheight=15 "Maximum number of entries in autocomplete popup
set exrc "Allow using local vimrc
set secure "Forbid autocmd in local vimrc
set grepprg=rg\ --vimgrep "Use ripgrep for grepping
set tagcase=smart "Use smarcase for tags
set updatetime=500 "Cursor hold timeout
set synmaxcol=300 "Use syntax highlighting only for 300 columns
syntax on
silent! colorscheme gruvbox
hi! link jsFuncCall GruvboxBlue
" Remove highlighting of Operator because it is reversed with cursorline enabled
hi! Operator guifg=NONE guibg=NONE
" }}}
" ================ Turn Off Swap Files ============== {{{
set noswapfile
set nobackup
set nowritebackup
" }}}
" ================ Persistent Undo ================== {{{
" Keep undo history across sessions, by storing in file.
silent !mkdir ~/.config/nvim/backups > /dev/null 2>&1
set undodir=~/.config/nvim/backups
set undofile
" }}}
" ================ Indentation ====================== {{{
set shiftwidth=2
set softtabstop=2
set tabstop=2
set expandtab
set breakindent
set smartindent
set nofoldenable
set colorcolumn=80
set foldmethod=syntax
set foldlevelstart=5
" }}}
" ================ Auto commands ====================== {{{
augroup vimrc
autocmd!
autocmd QuickFixCmdPost [^l]* cwindow "Open quickfix window after grepping
autocmd BufWritePre * call StripTrailingWhitespaces() "Auto-remove trailing spaces
autocmd InsertEnter * set nocul "Remove cursorline highlight
autocmd InsertLeave * set cul "Add cursorline highlight in normal mode
autocmd FocusGained,BufEnter * checktime "Refresh file when vim gets focus
autocmd FileType html,css,javascript.jsx EmmetInstall
augroup END
augroup php
autocmd!
autocmd FileType php setlocal shiftwidth=4 softtabstop=4 tabstop=4
autocmd FileType php nmap <buffer><silent><Leader>if :call phpactor#UseAdd()<CR>
autocmd FileType php nmap <buffer><silent><Leader>ir :call phpactor#ContextMenu()<CR>
autocmd FileType php vmap <buffer><silent><Leader>ie :<C-U>call phpactor#ExtractMethod()<CR>
autocmd FileType php nmap <buffer><silent><C-]> :call phpactor#GotoDefinition()<CR>
augroup END
augroup javascript
autocmd!
autocmd FileType javascript nmap <buffer><silent><C-]> <Plug>(JsGotoDefinition)
autocmd FileType javascript xmap <buffer><silent><C-]> <Plug>(JsGotoDefinition)
autocmd FileType javascript nmap <buffer><silent><Leader>] <C-W>v<Plug>(JsGotoDefinition)
autocmd FileType javascript xmap <buffer><silent><Leader>] <C-W>vgv<Plug>(JsGotoDefinition)
augroup END
augroup dirvish
autocmd!
autocmd FileType dirvish nnoremap <silent><buffer> o :call dirvish#open('edit', 0)<CR>
autocmd FileType dirvish nnoremap <silent><buffer> s :call dirvish#open('vsplit', 1)<CR>
autocmd FileType dirvish xnoremap <silent><buffer> o :call dirvish#open('edit', 0)<CR>
autocmd FileType dirvish nmap <silent><buffer> u <Plug>(dirvish_up)
autocmd FileType dirvish nmap <silent><buffer><Leader>n <Plug>(dirvish_quit)
autocmd FileType dirvish silent! unmap <buffer> <C-p>
augroup END
augroup numbertoggle
autocmd!
autocmd BufEnter,FocusGained,InsertLeave,WinEnter * if &nu | set rnu | endif
autocmd BufLeave,FocusLost,InsertEnter,WinLeave * if &nu | set nornu | endif
augroup END
" }}}
" ================ Completion ======================= {{{
set wildmode=list:full
set wildignore=*.o,*.obj,*~ "stuff to ignore when tab completing
set wildignore+=*.git*
set wildignore+=*.meteor*
set wildignore+=*vim/backups*
set wildignore+=*sass-cache*
set wildignore+=*cache*
set wildignore+=*logs*
set wildignore+=*node_modules/**
set wildignore+=*DS_Store*
set wildignore+=*.gem
set wildignore+=log/**
set wildignore+=tmp/**
set wildignore+=*.png,*.jpg,*.gif
" }}}
" ================ Scrolling ======================== {{{
set scrolloff=8 "Start scrolling when we're 8 lines away from margins
set sidescrolloff=15
set sidescroll=5
" }}}
" ================ Statusline ======================== {{{
let s:statuslineBgColor = synIDattr(synIDtrans(hlID('StatusLine')), 'reverse') ? 'fg' : 'bg'
let s:statuslineBg = synIDattr(synIDtrans(hlID('StatusLine')), s:statuslineBgColor)
silent exe 'hi User1 guifg=#FF0000 guibg='.s:statuslineBg.' gui=bold'
hi User2 guifg=#FFFFFF guibg=#FF1111 gui=bold
hi User3 guifg=#2C323C guibg=#E5C07B gui=bold
set statusline=\ %{toupper(mode())} "Mode
set statusline+=\ \│\ %{StatuslineFn('fugitive#head')} "Git branch
set statusline+=%{GitFileStatus()} "Git file status
set statusline+=\ \│\ %4F "File path
set statusline+=\ %1*%m%* "Modified indicator
set statusline+=\ %w "Preview indicator
set statusline+=\ %r "Read only indicator
set statusline+=\ %q "Quickfix list indicator
set statusline+=\ %= "Start right side layout
set statusline+=\ %{&enc} "Encoding
set statusline+=\ \│\ %y "Filetype
set statusline+=\ \│\ %p%% "Percentage
set statusline+=\ \│\ %c "Column number
set statusline+=\ \│\ %l/%L "Current line number/Total line numbers
set statusline+=\ %{StatuslineFn('gutentags#statusline','\│\ ')} "Tags status
set statusline+=\ %2*%{AleStatusline('error')}%* "Errors count
set statusline+=%3*%{AleStatusline('warning')}%* "Warning count
"}}}
" ================ Abbreviations ==================== {{{
cnoreabbrev Wq wq
cnoreabbrev WQ wq
cnoreabbrev Wqa wqa
cnoreabbrev W w
cnoreabbrev Q q
cnoreabbrev Qa qa
cnoreabbrev Bd bd
cnoreabbrev wrap set wrap
cnoreabbrev nowrap set nowrap
" }}}
" ================ Functions ======================== {{{
function! StatuslineFn(name, ...) abort
try
return call(a:name, a:000)
catch
return ''
endtry
endfunction
function! StripTrailingWhitespaces()
if &modifiable
let l:l = line('.')
let l:c = col('.')
call execute('%s/\s\+$//e')
call histdel('/', -1)
call cursor(l:l, l:c)
endif
endfunction
function! Search(...)
let l:default = a:0 > 0 ? expand('<cword>') : ''
let l:term = input('Search for: ', l:default)
if l:term !=? ''
let l:path = input('Path: ', '', 'file')
execute 'CtrlSF "'.l:term.'" '.l:path
endif
endfunction
function! AleStatusline(type)
try
let l:count = ale#statusline#Count(bufnr(''))
if a:type ==? 'error' && l:count['error']
return printf(' %d E ', l:count['error'])
endif
if a:type ==? 'warning' && l:count['warning']
let l:space = l:count['error'] ? ' ': ''
return printf('%s %d W ', l:space, l:count['warning'])
endif
return ''
catch
return ''
endtry
endfunction
function! GitFileStatus()
if !exists('b:gitgutter')
return ''
endif
let [l:added, l:modified, l:removed] = get(b:gitgutter, 'summary', [0, 0, 0])
let l:result = l:added == 0 ? '' : ' +'.l:added
let l:result .= l:modified == 0 ? '' : ' ~'.l:modified
let l:result .= l:removed == 0 ? '' : ' -'.l:removed
if l:result !=? ''
return ' '.l:result
endif
return l:result
endfunction
function! CloseBuffer(...) abort
if &buftype !=? ''
return execute('q!')
endif
let l:windowCount = winnr('$')
let l:totalBuffers = len(getbufinfo({ 'buflisted': 1 }))
let l:noSplits = l:windowCount ==? 1
let l:bang = a:0 > 0 ? '!' : ''
if l:totalBuffers > 1 && l:noSplits
let l:command = 'bp'
if buflisted(bufnr('#'))
let l:command .= '|bd'.l:bang.'#'
endif
return execute(l:command)
endif
return execute('q'.l:bang)
endfunction
" }}}
" ================ Custom mappings ======================== {{{
" Comment map
nmap <Leader>c gcc
" Line comment command
xmap <Leader>c gc
" Map save to Ctrl + S
map <c-s> :w<CR>
imap <c-s> <C-o>:w<CR>
nnoremap <Leader>s :w<CR>
" Open vertical split
nnoremap <Leader>v <C-w>v
" Move between slits
nnoremap <c-h> <C-w>h
nnoremap <c-j> <C-w>j
nnoremap <c-k> <C-w>k
nnoremap <c-l> <C-w>l
nnoremap <c-Space> <C-w>p
tnoremap <c-h> <C-\><C-n><C-w>h
tnoremap <c-l> <C-\><C-n><C-w>l
tnoremap <c-Space> <C-\><C-n><C-w>p
" Down is really the next line
nnoremap j gj
nnoremap k gk
" Expand snippets on tab if snippets exists, otherwise do autocompletion
imap <expr><TAB> neosnippet#expandable_or_jumpable() ?
\ "\<Plug>(neosnippet_expand_or_jump)"
\ : pumvisible() ? "\<C-n>" : "\<TAB>"
" If popup window is visible do autocompletion from back
imap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<S-Tab>"
" Fix for jumping over placeholders for neosnippet
smap <expr><TAB> neosnippet#jumpable() ?
\ "\<Plug>(neosnippet_jump)"
\: "\<TAB>"
" Map for Escape key
inoremap jj <Esc>
tnoremap <Leader>jj <C-\><C-n>
" Yank to the end of the line
nnoremap Y y$
" Copy to system clipboard
vnoremap <C-c> "+y
" Paste from system clipboard with Ctrl + v
inoremap <C-v> <Esc>"+p
nnoremap <Leader>p "0p
vnoremap <Leader>p "0p
nnoremap <Leader>h viw"0p
" Move to the end of yanked text after yank and paste
nnoremap p p`]
vnoremap y y`]
vnoremap p p`]
" Move selected lines up and down
vnoremap J :m '>+1<CR>gv=gv
vnoremap K :m '<-2<CR>gv=gv
" Clear search highlight
nnoremap <Leader><space> :AnzuClearSearchStatus<BAR>noh<CR>
" Handle ale error window
nnoremap <Leader>e :lopen<CR>
nnoremap <Leader>E :copen<CR>
nnoremap <silent><Leader>q :call CloseBuffer()<CR>
nnoremap <silent><Leader>Q :call CloseBuffer(1)<CR>
nnoremap <Leader>hf :Dirvish %<CR>
nnoremap <Leader>n :Dirvish<CR>
" Toggle between last 2 buffers
nnoremap <leader><tab> <c-^>
" Filesearch plugin map for searching in whole folder
nnoremap <Leader>f :call Search()<CR>
nnoremap <Leader>F :call Search(1)<CR>
" Toggle buffer list
nnoremap <C-p> :Files<CR>
nnoremap <Leader>b :Buffers<CR>
nnoremap <Leader>t :BTags<CR>
nnoremap <Leader>m :History<CR>
" Indenting in visual mode
xnoremap <s-tab> <gv
xnoremap <tab> >gv
" Resize window with shift + and shift - or use for diffget/diffput in diff mode
nnoremap <expr> + &diff ? ':diffput<BAR>diffupdate<CR>' : '<c-w>5>'
nnoremap <expr> _ &diff ? ':diffget<BAR>diffupdate<CR>' : '<c-w>5<'
xnoremap <expr> + &diff ? ':diffput<BAR>diffupdate<CR>' : '+'
xnoremap <expr> _ &diff ? ':diffget<BAR>diffupdate<CR>' : '_'
nnoremap <expr> R &diff ? ':diffupdate<CR>' : 'R'
" Better search status
nmap n <Plug>(anzu-n-with-echo)zz
nmap N <Plug>(anzu-N-with-echo)zz
map * <Plug>(asterisk-z*)<Plug>(anzu-update-search-status-with-echo)
map # <Plug>(asterisk-z#)<Plug>(anzu-update-search-status-with-echo)
map g* <Plug>(asterisk-gz*)<Plug>(anzu-update-search-status-with-echo)
map g# <Plug>(asterisk-gz#)<Plug>(anzu-update-search-status-with-echo)
" Language client context menu
nnoremap <Leader>r :call LanguageClient_contextMenu()<CR>
"Disable ex mode mapping
map Q <Nop>
" Jump to definition in vertical split
nnoremap <Leader>] <C-W>v<C-]>
" Reformat and fix linting errors
nnoremap <Leader>R :ALEFix<CR>
" Close all other buffers except current one
nnoremap <Leader>db :silent w <BAR> :silent %bd <BAR> e#<CR>
" }}}
" ================ Plugins setups ======================== {{{
let g:ctrlsf_auto_close = 0 "Do not close search when file is opened
let g:ctrlsf_mapping = {'vsplit': 's'} "Mapping for opening search result in vertical split
let g:dirvish_mode = ':sort ,^.*[\/],' "List directories first in dirvish
let g:user_emmet_leader_key = '<c-e>' "Change trigger emmet key
let g:user_emmet_install_global = 0 "Load emmet on demand
let g:deoplete#enable_at_startup = 1 "Enable deoplete on startup
let g:deoplete#camel_case = 1 "Autocomplete files relative to current buffer path
let g:deoplete#file#enable_buffer_path = 1 "Show only 30 entries in list and allow smart case autocomplete
let g:neosnippet#disable_runtime_snippets = {'_' : 1} "Snippets setup
let g:neosnippet#snippets_directory = ['~/.config/nvim/snippets'] "Snippets directory
let g:delimitMate_expand_cr = 1 "Auto indent on enter
let g:ale_linters = {'javascript': ['eslint']} "Lint js with eslint
let g:ale_fixers = {'javascript': ['prettier', 'eslint']} "Fix eslint errors
let g:ale_javascript_prettier_options = '--print-width 100' "Set max width to 100 chars for prettier
let g:ale_sign_error = '✖' "Lint error sign
let g:ale_sign_warning = '⚠' "Lint warning sign
let g:jsx_ext_required = 1 "Force jsx extension for jsx filetype
let g:javascript_plugin_jsdoc = 1 "Enable syntax highlighting for js doc blocks
let g:vimwiki_list = [{'path': '~/Dropbox/vimwiki'}] "Use dropbox folder for easier syncing of wiki
let g:matchup_matchparen_status_offscreen = 0 "Do not show offscreen closing match in statusline
let g:matchup_matchparen_nomode = "ivV\<c-v>" "Enable matchup only in normal mode
let g:LanguageClient_serverCommands = {
\ 'javascript': ['javascript-typescript-stdio'],
\ 'javascript.jsx': ['javascript-typescript-stdio'],
\ 'typescript': ['javascript-typescript-stdio'],
\ }
let g:keepeye_start = v:true "Start keepeye on vim enter
let g:keepeye_timer = 2100 "Remind every 35 min
hi User4 guifg=#FFFFFF guibg=#FF0000
let g:keepeye_message_hl_user = 4 "Use User4 hl group when showing keepeye message
" }}}
" vim:foldenable:foldmethod=marker