forked from knight-byte/Vim-Configuration
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.vim
510 lines (446 loc) · 16.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
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
"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
" _ _ _ |
" / \ | |__ _ _ _ __ __ _ ___| |__ __ _ _ __ |
" / _ \ | '_ \| | | | '_ \ / _` |/ __| '_ \ / _` | '__| |
" / ___ \| |_) | |_| | | | | (_| | (__| | | | (_| | | |
" /_/ \_\_.__/ \__,_|_| |_|\__,_|\___|_| |_|\__,_|_| |
" |
"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+~~~~~~~~~~~~+
" |
" FILENAME : init.vim |
" AUTHOR : Abunachar ( knight-byte ) |
" GITHUB : https://www.github.com/knight-byte |
" |
" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+
" Plugins {{{
syntax on
call plug#begin('~/.vim/plugged')
Plug 'scrooloose/nerdtree' " file list
Plug 'majutsushi/tagbar' " show tags in a bar (functions etc) for easy browsing
Plug 'vim-airline/vim-airline' " make statusline awesome
Plug 'vim-airline/vim-airline-themes' " themes for statusline
Plug 'jonathanfilip/vim-lucius' " nice white colortheme
Plug 'kyoz/purify', { 'rtp': 'vim' }
Plug 'davidhalter/jedi-vim' " jedi for python
Plug 'tiagofumo/vim-nerdtree-syntax-highlight' "to highlight files in nerdtree
Plug 'Vimjas/vim-python-pep8-indent' "better indenting for python
Plug 'ctrlpvim/ctrlp.vim' " fuzzy search files
Plug 'tweekmonster/impsort.vim' " color and sort imports
Plug 'wsdjeg/FlyGrep.vim' " awesome grep on the fly
Plug 'w0rp/ale' " python linters
Plug 'airblade/vim-gitgutter' " show git changes to files in gutter
Plug 'tpope/vim-commentary' "comment-out by gc
Plug 'roxma/nvim-yarp' " dependency of ncm2
Plug 'ncm2/ncm2' " awesome autocomplete plugin
Plug 'ncm2/ncm2-bufword' " buffer keyword completion
Plug 'morhetz/gruvbox'
Plug 'neoclide/coc.nvim', {'branch': 'release'}
Plug 'Shougo/deoplete.nvim' "Async autocompletion
Plug 'roxma/nvim-yarp'
Plug 'roxma/vim-hug-neovim-rpc'
Plug 'zchee/deoplete-jedi' " Python autocompletion
Plug 'Shougo/context_filetype.vim' " Completion from other opened files
Plug 'davidhalter/jedi-vim' " Just to add the python go-to-definition and similar features, autocompletion
Plug 'Townk/vim-autoclose' " Automatically close parenthesis, etc
Plug 'tpope/vim-surround'
Plug 'michaeljsmith/vim-indent-object' " Indent text object
Plug 'jeetsukumaran/vim-indentwise' " Indentation based movements
Plug 'sheerun/vim-polyglot' " Better language packs
Plug 'mileszs/ack.vim' " Ack code search (requires ack installed in the system)
Plug 'lilydjwg/colorizer' " Paint css colors with the real color
Plug 'ryanoasis/vim-devicons' "NerdTree Icon
"Plug 'vim-syntastic/syntastic' "Syntax highlight
"Plug 'nvie/vim-flake8' "PEP check
Plug 'tell-k/vim-autopep8' "autopep8
"Plug 'ghifarit53/tokyonight-vim' "Tokyonight theme
"Plug 'joshdick/onedark.vim' "Onedark
Plug 'Yggdroot/indentLine'
Plug 'ajmwagar/vim-deus'
"Plug 'numirias/semshi', { 'do': ':UpdateRemotePlugins' } "Highlight python
Plug 'vim-pandoc/vim-pandoc'
Plug 'vim-pandoc/vim-rmarkdown'
Plug 'vim-pandoc/vim-pandoc-syntax'
call plug#end()
" }}}
" Set options {{{
command! -nargs=0 Prettier :CocCommand prettier.formatFile
" path to your python
let g:python3_host_prog = '/usr/bin/python3'
let g:python_host_prog = '/usr/bin/python'
filetype indent on
set foldmethod=marker
set fileformat=unix
set shortmess+=c
set mouse=a " change cursor per mode
set number " always show current line number
set smartcase " better case-sensitivity when searching
set wrapscan " begin search from top of file when nothing is found anymore
set expandtab
set tabstop=4
set shiftwidth=4
set fillchars+=vert:\ " remove chars from seperators
set softtabstop=4
set history=1000 " remember more commands and search history
set nobackup " no backup or swap file, live dangerously
set noswapfile " swap files give annoying warning
set breakindent " preserve horizontal whitespace when wrapping
set showbreak=..
set lbr " wrap words
set nowrap " i turn on wrap manually when needed
set scrolloff=3 " keep three lines between the cursor and the edge of the screen
set undodir=~/.vim/undodir
set undofile " save undos
set undolevels=10000 " maximum number of changes that can be undone
set undoreload=100000 " maximum number lines to save for undo on a buffer reload
set noshowmode " keep command line clean
set noshowcmd
set laststatus=2 " always slow statusline
set splitright "i prefer splitting right and below
set splitbelow
set hlsearch " highlight search and search while typing
set incsearch
set cpoptions+=x " stay at seach item when <esc>
set noerrorbells " remove bells (i think this is default in neovim)
set visualbell
set t_vb=
set relativenumber
set viminfo='20,<1000 " allow copying of more than 50 lines to other applications
set encoding=UTF-8
"let g:WebDevIconsNerdTreeAfterGlyphPadding = ' '
autocmd FileType nerdtree setlocal nolist
let g:WebDevIconsNerdTreeAfterGlyphPadding = ' '
" semshi settings
"let g:semshi#error_sign = v:false
" intendation lines
"let g:indentLine_enabled = 1
" }}}
" easy split movement {{{
nnoremap <C-h> <C-w>h
nnoremap <C-j> <C-w>j
nnoremap <C-k> <C-w>k
nnoremap <C-l> <C-w>l
" }}}
" tabs: {{{
nnoremap tn :tabnew<Space>
nnoremap tk :tabnext<CR>
nnoremap tj :tabprev<CR>
nnoremap th :tabfirst<CR>
nnoremap tl :tablast<CR>
" }}}
" colorscheme options {{{
colorscheme gruvbox
let g:gruvbox_contrast_dark = 'hard'
"highlight Comment ctermfg=Red
"colorscheme deus
"let g:deus_termcolors=256
"set termguicolors
"let g:tokyonight_style = 'storm' " available: night, storm
"let g:tokyonight_enable_italic = 1
"colorscheme tokyonight
"colorscheme onedark
" }}}
" mapping Esc {{{
imap <F13> <Esc>
cnoremap <Esc> <C-c>
inoremap <c-c> <ESC>
nnoremap <C-z> <Esc> " disable terminal ctrl-z
" }}}
" map S to replace current word with pasteboard {{{
nnoremap S diw"0P
nnoremap cc "_cc
nnoremap q: :q<CR>
nnoremap w: :w<CR>
" map paste, yank and delete to named register so the content
" will not be overwritten (I know I should just remember...)
nnoremap x "_x
vnoremap x "_x
set clipboard=unnamedplus
" }}}
" toggle nerdtree on ctrl+n {{{
map <C-n> :NERDTreeToggle<CR>
map <C-t> :set nosplitright<CR>:TagbarToggle<CR>:set splitright<CR>
" }}}
" ncm2 settings {{{
autocmd BufEnter * call ncm2#enable_for_buffer()
set completeopt=menuone,noselect,noinsert
" make it FAST
let ncm2#popup_delay = 5
let ncm2#complete_length = [[1,1]]
let g:ncm2#matcher = 'substrfuzzy'
set pumheight=5
" }}}
" Tab set {{{
inoremap <expr> <Tab> pumvisible() ? "\<C-n>" : "\<Tab>"
inoremap <expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<S-Tab>"
inoremap <silent> <expr> <CR> (pumvisible() && empty(v:completed_item)) ? "\<c-y>\<cr>" : "\<CR>"
" }}}
" Airline settings {{{
" do not show error/warning section
let g:airline_symbols = {'s1':''}
let g:airline_section_error = ""
let g:airline_powerline_fonts = 1
let g:airline#extensions#tabline#enabled = 1
let g:airline_section_warning = ""
let g:airline_section_c = "%<%t%m %#__accent_red#%{airline#util#wrap(airline#parts#readonly(),0)}%#__restore__#%#__accent_bold#%{airline#util#wrap(airline#extensions#coc#get_status(),0)}%#__restore__#%#__accent_bold#%#__restore__#"
if !exists('g:airline_symbols')
let g:airline_symbols = {}
endif
let mapleader = " " " Leader is the space key
let g:mapleader = " "
let maplocalleader = "`"
let g:maplocalleader = "`"
nnoremap <SPACE> <Nop>
" }}}
"auto indent for brackets {{{
nmap <leader>w :w!<cr>
nmap <leader>q :lcl<cr>:q<cr>
nnoremap <leader>h :nohlsearch<Bar>:echo<CR>
"}}}
" FlyGrep settings {{{
nnoremap <leader>s :FlyGrep<cr>
" }}}
" easy breakpoint python {{{
au FileType python map <silent> <leader>b ofrom pudb import set_trace; set_trace()<esc>
au FileType python map <silent> <leader>B Ofrom pudb import set_trace; set_trace()<esc>
au FileType python map <silent> <leader>j ofrom pdb import set_trace; set_trace()<esc>
au FileType python map <silent> <leader>J Ofrom pdb import set_trace; set_trace()<esc>
" }}}
" ale options {{{
let g:autopep8_on_save = 1
let g:autopep8_disable_show_diff=1
let g:ale_python_flake8_options = '--ignore=E129,E501,E302,E265,E241,E305,E402,W503'
"let g:ale_python_pylint_options = '-j 0 --max-line-length=120'
let g:ale_fixers = {
\ 'javascript': ['prettier'],
\ 'css': ['prettier'],
\ 'python': ['prettier'],
\}
" let g:ale_linters_ignore = {'python': ['pylint','flake8','pyls','pyright']}
let g:ale_list_window_size = 4
let g:ale_sign_column_always = 0
let g:ale_open_list = 1
let g:ale_keep_list_window_open = '0'
let g:ale_sign_error = '‼'
let g:ale_sign_warning = '∙'
let g:ale_lint_on_text_changed = 'never'
let g:ale_lint_on_enter = '0'
let g:ale_lint_on_save = '1'
let g:ale_cpp_clangcheck_executable = ''
nmap <silent> <C-M> <Plug>(ale_previous_wrap)
nmap <silent> <C-m> <Plug>(ale_next_wrap)
" }}}
" COC configuration {{{
let g:coc_global_extensions = [
\ 'coc-snippets',
\ 'coc-pairs',
\ 'coc-tsserver',
\ 'coc-eslint',
\ 'coc-prettier',
\ 'coc-json',
\ 'coc-python',
\ 'coc-clangd',
\ ]
let python_highlight_all=1
" inoremap <silent><expr> <DOWN>
" \ pumvisible() ? "\<C-n>" :
" \ <SID>check_back_space() ? "\<TAB>" :
" \ coc#refresh()
"
"inoremap <expr><S-TAB> pumvisible() ? "\<C-n>" : "\<C-h>"
" Options are in .pylintrc!
inoremap <silent><expr> <TAB>
\ pumvisible() ? "\<C-n>" :
\ coc#expandableOrJumpable() ? "\<C-r>=coc#rpc#request('doKeymap', ['snippets-expand-jump',''])\<CR>" :
\ <SID>check_back_space() ? "\<TAB>" :
\ coc#refresh()
function! s:check_back_space() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~# '\s'
endfunction
let g:coc_snippet_next = '<tab>'
highlight VertSplit ctermbg=253
inoremap <silent><expr> <c-space> coc#refresh()
" inoremap <expr> <DOWN> pumvisible() ? "\<TAB>" : "\<DOWN>"
" Use `[g` and `]g` to navigate diagnostics
" nmap <silent> [g <Plug>(coc-diagnostic-prev)
" nmap <silent> ]g <Plug>(coc-diagnostic-next)
" Remap keys for gotos
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)
" Highlight symbol under cursor on CursorHold
autocmd CursorHold * silent call CocActionAsync('highlight')
" Remap for rename current word
nmap <F2> <Plug>(coc-rename)
" Remap for format selected region
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
" 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>qf <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 <C-d> for select selections ranges, needs server support, like: coc-tsserver, coc-python
nmap <silent> <C-d> <Plug>(coc-range-select)
xmap <silent> <C-d> <Plug>(coc-range-select)
" 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 OR :call CocAction('runCommand', 'editor.action.organizeImport')
" Add status line support, for integration with other plugin, checkout `:h coc-status`
set statusline^=%{coc#status()}%{get(b:,'coc_current_function','')}
" }}}
" 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>
function! s:show_documentation()
if (index(['vim','help'], &filetype) >= 0)
execute 'h '.expand('<cword>')
else
call CocAction('doHover')
endif
endfunction
"}}}
" mapping to make movements operate on 1 screen line in wrap mode {{{
function! ScreenMovement(movement)
if &wrap
return "g" . a:movement
else
return a:movement
endif
endfunction
onoremap <silent> <expr> j ScreenMovement("j")
onoremap <silent> <expr> k ScreenMovement("k")
onoremap <silent> <expr> 0 ScreenMovement("0")
onoremap <silent> <expr> ^ ScreenMovement("^")
onoremap <silent> <expr> $ ScreenMovement("$")
nnoremap <silent> <expr> j ScreenMovement("j")
nnoremap <silent> <expr> k ScreenMovement("k")
nnoremap <silent> <expr> 0 ScreenMovement("0")
nnoremap <silent> <expr> ^ ScreenMovement("^")
nnoremap <silent> <expr> $ ScreenMovement("$")
" }}}
" highlight python and self function {{{
autocmd BufEnter * syntax match Type /\v\.[a-zA-Z0-9_]+\ze(\[|\s|$|,|\]|\)|\.|:)/hs=s+1
autocmd BufEnter * syntax match pythonFunction /\v[[:alnum:]_]+\ze(\s?\()/
hi def link pythonFunction Function
autocmd BufEnter * syn match Self "\(\W\|^\)\@<=self\(\.\)\@="
highlight self ctermfg=239
" }}}
" jedi options {{{
let g:jedi#auto_initialization = 1
let g:jedi#completions_enabled = 0
let g:jedi#auto_vim_configuration = 0
let g:jedi#smart_auto_mappings = 0
let g:jedi#popup_on_dot = 0
let g:jedi#completions_command = ""
let g:jedi#show_call_signatures = "1"
let g:jedi#show_call_signatures_delay = 0
let g:jedi#use_tabs_not_buffers = 0
let g:jedi#show_call_signatures_modes = 'i' " ni = also in normal mode
let g:jedi#enable_speed_debugging=0
let g:jedi#force_py_version = 3
let g:pymode_python = 'python3'
" }}}
" Impsort option {{{
hi pythonImportedObject ctermfg=127
hi pythonImportedFuncDef ctermfg=127
hi pythonImportedClassDef ctermfg=127
" }}}
" Remove all trailing whitespace by pressing C-S {{{
nnoremap <C-S> :let _s=@/<Bar>:%s/\s\+$//e<Bar>:let @/=_s<Bar><CR>
autocmd BufReadPost quickfix nnoremap <buffer> <CR> <CR>
" }}}
" move between defs python {{{
" NOTE: this break shortcuts with []
nnoremap [[ [m
nnoremap ]] ]m
nnoremap <silent><nowait> [ [[
nnoremap <silent><nowait> ] ]]
function! MakeBracketMaps()
nnoremap <silent><nowait><buffer> [ :<c-u>exe 'normal '.v:count.'[m'<cr>
nnoremap <silent><nowait><buffer> ] :<c-u>exe 'normal '.v:count.']m'<cr>
endfunction
augroup bracketmaps
autocmd!
autocmd FileType python call MakeBracketMaps()
augroup END
" }}}
" neovim options {{{
au BufEnter * if &buftype == 'terminal' | :startinsert | endif
nnoremap <C-a> <Esc>
nnoremap <C-x> <Esc>
" }}}
" vimgutter options {{{
let g:gitgutter_override_sign_column_highlight = 0
let g:gitgutter_map_keys = 0
" }}}
" ctrl p options {{{
let g:ctrlp_custom_ignore = '\v\.(npy|jpg|pyc|so|dll)$'
let g:ctrlp_user_command = ['.git', 'cd %s && git ls-files -co --exclude-standard']
" }}}
" Split Alignment {{{
noremap <silent> <C-S-Left> :vertical resize +1<CR>
noremap <silent> <C-S-Right> :vertical resize -1<CR>
noremap <silent> <C-S-Up> :resize +1<CR>
noremap <silent> <C-S-Down> :resize -1<CR>
" }}}
" Copy Paste Command{{{
" CTRL-C to copy (visual mode)
vmap <C-c> y
" CTRL-X to cut (visual mode)
vmap <C-x> x
" CTRL-V to paste (insert mode)
imap <C-v> <esc>P
imap <C-s> <esc>:w<CR>
" }}}
" Markdown {{{
let g:markdown_fenced_languages = ['python']
let g:indentLine_concealcursor = ""
" let g:indentLine_conceallevel = 0
highlight htmlBold gui=bold ctermfg=203
highlight htmlItalic gui=italic ctermfg=111
" autocmd BufNewFile,BufFilePre,BufRead *.rmd,*.Rmd set filetype=markdown
autocmd FileType python,python3,py,py3 map <F5> :!python % <CR>
autocmd Filetype r,R map <f5> :!Rscript % <CR>
autocmd FileType CPP,Cpp,cpp map <F5> :!g++ % -o %:r.out<CR>
autocmd FileType CPP,Cpp,cpp map <F6> :!if [[ -f testcase.txt ]];then cat testcase.txt \| ./%:r.out ;else echo "No file";fi<CR>
" autocmd FileType CPP,Cpp,cpp map <F8> :!cat testcase.txt | ./%<CR>
autocmd FileType CPP,Cpp,cpp map <F7> :!g++ % -o %:r.out && ./%:r.out<CR>
autocmd Filetype markdown,rmd,Rmd map <F5> :!Rscript -e "rmarkdown::render('%', 'pdf_document',quiet=TRUE)" && echo "output created : " %:r".pdf" <CR>
autocmd Filetype tex map <F5> :!pdflatex % -o %:r.pdf<CR>
autocmd Filetype tex,markdown,rmd,Rmd map <F6> :!if [[ -f %:r".pdf" ]];then zathura %:r.pdf & ;else echo "ERROR : "%:r".pdf file don't exists"; fi <CR>
" noremap <silent> <f6> :!Rscript -e "rmarkdown::render('%', 'pdf_document')"<CR>
"}}}
"