Skip to content

Instantly share code, notes, and snippets.

@juvi21
Last active July 30, 2023 19:55
Show Gist options
  • Save juvi21/1ab8446159ab8e33bd7847c4dc099ce0 to your computer and use it in GitHub Desktop.
Save juvi21/1ab8446159ab8e33bd7847c4dc099ce0 to your computer and use it in GitHub Desktop.
init.vim
call plug#begin()
" UI and Themes
Plug 'drewtempelmeyer/palenight.vim'
Plug 'morhetz/gruvbox'
Plug 'vim-airline/vim-airline'
" Navigation and File Management
Plug 'junegunn/fzf.vim'
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'knubie/vim-kitty-navigator'
Plug 'preservim/tagbar'
Plug 'universal-ctags/ctags'
" Language Support and Syntax Highlighting
Plug 'sheerun/vim-polyglot'
Plug 'wlangstroth/vim-racket'
Plug 'rust-lang/rust.vim'
Plug 'JuliaEditorSupport/julia-vim'
Plug 'Shirk/vim-gas'
" Code Quality and Assistance
Plug 'vim-syntastic/syntastic'
Plug 'dense-analysis/ale'
Plug 'neoclide/coc.nvim', { 'branch': 'release' }
Plug 'github/copilot.vim'
" Editing Helpers
Plug 'tpope/vim-surround'
Plug 'tommcdo/vim-lion'
Plug 'ntpeters/vim-better-whitespace'
Plug 'luochen1990/rainbow'
Plug 'jiangmiao/auto-pairs'
" CP
Plug 'sirver/ultisnips'
Plug 'searleser97/cpbooster.vim'
call plug#end()
" ===========================
" Basic Editor Configurations
" ===========================
set background=light
set termguicolors
set encoding=utf-8
set number
set ruler
set visualbell
set wrap
syntax on
" UI Customizations
colorscheme gruvbox
let g:gruvbox_contrast_light='hard'
set laststatus=2
set hlsearch
set incsearch
set cmdheight=1
set shortmess+=c
set signcolumn=yes
set mouse=a
" Behavior Tweaks
set autoindent
set smartindent
set nobackup
set nowritebackup
set updatetime=300
" ===========================
" Custom Functions
" ===========================
" Function to set tab width to n spaces
function! SetTab(n)
let &l:tabstop=a:n
let &l:softtabstop=a:n
let &l:shiftwidth=a:n
set expandtab
endfunction
command! -nargs=1 SetTab call SetTab(<f-args>)
" Function to trim extra whitespace in whole file
function! Trim()
let l:save = winsaveview()
keeppatterns %s/\s\+$//e
call winrestview(l:save)
endfun
command! -nargs=0 Trim call Trim()
" ===========================
" Key Mappings
" ===========================
nnoremap <c-z> <nop>
nnoremap <silent> <C-f> :Files<CR>
nnoremap <C-\><C-t> :tabnew<CR>
nnoremap <C-\><C-s> :split<CR>
nnoremap <C-w>c :close<CR>
nnoremap <C-\><C-v> :vsplit<CR>
nnoremap <silent> <C-l> :Files<CR>
nmap <F8> :TagbarToggle<CR>
" ===========================
" Lang conf
" ===========================
" SQL++ == SQL
augroup sqlpp_ft
au!
autocmd BufNewFile,BufRead *.sqlp set syntax=sql
augroup END
" .S == gas
augroup gas_ft
au!
autocmd BufNewFile,BufRead *.S set syntax=gas
augroup END
" JFlex syntax highlighting
augroup jfft
au BufRead,BufNewFile *.flex,*.jflex set filetype=jflex
augroup END
au Syntax jflex so ~/.vim/syntax/jflex.vim
" ===========================
" Plug conf
" ===========================
" ALE Configuration
let g:ale_enabled = 1
" CoPilot Configuration
autocmd VimEnter * Copilot disable
" fzf Configuration
let g:fzf_layout = { 'window': { 'width': 0.9, 'height': 0.9 } }
let $FZF_DEFAULT_OPTS="--ansi --preview-window 'right:60%' --layout reverse --margin=1,4 --preview 'bat --color=always --style=header,grid --line-range :300 {}'"
" CTags Configuration
let g:Tlist_Ctags_Cmd='/usr/local/Cellar/ctags/5.8_1/bin/ctags'
" ===========================
" CoC Conf
" ===========================
" Use tab for trigger completion with characters ahead and navigate.
inoremap <silent><expr> <TAB>
\ pumvisible() ? "\<C-n>" :
\ <SID>check_back_space() ? "\<TAB>" :
\ coc#refresh()
inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"
function! s:check_back_space() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~# '\s'
endfunction
" Use <c-space> to trigger completion.
" Make <CR> auto-select the first completion item and notify coc.nvim to
" format on enter. (This section is commented out, so it's not active.)
"inoremap <silent><expr> <cr> pumvisible() ? coc#_select_confirm()
" Navigate diagnostics
nmap <silent> [g <Plug>(coc-diagnostic-prev)
nmap <silent> ]g <Plug>(coc-diagnostic-next)
" 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)
" Show documentation in preview window
nnoremap <silent> K :call <SID>show_documentation()<CR>
function! s:show_documentation()
if (index(['vim','help'], &filetype) >= 0)
execute 'h '.expand('<cword>')
elseif (coc#rpc#ready())
call CocActionAsync('doHover')
else
execute '!' . &keywordprg . " " . expand('<cword>')
endif
endfunction
" Highlight symbol and its references on cursor hold
autocmd CursorHold * silent call CocActionAsync('highlight')
" Symbol renaming
nmap <leader>rn <Plug>(coc-rename)
" Formatting selected code
xmap <leader>f <Plug>(coc-format-selected)
nmap <leader>f <Plug>(coc-format-selected)
" Applying codeAction to selected region and buffer
xmap <leader>a <Plug>(coc-codeaction-selected)
nmap <leader>a <Plug>(coc-codeaction-selected)
nmap <leader>ac <Plug>(coc-codeaction)
nmap <leader>qf <Plug>(coc-fix-current)
" Text objects for functions and classes
xmap if <Plug>(coc-funcobj-i)
omap if <Plug>(coc-funcobj-i)
xmap af <Plug>(coc-funcobj-a)
omap af <Plug>(coc-funcobj-a)
xmap ic <Plug>(coc-classobj-i)
omap ic <Plug>(coc-classobj-i)
xmap ac <Plug>(coc-classobj-a)
omap ac <Plug>(coc-classobj-a)
" Use CTRL-S for selections ranges
nmap <silent> <C-s> <Plug>(coc-range-select)
xmap <silent> <C-s> <Plug>(coc-range-select)
" Custom commands for coc functionalities
command! -nargs=0 Format :call CocAction('format')
command! -nargs=? Fold :call CocAction('fold', <f-args>)
command! -nargs=0 OR :call CocAction('runCommand', 'editor.action.organizeImport')
" Add native statusline support and CoCList mappings
set statusline^=%{coc#status()}%{get(b:,'coc_current_function','')}
nnoremap <silent><nowait> <space>a :<C-u>CocList diagnostics<cr>
nnoremap <silent><nowait> <space>e :<C-u>CocList extensions<cr>
nnoremap <silent><nowait> <space>c :<C-u>CocList commands<cr>
nnoremap <silent><nowait> <space>o :<C-u>CocList outline<cr>
nnoremap <silent><nowait> <space>s :<C-u>CocList -I symbols<cr>
nnoremap <silent><nowait> <space>j :<C-u>CocNext<CR>
nnoremap <silent><nowait> <space>k :<C-u>CocPrev<CR>
nnoremap <silent><nowait> <space>p :<C-u>CocListResume<CR>
" ===========================
" Ultisnips
" ===========================
let g:UltiSnipsExpandTrigger = '<tab>'
let g:UltiSnipsJumpForwardTrigger = '<tab>'
let g:UltiSnipsJumpBackwardTrigger = '<s-tab>'
let g:UltiSnipsJumpForwardTrigger="<c-b>"
let g:UltiSnipsJumpBackwardTrigger="<c-z>"
let g:UltiSnipsEditSplit="vertical"
" ===========================
" Lightline conf
" ===========================
autocmd User CocStatusChange,CocDiagnosticChange call lightline#update()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment