forked from Blacksuan19/init.nvim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.vim
467 lines (387 loc) · 17 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
" ============= Vim-Plug ============== "{{{
" auto-install vim-plug
if empty(glob('~/.config/nvim/autoload/plug.vim'))
silent !curl -fLo ~/.config/nvim/autoload/plug.vim --create-dirs
\ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
autocmd VimEnter * PlugInstall | source $MYVIMRC
endif
call plug#begin(expand('~/.config/nvim/plugged'))
"}}}
" ================= looks and GUI stuff ================== "{{{
Plug 'vim-airline/vim-airline' " airline status bar
Plug 'ryanoasis/vim-devicons' " pretty icons everywhere
Plug 'luochen1990/rainbow' " rainbow parenthesis
Plug 'hzchirs/vim-material' " material color themes
Plug 'gregsexton/MatchTag' " highlight matching html tags
Plug 'Jorengarenar/vim-MvVis' " move visual selection
"}}}
" ================= Functionalities ================= "{{{
Plug 'neoclide/coc.nvim', {'branch': 'release'} " LSP and more
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } } " fzf itself
Plug 'junegunn/fzf.vim' " fuzzy search integration
Plug 'honza/vim-snippets' " actual snippets
Plug 'Yggdroot/indentLine' " show indentation lines
Plug 'tpope/vim-liquid' " liquid language support
Plug 'numirias/semshi', {'do': ':UpdateRemotePlugins'} " better python
Plug 'tpope/vim-commentary' " better commenting
Plug 'mhinz/vim-startify' " cool start up screen
Plug 'tpope/vim-fugitive' " git support
Plug 'psliwka/vim-smoothie' " some very smooth ass scrolling
Plug 'wellle/tmux-complete.vim' " complete words from a tmux panes
Plug 'tpope/vim-eunuch' " run common Unix commands inside Vim
Plug 'dart-lang/dart-vim-plugin'
Plug 'machakann/vim-sandwich' " make sandwiches
Plug 'christoomey/vim-tmux-navigator' " seamless vim and tmux navigation
Plug 'iamcco/markdown-preview.nvim', { 'do': 'cd app && yarn install' }
Plug 'TovarishFin/vim-solidity'
Plug 'lervag/vimtex' " VimTeX
Plug 'folke/tokyonight.nvim'
call plug#end()
"}}}
" vimtex
let g:tex_flavor='latex'
let g:vimtex_view_method='zathura'
let g:vimtex_quickfix_mode=0
set conceallevel=1
let g:tex_conceal='abdmg'
" ==================== general config ======================== "{{{
set termguicolors " Opaque Background
set mouse=a " enable mouse scrolling
set clipboard+=unnamedplus " use system clipboard by default
set tabstop=4 softtabstop=4 shiftwidth=4 autoindent " tab width
set expandtab smarttab " tab key actions
set incsearch ignorecase smartcase hlsearch " highlight text while searching
set list listchars=trail:»,tab:»- " use tab to navigate in list mode
set fillchars+=vert:\▏ " requires a patched nerd font (try FiraCode)
set wrap breakindent " wrap long lines to the width set by tw
set encoding=utf-8 " text encoding
set number " enable numbers on the left
set relativenumber " current line is 0
set title " tab title as file name
set noshowmode " dont show current mode below statusline
set noshowcmd " to get rid of display of last command
set conceallevel=2 " set this so we wont break indentation plugin
set splitright " open vertical split to the right
set splitbelow " open horizontal split to the bottom
set tw=90 " auto wrap lines that are longer than that
set emoji " enable emojis
set history=1000 " history limit
set backspace=indent,eol,start " sensible backspacing
set undofile " enable persistent undo
set undodir=/tmp " undo temp file directory
set foldlevel=0 " open all folds by default
set inccommand=nosplit " visual feedback while substituting
set showtabline=2 " always show tabline
set grepprg=rg\ --vimgrep " use rg as default grepper
" performance tweaks
set nocursorline
set nocursorcolumn
set scrolljump=5
set lazyredraw
set redrawtime=10000
set synmaxcol=180
set re=1
" required by coc
set hidden
set nobackup
set nowritebackup
set cmdheight=1
set updatetime=300
set shortmess+=c
set signcolumn=yes
" Themeing
let g:material_style = 'oceanic'
colorscheme tokyonight
hi Pmenu guibg='#00010a' guifg=white " popup menu colors
hi Comment gui=italic cterm=italic " italic comments
hi Search guibg=#b16286 guifg=#ebdbb2 gui=NONE " search string highlight color
hi NonText guifg=bg " mask ~ on empty lines
hi clear CursorLineNr " use the theme color for relative number
hi CursorLineNr gui=bold " make relative number bold
hi SpellBad guifg=NONE gui=bold,undercurl " misspelled words
" colors for git (especially the gutter)
hi DiffAdd guibg=#0f111a guifg=#43a047
hi DiffChange guibg=#0f111a guifg=#fdd835
hi DiffRemoved guibg=#0f111a guifg=#e53935
" coc multi cursor highlight color
hi CocCursorRange guibg=#b16286 guifg=#ebdbb2
"}}}
" ======================== Plugin Configurations ======================== "{{{
"" built in plugins
let loaded_netrw = 0 " diable netew
let g:omni_sql_no_default_maps = 1 " disable sql omni completion
let g:loaded_python_provider = 0
let g:loaded_perl_provider = 0
let g:loaded_ruby_provider = 0
" Airline
let g:airline_theme='material'
let g:airline_skip_empty_sections = 1
let g:airline_section_warning = ''
let g:airline_section_x=''
let g:airline_section_z = airline#section#create(['%3p%% ', 'linenr', ':%c'])
let g:airline#parts#ffenc#skip_expected_string='utf-8[unix]'
let g:airline#extensions#tabline#enabled = 1
let g:airline#extensions#tabline#buffer_min_count = 2 " show tabline only if there is more than 1 buffer
let g:airline#extensions#tabline#fnamemod = ':t' " show only file name on tabs
let airline#extensions#coc#error_symbol = '✘:'
let airline#extensions#coc#warning_symbol = '⚠:'
if !exists('g:airline_symbols')
let g:airline_symbols = {}
endif
let g:airline_symbols.linenr = ''
let g:airline_symbols.branch = '⎇ '
let g:airline_symbols.dirty= ''
"" coc
" Navigate snippet placeholders using tab
let g:coc_snippet_next = '<Tab>'
let g:coc_snippet_prev = '<S-Tab>'
" list of the extensions to make sure are always installed
let g:coc_global_extensions = [
\'coc-yank',
\'coc-pairs',
\'coc-json',
\'coc-css',
\'coc-html',
\'coc-tsserver',
\'coc-yaml',
\'coc-lists',
\'coc-snippets',
\'coc-pyright',
\'coc-clangd',
\'coc-prettier',
\'coc-xml',
\'coc-syntax',
\'coc-git',
\'coc-marketplace',
\'coc-highlight',
\'coc-flutter',
\]
" indentLine
let g:indentLine_char_list = ['▏', '¦', '┆', '┊']
let g:indentLine_setColors = 0
let g:indentLine_setConceal = 0 " actually fix the annoying markdown links conversion
let g:indentLine_fileTypeExclude = ['startify']
"" startify
let g:startify_padding_left = 10
let g:startify_session_persistence = 1
let g:startify_enable_special = 0
let g:startify_change_to_vcs_root = 1
let g:startify_lists = [
\ { 'type': 'dir' },
\ { 'type': 'files' },
\ { 'type': 'sessions' },
\ { 'type': 'bookmarks' },
\ { 'type': 'commands' },
\ ]
" bookmark examples
let g:startify_bookmarks = [
\ {'v': '~/.config/nvim'},
\ {'d': '~/.dotfiles' }
\ ]
" custom commands
let g:startify_commands = [
\ {'ch': ['Health Check', ':checkhealth']},
\ {'ps': ['Plugins status', ':PlugStatus']},
\ {'pu': ['Update vim plugins',':PlugUpdate | PlugUpgrade']},
\ {'uc': ['Update coc Plugins', ':CocUpdate']},
\ {'h': ['Help', ':help']},
\ ]
" custom banner
let g:startify_custom_header = [
\ '',
\ ' ▟▙ ',
\ ' ▝▘ ',
\ ' ██▃▅▇█▆▖ ▗▟████▙▖ ▄████▄ ██▄ ▄██ ██ ▗▟█▆▄▄▆█▙▖',
\ ' ██▛▔ ▝██ ██▄▄▄▄██ ██▛▔▔▜██ ▝██ ██▘ ██ ██▛▜██▛▜██',
\ ' ██ ██ ██▀▀▀▀▀▘ ██▖ ▗██ ▜█▙▟█▛ ██ ██ ██ ██',
\ ' ██ ██ ▜█▙▄▄▄▟▊ ▀██▙▟██▀ ▝████▘ ██ ██ ██ ██',
\ ' ▀▀ ▀▀ ▝▀▀▀▀▀ ▀▀▀▀ ▀▀ ▀▀ ▀▀ ▀▀ ▀▀',
\ '',
\ '',
\ '',
\]
" rainbow brackets
let g:rainbow_active = 1
" tmux navigator
let g:tmux_navigator_no_mappings = 1
" semshi settings
let g:semshi#error_sign = v:false " let ms python lsp handle this
"" FZF
let g:fzf_action = {
\ 'ctrl-t': 'tab split',
\ 'ctrl-x': 'split',
\ 'ctrl-v': 'vsplit' }
let g:fzf_layout = {'up':'~90%', 'window': { 'width': 0.8, 'height': 0.8,'yoffset':0.5,'xoffset': 0.5, 'border': 'sharp' } }
let g:fzf_tags_command = 'ctags -R'
let $FZF_DEFAULT_OPTS = '--layout=reverse --inline-info'
let $FZF_DEFAULT_COMMAND = "rg --files --hidden --glob '!.git/**' --glob '!build/**' --glob '!.dart_tool/**' --glob '!.idea' --glob '!node_modules'"
"}}}
" ======================== Commands ============================= "{{{
au BufEnter * set fo-=c fo-=r fo-=o " stop annoying auto commenting on new lines
au FileType help wincmd L " open help in vertical split
au BufWritePre * :%s/\s\+$//e " remove trailing whitespaces before saving
au CursorHold * silent call CocActionAsync('highlight') " highlight match on cursor hold
" enable spell only if file type is normal text
let spellable = ['markdown', 'gitcommit', 'txt', 'text', 'liquid', 'rst']
autocmd BufEnter * if index(spellable, &ft) < 0 | set nospell | else | set spell | endif
" coc completion popup
autocmd! CompleteDone * if pumvisible() == 0 | pclose | endif
" startify if no passed argument or all buffers are closed
augroup noargs
" startify when there is no open buffer left
autocmd BufDelete * if empty(filter(tabpagebuflist(), '!buflisted(v:val)')) | Startify | endif
" open startify on start if no argument was passed
autocmd VimEnter * if argc() == 0 | Startify | endif
augroup END
" fzf if passed argument is a folder
augroup folderarg
" change working directory to passed directory
autocmd VimEnter * if argc() != 0 && isdirectory(argv()[0]) | execute 'cd' fnameescape(argv()[0]) | endif
" start startify (fallback if fzf is closed)
autocmd VimEnter * if argc() != 0 && isdirectory(argv()[0]) | Startify | endif
" start fzf on passed directory
autocmd VimEnter * if argc() != 0 && isdirectory(argv()[0]) | execute 'Files ' fnameescape(argv()[0]) | endif
augroup END
" Return to last edit position when opening files
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal! g`\"" |
\ endif
"skeleton for new files
autocmd BufNewFile *.cpp 0r ~/.config/nvim/skeleton.cpp
autocmd BufNewFile *.h 0r ~/.config/nvim/skeleton.h
autocmd BufNewFile *.py 0r ~/.config/nvim/skeleton.py
" python renaming
autocmd FileType python nnoremap <leader>rn :Semshi rename <CR>
" format with available file format formatter
command! -nargs=0 Format :call CocAction('format')
" organize imports
command! -nargs=0 OR :call CocAction('runCommand', 'editor.action.organizeImport')
" files in fzf
command! -bang -nargs=? -complete=dir Files
\ call fzf#vim#files(<q-args>, fzf#vim#with_preview({'options': ['--layout=reverse', '--inline-info']}), <bang>0)
" advanced grep
command! -nargs=* -bang Rg call RipgrepFzf(<q-args>, <bang>0)
"}}}
" ================== Custom Functions ===================== "{{{
" advanced grep(faster with preview)
function! RipgrepFzf(query, fullscreen)
let command_fmt = 'rg --column --line-number --no-heading --color=always --smart-case %s || true'
let initial_command = printf(command_fmt, shellescape(a:query))
let reload_command = printf(command_fmt, '{q}')
let spec = {'options': ['--phony', '--query', a:query, '--bind', 'change:reload:'.reload_command]}
call fzf#vim#grep(initial_command, 1, fzf#vim#with_preview(spec), a:fullscreen)
endfunction
" startify file icons
function! StartifyEntryFormat()
return 'WebDevIconsGetFileTypeSymbol(absolute_path) ." ". entry_path'
endfunction
" check if last inserted char is a backspace (used by coc pmenu)
function! s:check_back_space() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~# '\s'
endfunction
" show docs on things with K
function! s:show_documentation()
if (index(['vim','help'], &filetype) >= 0)
execute 'h '.expand('<cword>')
else
call CocAction('doHover')
endif
endfunction
"}}}
" ======================== Custom Mappings ====================== "{{{
"" the essentials
let mapleader=","
nnoremap ; :
nmap \ <leader>q
map <F6> :Startify <CR>
nmap <leader>r :so ~/.config/nvim/init.vim<CR>
nmap <leader>q :bd<CR>
nmap <leader>w :w<CR>
map <leader>s :Format<CR>
nmap <Tab> :bnext<CR>
nmap <S-Tab> :bprevious<CR>
noremap <leader>e :PlugInstall<CR>
noremap <C-q> :q<CR>
" new line in normal mode and back
map <Enter> o<ESC>
map <S-Enter> O<ESC>
" use a different register for delete and paste
nnoremap d "_d
vnoremap d "_d
vnoremap p "_dP
nnoremap x "_x
" emulate windows copy, cut behavior
vnoremap <LeftRelease> "+y<LeftRelease>
vnoremap <C-c> "+y<CR>
vnoremap <C-x> "+d<CR>
" switch between splits using ctrl + {h,j,k,l}
inoremap <C-h> <C-\><C-N><C-w>h
inoremap <C-j> <C-\><C-N><C-w>j
inoremap <C-k> <C-\><C-N><C-w>k
inoremap <C-l> <C-\><C-N><C-w>l
nnoremap <C-h> <C-w>h
noremap <C-j> <C-w>j
nnoremap <C-k> <C-w>k
nnoremap <C-l> <C-w>l
" disable hl with 2 esc
noremap <silent><esc> <esc>:noh<CR><esc>
" trim white spaces
nnoremap <F2> :let _s=@/<Bar>:%s/\s\+$//e<Bar>:let @/=_s<Bar><CR>
" markdown preview
au FileType markdown nmap <leader>m :MarkdownPreview<CR>
"" FZF
nnoremap <silent> <leader>f :Files<CR>
nmap <leader>b :Buffers<CR>
nmap <leader>c :Commands<CR>
nmap <leader>t :BTags<CR>
nmap <leader>/ :Rg<CR>
nmap <leader>gc :Commits<CR>
nmap <leader>gs :GFiles?<CR>
nmap <leader>sh :History/<CR>
" show mapping on all modes with F1
nmap <F1> <plug>(fzf-maps-n)
imap <F1> <plug>(fzf-maps-i)
vmap <F1> <plug>(fzf-maps-x)
"" coc
" use tab to navigate snippet placeholders
inoremap <silent><expr> <TAB>
\ pumvisible() ? "\<C-n>" :
\ <SID>check_back_space() ? "\<TAB>" :
\ coc#refresh()
inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"
" Use enter to accept snippet expansion
inoremap <expr> <cr> pumvisible() ? "\<C-y>" : "\<CR>"
" multi cursor shortcuts
nmap <silent> <C-a> <Plug>(coc-cursors-word)
xmap <silent> <C-a> <Plug>(coc-cursors-range)
" Use `[g` and `]g` to navigate diagnostics
nmap <silent> [g <Plug>(coc-diagnostic-prev)
nmap <silent> ]g <Plug>(coc-diagnostic-next)
" other stuff
nmap <leader>rn <Plug>(coc-rename)
nmap <leader>o :OR <CR>
" jump stuff
nmap <leader>jd <Plug>(coc-definition)
nmap <leader>jy <Plug>(coc-type-definition)
nmap <leader>ji <Plug>(coc-implementation)
nmap <leader>jr <Plug>(coc-references)
" other coc actions
nnoremap <silent> K :call <SID>show_documentation()<CR>
nmap <leader>a <Plug>(coc-codeaction-line)
xmap <leader>a <Plug>(coc-codeaction-selected)
" flutter mappings
nnoremap <F3> :CocCommand flutter.devices<CR>
nnoremap <F4> :CocCommand flutter.emulators<CR>
nnoremap <F5> :CocCommand flutter.run<CR>
" fugitive mappings
nmap <leader>gd :Gdiffsplit<CR>
nmap <leader>gb :Git blame<CR>
" tmux navigator
nnoremap <silent> <C-h> :TmuxNavigateLeft<cr>
nnoremap <silent> <C-l> :TmuxNavigateRight<cr>
nnoremap <silent> <C-j> :TmuxNavigateDown<cr>
nnoremap <silent> <C-k> :TmuxNavigateUp<cr>
inoremap ;i <Esc>
"}}}