-
Notifications
You must be signed in to change notification settings - Fork 0
/
.vimrc
executable file
·429 lines (350 loc) · 13.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
"_
"_ __(_)___ ___ __________
"| | / / / __ `__ \/ ___/ ___/
"_| |/ / / / / / / / / / /__
"____/_/_/ /_/ /_/_/ \___/
"
" By: | Musa Ahmed
" Created On: | August 20, 2021
" Last Modified: | Constantly
" ----------------
" --- Encoding ---
" ----------------
set encoding=utf-8
" --------------------------------
" --- Plugins - Using Vim-Plug ---
" --------------------------------
call plug#begin('~/.vim/plugged')
" Auto-installs Vim-Plug and all plugins if not installed
let data_dir = has('nvim') ? stdpath('data') . '/site' : '~/.vim'
if empty(glob(data_dir . '/autoload/plug.vim'))
silent execute '!curl -fLo '.data_dir.'/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim'
autocmd VimEnter * PlugInstall --sync | source ~/.vimrc
endif
" -------------------
" -- Functionality --
" -------------------
" Smooth Scrolling
Plug 'psliwka/vim-smoothie'
" Distraction-free writing
Plug 'junegunn/goyo.vim'
" JS and JSX Syntax
Plug 'yuezk/vim-js'
Plug 'maxmellon/vim-jsx-pretty'
" C / C++ Extended Highlighting
Plug 'bfrg/vim-cpp-modern'
" Better language support
Plug 'sheerun/vim-polyglot'
" COC-vim language server for auto-complete
Plug 'neoclide/coc.nvim', {'branch': 'release'}
" Fix copy & past problem
Plug 'christoomey/vim-system-copy'
" Easy commenting and uncommenting
Plug 'preservim/nerdcommenter'
" Visual system file explorer
Plug 'preservim/nerdtree'
" Synxtax highlighting and icons for nerdtree
Plug 'tiagofumo/vim-nerdtree-syntax-highlight'
Plug 'ryanoasis/vim-devicons'
" Fuzzy search
Plug 'junegunn/fzf.vim'
" Synxtax checker
Plug 'vim-syntastic/syntastic'
" Search and open previous Files
Plug 'https://github.com/yegappan/mru.git'
" Fancy start screen
Plug 'mhinz/vim-startify'
" Auto code formatting
Plug 'vim-autoformat/vim-autoformat'
" Floating screen
"Plug 'voldikss/vim-floaterm'
" Shows a line for each indent in a space separated file
Plug 'Yggdroot/indentLine'
" Auto bracket pairs
Plug 'jiangmiao/auto-pairs'
" Autocomplete for tailwindcss
Plug 'rodrigore/coc-tailwind-intellisense', {'do': 'npm install'}
" Git Changes Displayer (requires vim 8.0.902+)
Plug 'mhinz/vim-signify'
" ---------------
" -- Aesthetic --
" ---------------
" Status line at the bottom
Plug 'itchyny/lightline.vim'
" Color previews for CSS
Plug 'ap/vim-css-color'
" ------------
" -- Themes --
" ------------
Plug 'joshdick/onedark.vim'
Plug 'ghifarit53/daycula-vim' , {'branch' : 'main'}
" Plug 'morhetz/gruvbox.git'
Plug 'crusoexia/vim-monokai'
Plug 'arcticicestudio/nord-vim'
Plug 'mhartington/oceanic-next'
Plug 'wuelnerdotexe/vim-enfocado'
call plug#end()
" -----------------------
" --- Plugin Settings ---
" -----------------------
" ----------------------------------
" -- Lightline status line config --
" ----------------------------------
let g:lightline = {
\ 'colorscheme': 'daycula',
\ 'separator': { 'left': '', 'right': '' },
\ 'subseparator': { 'left': '', 'right': '' },
\ }
set laststatus=2
set noshowmode
" No statusline in nerdtree window
augroup filetype_nerdtree
au!
au FileType nerdtree call s:disable_lightline_on_nerdtree()
au WinEnter,BufWinEnter,TabEnter * call s:disable_lightline_on_nerdtree()
augroup END
fu s:disable_lightline_on_nerdtree() abort
let nerdtree_winnr = index(map(range(1, winnr('$')), {_,v -> getbufvar(winbufnr(v), '&ft')}), 'nerdtree') + 1
call timer_start(0, {-> nerdtree_winnr && setwinvar(nerdtree_winnr, '&stl', '%#Normal#')})
endfu
" --------------------
" -- Coc-vim config --
" --------------------
" Allows tab completion by pressing tab to select items
inoremap <silent><expr> <TAB>
\ coc#pum#visible() ? coc#pum#next(1):
\ CheckBackspace() ? "\<Tab>" :
\ coc#refresh()
inoremap <expr><S-TAB> coc#pum#visible() ? coc#pum#prev(1) : "\<C-h>"
inoremap <silent><expr> <CR> coc#pum#visible() ? coc#pum#confirm()
\: "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"
function! CheckBackspace() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~# '\s'
endfunction
" GoTo code navigation
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)
" Use K to show documentation in preview window
nnoremap <silent> N :call ShowDocumentation()<CR>
function! ShowDocumentation()
if CocAction('hasProvider', 'hover')
call CocActionAsync('doHover')
else
call feedkeys('N', 'in')
endif
endfunction
" Highlight the symbol and its references when holding the cursor
autocmd CursorHold * silent call CocActionAsync('highlight')
" Auto-installs these extensions on startup if they're missin" g
let g:coc_global_extensions = [
\ 'coc-pyright', 'coc-clangd', 'coc-tsserver',
\ 'coc-prettier', 'coc-emoji', 'coc-rust-analyzer'
\ ]
" " ----------------------
" -- Syntastic config --
" ----------------------
set statusline+=%#warningmsg#
set statusline+=%{SyntasticStatuslineFlag()}
set statusline+=%*
let g:syntastic_always_populate_loc_list = 1
let g:syntastic_auto_loc_list = 0
let g:syntastic_check_on_open = 1
let g:syntastic_check_on_wq = 0
" Error highlighting for error and line
hi SyntasticErrorSign ctermfg=red ctermbg=yellow
hi SyntasticErrorLine ctermbg=black
" ---------------------
" -- NERDTree config --
" ---------------------
" Auto start NERDTree and put cursor in empty buffer
" autocmd VimEnter * NERDTree | wincmd p
" If another buffer tries to replace NERDTree, put it in the other window, and bring back NERDTree.
autocmd BufEnter * if bufname('#') =~ 'NERD_tree_\d\+' && bufname('%') !~ 'NERD_tree_\d\+' && winnr('$') > 1 |
\ let buf=bufnr() | buffer# | execute "normal! \<C-W>w" | execute 'buffer'.buf | endif
" Exit Vim if NERDTree is the only window remaining in the only tab.
autocmd BufEnter * if tabpagenr('$') == 1 && winnr('$') == 1 && exists('b:NERDTree') && b:NERDTree.isTabTree() | quit | endif
let g:NERDTreeWinSize=20 " Nerdtree width
let NERDTreeMinimalUI=1 "remove press ? for help on top of nerdtreedisable 80 extentions of nerdtree for less lag
let g:NERDTreeLimitedSyntax = 1
let g:NERDCreateDefaultMappings = 1 " Create default mappings
let g:NERDSpaceDelims = 1 " Add spaces after comment delimiters by default
let g:NERDCompactSexyComs = 1 " Use compact syntax for prettified multi-line comments
let g:NERDDefaultAlign = 'left' " Align line-wise comment delimiters flush left instead of following code indentation
let g:NERDAltDelims_java = 1 " Set a language to use its alternate delimiters by default
let g:NERDCustomDelimiters = { 'c': { 'left': '/**','right': '*/' } } " Add your own custom formats or override the defaults
let g:NERDCommentEmptyLines = 1 " Allow commenting and inverting empty lines (useful when commenting a region)
let g:NERDTrimTrailingWhitespace = 1 " Enable trimming of trailing whitespace when uncommenting
let g:NERDToggleCheckAllLines = 1 " Enable NERDCommenterToggle to check all selected lines is commented or not
let g:NERDTreeDirArrowExpandable = ''
let g:NERDTreeDirArrowCollapsible = ''
let g:NERDTreeHighlightFolders = 1 " enables folder icon highlighting using exact match
let g:NERDTreeHighlightFoldersFullName = 1 " highlights the folder name
" --------------
" -- Startify --
" --------------
let g:startify_custom_header =
\ startify#pad(split(system('figlet -f ANSI welcome musa'), '\n'))
"Incase you are insane and want to open a new tab with Goyo enabled
autocmd BufEnter *
\ if !exists('t:startify_new_tab') && empty(expand('%')) && !exists('t:goyo_master') |
\ let t:startify_new_tab = 1 |
\ Startify |
\ endif
"Bookmarks. Syntax is clear.add yours
let g:startify_bookmarks = [ {'I': '~/i3/i3/config'},{'B': '~/.bashrc'},{'V': '~/.vimrc'}]
let g:startify_lists = [
\ { 'type': 'bookmarks' , 'header': [' Bookmarks'] } ,
\ { 'type': 'files' , 'header': [' Recent' ] } ,
\ { 'type': 'sessions' , 'header': [' Sessions' ] } ,
\ { 'type': 'commands' , 'header': [' Commands' ] } ,
\ ]
"cant tell wtf it does so its commented
" \ { 'type': 'dir', 'header': [' MRU '. getcwd()] },
" This allows a custom header color but daycula overrides it and i can't
" figure it out
"hi StartifyHeader guifg=#1f24de guibg=NONE
" ----------------
" Daycula Settings
" ----------------
let g:daycula_enable_italic = 1
" ----------------
" vim-signify Settings
" ----------------
set updatetime=5000
" ----------------
" vim-autoformat Settings
" ----------------
au BufWrite * :Autoformat " BufWritePost allows format to be run on auto-saved files
au FileType groovy,text let b:autoformat_autoindent=0
let g:formatdef_custom_java = '"astyle --style=google --indent=spaces=4 --indent-switches --pad-oper --pad-header --unpad-paren --add-braces --convert-tabs"'
let g:formatters_java = ['custom_java']
let g:formatdef_custom_python = '"autopep8 --in-place --aggressive --aggressive"'
let g:formatters_python = ['custom_python']
" ---------------------------------
" --- Colour and theme settings ---
" ---------------------------------
if &term =~ '256color'
if has('termguicolors') " Enable true (24-bit) colors instead of (8-bit) 256 colors.
let &t_8f = "\<Esc>[38;2;%lu;%lu;%lum"
let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum"
set termguicolors
endif
colorscheme daycula " Change colorscheme here
endif
" --------------------
" --- Vim Settings ---
" --------------------
syntax on
set modifiable " Sets files to be modifiable by deafault
set autoread " Re-reads a file when edits in another editor are detected
set cmdheight=1 " Sets max height of commands when run
set foldenable " Allows folding
set incsearch " When searching, shows strings that match as you are typing
set mouse=a " Enable mouse
set rnu " Relative Line numbers
set smartindent " Indentation
set ignorecase " Case insensitive searching
set smartcase " Will automatically switch to case sensitive if you use any capitals
set cursorline " Highlights line cursor is on
set notimeout " Remove timeout for partially typed commands
set timeoutlen=100
set autoindent " Automatically indent the next line
set background=dark " Use dark a the background colour
set expandtab " Use spaces instead of tabs
set smarttab " Not sure DT uses it
set shiftwidth=4 " One tab == 4 spaces
set tabstop=4 " One tab == 4 spaces
filetype plugin on " Enable loading the plugin files for specific file types
" Make comments italic
highlight Comment cterm=italic
function! FormatOnUpdate()
exe 'Autoformat'
silent update
endfunction
if has("autocmd")
" Jump to last position when reopening a file
au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
" Save writeable files automatically 'updatetime' ms later after the cursor stops moving
au CursorHold,CursorHoldI <buffer> if &readonly == 0 && filereadable(bufname('%')) | call FormatOnUpdate() | endif
endif
" -----------------------
" --- Custom Mappings ---
" -----------------------
nnoremap <SPACE> <Nop>
let mapleader = " "
" Open Nerdtree
nnoremap <silent> <expr> <leader>n g:NERDTree.IsOpen() ? "\:NERDTreeClose<CR>" : bufexists(expand('%')) ? "\:NERDTreeFind<CR>" : "\:NERDTree<CR>"
nnoremap <leader>m :MRU <Cr>
nnoremap <leader>i :Startify <Cr>
" <leader>p runs Prettier
" Toggle spelling errors
nnoremap <leader>sp :setlocal spell! spelllang=en_us<Cr>
hi SpellBad ctermfg=red guifg=red
" Fix spelling errors (if this is active :Files requires a second input char
" to activate )
" nnoremap <leader>fs :normal! 1z=<Cr>
" Open fzf file explorer
noremap <Space>f :Files<Cr>
" Open fzf window explorer and switch to window on enter
noremap <Space>w :Windows<Cr>
" CRTL+A selects all text
map <C-a> <esc>ggVG
" CTRL+C copy selected text to clipboard (only works with gvim install)<CR>
vnoremap <C-c> "+y
" Home and End keys
" map 1 ^
" map 0 $
" Map 'jk' as escape
imap jk <Esc>
imap JK <Esc> :echo "Turn off caps lock!"<CR>
" Using CTRL-e and CTRL-y work to scroll in insert mode
inoremap <C-e> <C-O><C-E>
inoremap <C-y> <C-O><C-Y>
" CTRL-S saves (second one saves in insert mode)
noremap <C-s> :update<CR>
inoremap <C-s> <ESC>:update<CR>
" CTRL-Q saves and quits (second one saves in insert mode)
noremap <C-q> :update<Bar>quit<CR>
inoremap <C-q> <c-o>:update<Bar>quit<CR>
" CTRL-X quits without saving
noremap <C-x> :q!<CR>
inoremap <C-x> <ESC>:q!<CR>
" Moving around in insert mode
" imap pp <right>
" imap qq <left>
" CTRL + L or H jumps one word
imap <C-l> <C-Right>
imap <C-h> <C-left>
" -----------------------
" -- Buffer navigation --
" -----------------------
set splitbelow splitright
map <C-h> <C-w>h
map <C-j> <C-w>j
map <C-k> <C-w>k
map <C-l> <C-w>l
map <C-LEFT> <C-w>h
map <C-DOWN> <C-w>j
map <C-UP> <C-w>k
map <C-RIGHT> <C-w>l
map <s-l> :vertical resize +5 <Cr>
map <s-h> :vertical resize -5 <Cr>
map <s-j> :resize +5 <Cr>
map <s-k> :resize -5 <Cr>
" Tabs (space is needed as using space as leader doesnt raelly work)
nnoremap <Space>t :tabnew<Cr>
nnoremap <Space>l :tabnext<CR>
nnoremap <Space>h :tabprevious<CR>
"Keybindings for tab navigation with leader and number
noremap <leader>1 1gt
noremap <leader>2 2gt
noremap <leader>3 3gt
noremap <leader>4 4gt
noremap <leader>5 5gt
noremap <leader>6 6gt
noremap <leader>7 7gt
noremap <leader>8 8gt
noremap <leader>9 9gt