-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.vim
455 lines (366 loc) · 13.9 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
function! GetSystem()
let l:system = 'Unknown'
if has('unix') && filereadable('/proc/version')
let lines = readfile('/proc/version')
if lines[0] =~ "Microsoft"
let l:system = 'LinuxWsl'
else
let l:system = 'Linux'
endif
elseif has('win32')
let l:system = 'Windows'
elseif has('macunix')
let l:system = 'Macos'
endif
return l:system
endfunction
let s:system = GetSystem()
call plug#begin(stdpath('data') . '/plugged')
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
Plug 'editorconfig/editorconfig-vim'
" Plug 'sheerun/vim-polyglot'
Plug 'joshdick/onedark.vim'
Plug 'sonph/onehalf', { 'rtp': 'vim' }
" Plug 'rakrvim-one'
Plug 'tpope/vim-fugitive'
Plug 'scrooloose/nerdtree'
" Plug 'neoclide/coc.nvim', {'branch': 'release'}
Plug 'janko/vim-test'
Plug 'tpope/vim-commentary'
Plug 'tpope/vim-surround'
Plug 'tpope/vim-repeat'
" Plug 'autozimu/LanguageClient-neovim', {
" \ 'branch': 'next',
" \ 'do': 'bash install.sh',
" \ }
" Plug 'reasonml-editor/vim-reason-plus'
Plug 'vim-scripts/ReplaceWithRegister'
Plug 'neovim/nvim-lspconfig'
" Plug 'nvim-lua/completion-nvim'
Plug 'hrsh7th/cmp-nvim-lsp'
Plug 'hrsh7th/nvim-cmp'
Plug 'saadparwaiz1/cmp_luasnip'
Plug 'hrsh7th/cmp-buffer'
Plug 'hrsh7th/cmp-path'
Plug 'hrsh7th/cmp-cmdline'
Plug 'L3MON4D3/LuaSnip'
" Plug 'hrsh7th/cmp-cmdline'
Plug 'sbdchd/neoformat'
if s:system == 'Macos'
" Plug '/usr/local/opt/fzf'
else
" Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
endif
" Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
" Plug 'junegunn/fzf.vim'
Plug 'nvim-lua/plenary.nvim'
Plug 'nvim-telescope/telescope.nvim'
Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'}
Plug 'kyazdani42/nvim-web-devicons'
call plug#end()
" set completeopt=menu,menuone,noselect
" Use `:Format` to format current buffer
" command! -nargs=0 Format :call CocAction('format')
" Use `:Fold` to fold current buffer
" command! -nargs=? Fold :call CocAction('fold', <f-args>)
" use `:OR` for organize import of current buffer
" command! -nargs=0 OrganizeImports :call CocAction('runCommand', 'editor.action.organizeImport')
" command! -bang -nargs=* RipGrep :call fzf#vim#grep("rg --column --line-number --no-heading --color=always --smart-case --sort=path".<q-args>, 1, <bang>0)
" nmap <silent> <leader>ng :RipGrep
" Add status line support, for integration with other plugin, checkout `:h coc-status`
" set statusline^=%{coc#status()}%{get(b:,'coc_current_function','')}
" command! -nargs=* -complete=dir Cd call fzf#run(fzf#wrap(
" \ {'source': 'fd --type d . /',
" \ 'sink': 'cd'}))
command! CopyCurrentFilePath let @+ = expand("%:p")
command! ReloadConfig :source $MYVIMRC
command! GoToCurrentFileDir :edit %:p:h
" function! CocInstallMine()
" :CocInstall
" \ coc-json
" \ coc-tsserver
" \ coc-css
" \ coc-vimlsp
" \ coc-eslint
" \ coc-prettier
" endfunction
function SetLightTheme()
set background=light
colorscheme onehalflight
let $BAT_THEME='OneHalfLight'
let g:airline_theme='onehalflight'
try
AirlineTheme onehalflight
catch
endtry
endfunction
function SetDarkTheme()
set background=dark
colorscheme onehalfdark
let $BAT_THEME='OneHalfDark'
let g:airline_theme='onehalfdark'
try
AirlineTheme onehalfdark
catch
endtry
endfunction
function SetCurrentSystemTheme()
let l:theme = 'light'
let l:system = GetSystem()
if l:system == 'Macos'
let l:mode = systemlist('defaults read -g AppleInterfaceStyle')[0]
if l:mode == 'Dark'
let l:theme = 'dark'
endif
elseif l:system == 'Windows' || l:system == 'LinuxWsl'
let l:appsUseLightTheme = systemlist('reg.exe query "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize" /v AppsUseLightTheme | sed "2 s/.*//" | sed "3 s/^.*0x//g" | sed "/^\s*$/d"')[0]
if l:appsUseLightTheme == 0
let l:theme = 'dark'
endif
endif
if l:theme == 'dark'
call SetDarkTheme()
else
call SetLightTheme()
endif
endfunction
command! SetLightTheme :call SetLightTheme()
command! SetDarkTheme :call SetDarkTheme()
command! SetCurrentSystemTheme :call SetCurrentSystemTheme()
" set termguicolors
syntax on
set background=dark
try
colorscheme onehalfdark
" colorscheme one
catch
colorscheme slate
endtry
set number relativenumber
set clipboard=unnamed
set expandtab
set softtabstop=2
set shiftwidth=2
set nowrap
set wildmode=longest:full
set autoread
try
set winblend=10
catch
endtry
set ignorecase
let mapleader = ' '
let g:NERDTreeShowHidden = 1
try
let g:airline_theme='onehalfdark'
let g:airline#extensions#tabline#enabled = 1
let g:airline_powerline_fonts = 1
let g:airline#extensions#tabline#buffer_nr_show = 1
"let g:airline#extensions#tabline#left_sep = ' '
"let g:airline#extensions#tabline#left_alt_sep = '|'
"let g:airline#extensions#tabline#formatter = 'unique_tail'
catch
echo 'Airline is not installed, give :PlugInstall a try'
endtry
call SetCurrentSystemTheme()
" Some servers have issues with backup files, see #649
set nobackup
set nowritebackup
" Better display for messages
set cmdheight=2
" You will have bad experience for diagnostic messages when it's default 4000.
set updatetime=300
" don't give |ins-completion-menu| messages.
set shortmess+=c
" always show signcolumns
set signcolumn=yes
" Use tab for trigger completion with characters ahead and navigate.
" Use command ':verbose imap <tab>' to make sure tab is not mapped by other plugin.
"inoremap <silent><expr> <C-TAB>
" \ pumvisible() ? "\<C-n>" :
" \ <SID>check_back_pace() ? "\<C-TAB>" :
" \ coc#refresh()
" inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"
" function! s:check_back_pace() abort
" let col = col('.') - 1
" endfunction
" Trigger completion.
" inoremap <silent><expr> <alt-pace> coc#refresh()
" imap <silent> <c-p> <Plug>(completion_trigger)
" imap <tab> <Plug>(completion_smart_tab)
" imap <s-tab> <Plug>(completion_smart_s_tab)
" imap <silent> <c-p>
" imap <tab> <C-X><C-O>
" imap <s-tab> <Plug>(completion_smart_s_tab)
" Use <cr> to confirm completion, `<C-g>u` means break undo chain at current position.
" Coc only does snippet and additional edit on confirm.
" inoremap <expr> <cr> pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>"
" Or use `complete_info` if your vim support it, like:
" inoremap <expr> <cr> complete_info()["selected"] != "-1" ? "\<C-y>" : "\<C-g>u\<CR>"
" Navigate diagnostics
" nmap <silent> <leader>d[ <Plug>(coc-diagnostic-prev)
" nmap <silent> <leader>d] <Plug>(coc-diagnostic-next)
" Remap keys for gotos
" nmap <silent> <leader>gd <Plug>(coc-definition)
" nmap <silent> <leader>gt <Plug>(coc-type-definition)
" nmap <silent> <leader>gi <Plug>(coc-implementation)
" nmap <silent> <leader>gr <Plug>(coc-references)
" Find symbol of current document
" nnoremap <silent> <leader>gs :<C-u>CocList outline<cr>
" Use K to show documentation in preview window
" nnoremap <silent> <leader>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 symbol under cursor on CursorHold
" autocmd CursorHold * silent call CocActionAsync('highlight')
" Remap for rename current word
" nmap <leader>rn <Plug>(coc-rename)
" nmap <leader>ar <Plug>(coc-rename)
" Remap for format selected region
" xmap <leader>af <Plug>(coc-format-selected)
" nmap <leader>af <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
function! ChangeDirToPrj()
let l:Args = argv()
if len(l:Args) != 1 " do it only when a single folder was passed to Vim as arg
return
endif
if isdirectory(l:Args[0])
exec 'chdir ' .. l:Args[0]
endif
endfunction
augroup VIMRC
autocmd!
autocmd VimEnter * call ChangeDirToPrj()
augroup END
" Remap for do codeAction of selected region, ex: `<leader>aap` for current paragraph
" xmap <leader>a <Plug>(coc-codeaction-selected)
" nmap <leader>a <Plug>(coc-codeaction-selected)
" Remap for do codeAction of current line
" nmap <leader>ac <Plug>(coc-codeaction)
" Fix autofix problem of current line
" nmap <leader>rf <Plug>(coc-fix-current)
" Create mappings for function text object, requires document symbols feature of languageserver.
" xmap if <Plug>(coc-funcobj-i)
" xmap af <Plug>(coc-funcobj-a)
" omap if <Plug>(coc-funcobj-i)
" omap af <Plug>(coc-funcobj-a)
" Use <TAB> for select selections ranges, needs server support, like: coc-tsserver, coc-python
"nmap <silent> <TAB> <Plug>(coc-range-select)
"xmap <silent> <TAB> <Plug>(coc-range-select)
" NAVIGATION
nnoremap <leader>[ <C-o>
nnoremap <leader>] <C-i>
nnoremap <leader>b] :bnext<CR>
nnoremap <leader>b[ :bprevious<CR>
nnoremap <silent> <leader>bd :bdelete<CR>
nnoremap <silent> <leader>bD :bdelete!<CR>
nnoremap <silent> <leader>nb :Buffers<CR>
nnoremap <leader>nt[ :tabprevious<CR>
nnoremap <leader>nt] :tabnext<CR>
nnoremap <silent> <leader>; :
vnoremap <silent> <leader>; :
" nnoremap <leader>d[ :action GotoPreviousError<CR>
" nnoremap <leader>d] :action GotoNextError<CR>
" nnoremap <silent> <leader>nt :action ActivateTerminalToolWindow<CR>
nnoremap <silent> <leader>np :NERDTreeFind<CR>
nnoremap <silent> <leader>qp :NERDTreeClose<CR>
" nnoremap <silent> <leader>nb :Buffers<CR>
nnoremap <silent> <leader>nb <cmd>Telescope buffers<CR>
nnoremap <silent> <leader>nf <cmd>Telescope live_grep<CR>
" " GOTO
" " nnoremap <silent> <leader>gd :call LanguageClient#textDocument_definition()<CR>
" nnoremap <silent> <leader>gd <cmd>lua vim.lsp.buf.definition()<CR>
" " nnoremap <silent> <leader>gt :call LanguageClient#textDocument_typeDefinition()<CR>
" nnoremap <silent> <leader>gt <cmd>lua vim.lsp.buf.type_definition()<CR>
" " nnoremap <silent> <leader>gi :call LanguageClient#textDocument_implementation()<CR>
" nnoremap <silent> <leader>gi <cmd>lua vim.lsp.buf.implementation()<CR>
" " nnoremap <silent> <leader>gr :call LanguageClient#textDocument_references()<CR>
" nnoremap <silent> <leader>gr <cmd>lua vim.lsp.buf.references()<CR>
" " nnoremap <silent> <leader>gs :call LanguageClient#workspace_symbol()<CR>
" nnoremap <silent> <leader>gs <cmd>lua vim.lsp.buf.workspace_symbol()<CR>
" " nnoremap <silent> <leader>gu :action GotoTest<CR>
" nnoremap <silent> <leader>c :Commands<CR>
nnoremap <silent> <leader>c <cmd>Telescope commands<CR>
" nnoremap <silent> <leader>f :Files<CR>
nnoremap <silent> <leader>f <cmd>Telescope git_files<CR>
nnoremap <silent> <leader>F <cmd>Telescope find_files<CR>
" nnoremap <silent> <leader>e :action SearchEverywhere<CR>
" map <silent> <leader>nd :Cd<CR>
" nnoremap <silent> <leader>m :Maps<CR>
nnoremap <silent> <leader>m <cmd>Telescope keymaps<CR>
" " PREVIEW
" nnoremap <silent> <leader>k :call LanguageClient#textDocument_hover()<CR>
" nnoremap <silent> <leader>k <cmd>lua vim.lsp.buf.hover()<CR>
" " noremap <A-Space> :call LanguageClient#textDocument_completion()<CR>
" inoremap <A-Space> <cmd>lua vim.lsp.buf.completion()<CR>
" " nnoremap <silent> <leader>pd :call QuickImplementations<CR>
" " nnoremap <silent> <leader>pr :call ShowUsages<CR>
" " nnoremap <silent> <leader>pb :call RecentLocations<CR>
" " nnoremap <silent> <leader>ps :call FileStructurePopup<CR>
" " nnoremap <silent> <leader>ps :call LanguageClient#textDocument_documentSymbol()<CR>
" nnoremap <silent> <leader>ps <cmd>lua vim.lsp.buf.document_symbol()<CR>
" " FORMAT FIXES REFACTORINGS
" " nnoremap <silent> <leader>ar :call LanguageClient#textDocument_rename()<CR>
" nnoremap <silent> <leader>ar <cmd>lua vim.lsp.buf.rename()<CR>
" " nnoremap <silent> <leader>am :call LanguageClient#textDocument_codeAction()<CR>
" " vnoremap <silent> <leader>am :call LanguageClient#textDocument_codeAction()<CR>
" nnoremap <silent> <leader>am <cmd>lua vim.lsp.buf.code_action()<CR>
" vnoremap <silent> <leader>am <cmd>lua vim.lsp.buf.code_action()<CR>
" " nnoremap <silent> <leader>af :call LanguageClient#textDocument_formatting()<CR>
" " vnoremap <silent> <leader>af :call LanguageClient#textDocument_rangeFormatting()<CR>
" " nnoremap <silent> <leader>ap :call ReformatWithPrettierAction<CR>
" " nmap <silent> <leader>al :action
" " nnoremap <silent> <leader>rr :action RenameElement<CR>
" " nnoremap <silent> <leader>rm :action Move<CR>
" " nnoremap <silent> <leader>rv :action IntroduceVariable<CR>
" " nnoremap <silent> <leader>ri :action Inline<CR>
" " nnoremap <silent> <leader>rf :action ExtractMethod<CR>
" " nnoremap <silent> <leader>rp :action IntroduceParameter<CR>
let g:neoformat_try_node_exe = 1
nnoremap <silent> <leader>af :Neoformat<CR>
vnoremap <silent> <leader>af :Neoformat<CR>
" FILES
nnoremap <silent> <leader>w :write<CR>
nnoremap <silent> <leader><S-w> :wall<CR>
" TESTS
nnoremap <silent> <leader>tt :TestNearest<CR>
nnoremap <silent> <leader>tf :TestFile<CR>
" nnoremap <silent> <leader>td :action DebugClass<CR>
" nnoremap <silent> <leader>tr :action RerunTest<CR>
" GIT
" nnoremap <silent> <leader>vs :action Git.Branches<CR>
" nnoremap <silent> <leader>vS :action Git.CreateNewBranch<CR>
nnoremap <silent> <leader>vc :Git commit<CR>
nnoremap <silent> <leader>vv :Git<CR>
nnoremap <silent> <leader>vp :Git push<CR>
" nnoremap <silent> <leader>vP :Gpush!<CR>
nnoremap <silent> <leader>vb :Git blame<CR>
nnoremap <silent> <leader>vl :Git pull<CR>
nnoremap <silent> <leader>vf :Git fetch<CR>
" HELP
nmap <silent> <leader>h <cmd>Telescope help_tags<CR>
" ETC
" nnoremap <leader>/ :nohlsearch<CR>
" nnoremap / :action Find<CR>
" nnoremap g/ /
map <silent> <leader>acp :CopyCurrentFilePath<CR>
" DEBUG
" nnoremap <silent> <leader>db :action ToggleLineBreakPoint<CR>
" nnoremap <silent> <leader>do :action StepOver<CR>
" nnoremap <silent> <leader>di :action StepInto<CR>
" nnoremap <silent> <leader>ds :action SmartStepInto<CR>
" nnoremap <silent> <leader>du :action StepOut<CR>
luafile ~/dotfiles/vim.lua