-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.vim
More file actions
575 lines (441 loc) · 13.8 KB
/
config.vim
File metadata and controls
575 lines (441 loc) · 13.8 KB
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
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"
" ██╗ ██╗██╗███╗ ███╗██████╗ ██████╗
" ██║ ██║██║████╗ ████║██╔══██╗██╔════╝
" ██║ ██║██║██╔████╔██║██████╔╝██║
" ╚██╗ ██╔╝██║██║╚██╔╝██║██╔══██╗██║
" ╚████╔╝ ██║██║ ╚═╝ ██║██║ ██║╚██████╗
" ╚═══╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝ ╚═════╝
"
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" BASIC SETTINGS --------------------------------------------------------- {{{
" Disable compatibility with vi which can cause unexpected issues.
set nocompatible
" Enable syntax highlighting
syntax on
" Set file format and encoding
set fileformat=unix
set encoding=UTF-8
" Ensure files are modifiable by default
set modifiable
" Enable type file detection. Vim will be able to try to detect the type of file is use.
filetype on
" Enable plugins and load plugin for the detected file type.
filetype plugin on
" Load an indent file for the detected file type.
filetype indent on
" Enable 24-bit color support if available
if has('termguicolors')
set termguicolors
endif
" Improve performance
set lazyredraw
set ttyfast
" }}}
" DISPLAY SETTINGS ------------------------------------------------------- {{{
" Show line numbers
set number
set relativenumber
" Highlight current line
set cursorline
" Keep cursor away from edges when scrolling
set scrolloff=8
set sidescrolloff=8
" Always show sign column to prevent text shifting
set signcolumn=yes
" Show command in bottom bar
set showcmd
" Hide current mode
set noshowmode
" Show visual feedback for matching brackets
set showmatch
" Conceal level for certain syntax elements
set conceallevel=1
" Shorten messages to avoid 'press a key' prompts
set shortmess+=c
" Enable smooth scrolling
set smoothscroll
" Break lines at word boundaries
set linebreak
" Show ruler
set ruler
" Enable folding
set foldenable
set foldlevelstart=10
set foldnestmax=10
set foldmethod=indent
" }}}
" INDENTATION AND FORMATTING --------------------------------------------- {{{
" Set tab width to 4 spaces
set tabstop=4
set softtabstop=4
set shiftwidth=4
" Use spaces instead of tabs
set expandtab
" Enable automatic indentation
set autoindent
set smartindent
set smarttab
" Disable line wrapping
set nowrap
" Show invisible characters
set list
set listchars=eol:¬,tab:▸\ ,trail:~,extends:>,precedes:<,space:·
" Set text width for automatic wrapping
set textwidth=79
" Control automatic comment formatting
set formatoptions-=cro
" Enable backspace over everything in insert mode
set backspace=indent,eol,start
" }}}
" SEARCH SETTINGS -------------------------------------------------------- {{{
" Case-insensitive searching unless uppercase letters are used
set ignorecase
set smartcase
" Highlight search results
set hlsearch
" Show search matches as you type
set incsearch
" Clear search highlighting with Enter key
nnoremap <CR> :noh<CR><CR>:<backspace>
" Use magic mode for regex searches
set magic
" }}}
" BEHAVIOR SETTINGS ------------------------------------------------------ {{{
" Enable mouse support in all modes
" set mouse=a
" Disable error bells and use visual bell
set noerrorbells visualbell t_vb=
" Set undo reload limit and enable persistent undo
set undoreload=10000
if has('persistent_undo')
set undofile
set undodir=~/.vim/undo
" Create undo directory if it doesn't exist
if !isdirectory(&undodir)
call mkdir(&undodir, 'p')
endif
endif
" Use system clipboard
set clipboard=unnamed
" Increase command history
set history=1000
" Better backup and swap file handling
set backup
set backupdir=~/.vim/backup
set directory=~/.vim/swap
" Create backup and swap directories if they don't exist
if !isdirectory(&backupdir)
call mkdir(&backupdir, 'p')
endif
if !isdirectory(&directory)
call mkdir(&directory, 'p')
endif
" Automatically reload files changed outside of vim
set autoread
" Hide buffers instead of closing them
set hidden
" Don't redraw during macros (performance)
set lazyredraw
" Timeout settings
set timeoutlen=500
set ttimeoutlen=50
" }}}
" COMPLETION SETTINGS ---------------------------------------------------- {{{
" Enable command-line completion
set wildmenu
" Set completion mode
set wildmode=list:longest,full
" Ignore certain file types in completion
set wildignore=*.docx,*.jpg,*.png,*.gif,*.pdf,*.pyc,*.exe,*.flv,*.img,*.xlsx
set wildignore+=*.o,*.obj,*.class,*.swp,*.DS_Store
" Better insert mode completion
set completeopt=menuone,noselect,preview
" }}}
" MAPPINGS --------------------------------------------------------------- {{{
" Set the , as the leader key.
let mapleader = ","
" Press ,, to jump back to the last cursor position.
nnoremap <leader>, ``
" Press ,p to print the current file to the default printer from a Linux operating system.
nnoremap <silent> <leader>p :%w !lp<CR>
" Type jj to exit insert mode quickly.
inoremap jj <Esc>
" Press the space bar to type the : character in command mode.
nnoremap <space> :
" Pressing the letter o will open a new line below the current one.
nnoremap o o<esc>
nnoremap O O<esc>
" Center the cursor vertically when moving to the next word during a search.
nnoremap n nzz
nnoremap N Nzz
" Yank from cursor to the end of line.
nnoremap Y y$
" Better movement on wrapped lines
nnoremap j gj
nnoremap k gk
" Quick save and quit
nnoremap <leader>w :w<CR>
nnoremap <leader>q :q<CR>
nnoremap <leader>x :x<CR>
" Toggle line numbers
nnoremap <leader>n :set number!<CR>
" Toggle relative line numbers
nnoremap <leader>r :set relativenumber!<CR>
" Toggle paste mode
nnoremap <leader>pp :set paste!<CR>
" Open file explorer
nnoremap <leader>e :Explore<CR>
" Buffer navigation
nnoremap <leader>bn :bnext<CR>
nnoremap <leader>bp :bprev<CR>
nnoremap <leader>bd :bdelete<CR>
" Map the F5 key to run a Python script inside Vim.
nnoremap <f5> :w <CR>:!clear <CR>:!python3 % <CR>
" F6 for running current file based on filetype
nnoremap <F6> :call RunCurrentFile()<CR>
" You can split the window in Vim by typing :split or :vsplit.
nnoremap <c-j> <c-w>j
nnoremap <c-k> <c-w>k
nnoremap <c-h> <c-w>h
nnoremap <c-l> <c-w>l
" Resize split windows using arrow keys
noremap <c-up> <c-w>+
noremap <c-down> <c-w>-
noremap <c-left> <c-w>>
noremap <c-right> <c-w><
" Better split creation
nnoremap <leader>v :vsplit<CR>
nnoremap <leader>s :split<CR>
" Folding shortcuts
nnoremap <leader>f za
nnoremap <leader>F zA
" }}}
" FUNCTIONS -------------------------------------------------------------- {{{
" Function to run current file based on filetype
function! RunCurrentFile()
let l:filetype = &filetype
if l:filetype == 'python'
execute '!python3 %'
elseif l:filetype == 'javascript'
execute '!node %'
elseif l:filetype == 'sh'
execute '!bash %'
elseif l:filetype == 'ruby'
execute '!ruby %'
elseif l:filetype == 'perl'
execute '!perl %'
else
echo "No run command defined for filetype: " . l:filetype
endif
endfunction
" Function to toggle between dark and light backgrounds
function! ToggleBackground()
if &background == 'dark'
set background=light
else
set background=dark
endif
endfunction
nnoremap <leader>bg :call ToggleBackground()<CR>
" }}}
" VIMSCRIPT -------------------------------------------------------------- {{{
" Enable the marker method of folding.
augroup filetype_vim
autocmd!
autocmd FileType vim setlocal foldmethod=marker
autocmd FileType vim setlocal foldlevel=0
autocmd BufRead *.vim setlocal foldmethod=marker
autocmd BufRead *.vim setlocal foldlevel=0
augroup END
" If the current file type is HTML, set indentation to 2 spaces.
autocmd Filetype html setlocal tabstop=2 shiftwidth=2 expandtab
" JavaScript and JSON files
autocmd Filetype javascript,json setlocal tabstop=2 shiftwidth=2 expandtab
" YAML files
autocmd Filetype yaml setlocal tabstop=2 shiftwidth=2 expandtab
" Markdown files
autocmd Filetype markdown setlocal wrap linebreak textwidth=80
" Python files
autocmd Filetype python setlocal textwidth=88
" You can split a window into sections by typing `:split` or `:vsplit`.
augroup cursor_off
autocmd!
autocmd WinLeave * set nocursorline nocursorcolumn
autocmd WinEnter * set cursorline cursorcolumn
augroup END
" Auto-create directories when saving files
augroup auto_mkdir
autocmd!
autocmd BufWritePre * call mkdir(expand('<afile>:p:h'), 'p')
augroup END
" Restore cursor position when opening files
augroup restore_cursor
autocmd!
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal! g`\"" |
\ endif
augroup END
" Remove trailing whitespace on save
augroup trailing_whitespace
autocmd!
autocmd BufWritePre * :%s/\s\+$//e
augroup END
" }}}
" STATUS LINE ------------------------------------------------------------ {{{
" Clear status line when vimrc is reloaded.
set statusline=
" Status line left side.
set statusline+=\ %{Mode()}\ %F\ %M\ %Y\ %R
" Show git branch if available
if executable('git')
set statusline+=\ [%{GitBranch()}]
endif
" Use a divider to separate the left side from the right side.
set statusline+=%=
" Show file size
set statusline+=\ %{FileSize()}
" Status line right side.
set statusline+=\ ascii:\ %b\ hex:\ 0x%B\ row:\ %l\ col:\ %c\ percent:\ %p%%
" Show the status on the second to last line.
set laststatus=2
" Function to display current mode
function! Mode()
let l:mode = mode()
if l:mode == 'n'
return 'NORMAL'
elseif l:mode == 'i'
return 'INSERT'
elseif l:mode == 'v'
return 'VISUAL'
elseif l:mode == 'V'
return 'V-LINE'
elseif l:mode == "\<C-V>"
return 'V-BLOCK'
elseif l:mode == 'R'
return 'REPLACE'
elseif l:mode == 'c'
return 'COMMAND'
elseif l:mode == 't'
return 'TERMINAL'
else
return l:mode
endif
endfunction
" Function to show file size
function! FileSize()
let bytes = getfsize(expand('%:p'))
if bytes <= 0
return '0B'
endif
if bytes < 1024
return bytes . 'B'
elseif bytes < 1048576
return (bytes / 1024) . 'KB'
else
return (bytes / 1048576) . 'MB'
endif
endfunction
" Function to get git branch (improved to handle escape sequences)
function! GitBranch()
if !executable('git')
return ''
endif
let l:git_dir = finddir('.git', expand('%:p:h').';')
if empty(l:git_dir)
return ''
endif
try
let l:branch = system('git -C ' . shellescape(expand('%:p:h')) . ' rev-parse --abbrev-ref HEAD 2>/dev/null')
let l:branch = substitute(l:branch, '\n\+$', '', '')
let l:branch = substitute(l:branch, '[^a-zA-Z0-9/_-]', '', 'g')
if v:shell_error == 0 && !empty(l:branch) && l:branch != 'HEAD'
return l:branch
endif
catch
return ''
endtry
return ''
endfunction
" }}}
" THEME AND COLORS ------------------------------------------------------- {{{
" Set color scheme (adjust based on your preference)
if has('gui_running') || &t_Co >= 256
" Enable 256 colors
set t_Co=256
" Try to set a nice colorscheme
silent! colorscheme gruvbox
endif
" Highlight extra whitespace
highlight ExtraWhitespace ctermbg=red guibg=red
match ExtraWhitespace /\s\+$/
" Better popup menu colors
highlight Pmenu ctermbg=238 ctermfg=white
highlight PmenuSel ctermbg=blue ctermfg=white
" }}}
" AUTOCLOSE ------------------------------------------------------- {{{
" Basic autoclose - insert matching pair and position cursor inside
inoremap ' ''<left>
inoremap ` ``<left>
inoremap " ""<left>
inoremap ( ()<left>
inoremap [ []<left>
inoremap { {}<left>
" Autoclose with semicolon - insert pair with semicolon and position cursor inside
inoremap '; '';<left><left>
inoremap `; ``;<left><left>
inoremap "; "";<left><left>
inoremap (; ();<left><left>
inoremap [; [];<left><left>
inoremap {; {};<left><left>
" Autoclose with comma - insert pair with comma and position cursor inside
inoremap ', '',<left><left>
inoremap `, ``,<left><left>
inoremap ", "",<left><left>
inoremap (, (),<left><left>
inoremap [, [],<left><left>
inoremap {, {},<left><left>
" Autoclose with tab - insert pair and position cursor after closing character
inoremap '<tab> ''
inoremap `<tab> ``
inoremap "<tab> ""
inoremap (<tab> ()
inoremap [<tab> []
inoremap {<tab> {}
" Autoclose with semicolon and tab - insert pair with semicolon and position cursor after
inoremap ';<tab> '';
inoremap `;<tab> ``;
inoremap ";<tab> "";
inoremap (;<tab> ();
inoremap [;<tab> [];
inoremap {;<tab> {};
" Autoclose with comma and tab - insert pair with comma and position cursor after
inoremap ',<tab> '',
inoremap `,<tab> ``,
inoremap ",<tab> "",
inoremap (,<tab> (),
inoremap [,<tab> [],
inoremap {,<tab> {},
" Autoclose with Enter - create multi-line structure and position cursor in middle
inoremap '<CR> '<CR>'<ESC>O
inoremap `<CR> `<CR>`<ESC>O
inoremap "<CR> "<CR>"<ESC>O
inoremap (<CR> (<CR>)<ESC>O
inoremap [<CR> [<CR>]<ESC>O
inoremap {<CR> {<CR>}<ESC>O
" Autoclose with semicolon and Enter - create multi-line with semicolon
inoremap ';<CR> '<CR>';<ESC>O
inoremap `;<CR> `<CR>`;<ESC>O
inoremap ";<CR> "<CR>";<ESC>O
inoremap (;<CR> (<CR>);<ESC>O
inoremap [;<CR> [<CR>];<ESC>O
inoremap {;<CR> {<CR>};<ESC>O
" Autoclose with comma and Enter - create multi-line with comma
inoremap ',<CR> '<CR>',<ESC>O
inoremap `,<CR> `<CR>`,<ESC>O
inoremap ",<CR> "<CR>",<ESC>O
inoremap (,<CR> (<CR>),<ESC>O
inoremap [,<CR> [<CR>],<ESC>O
inoremap {,<CR> {<CR>},<ESC>O
" }}}