Last active
March 29, 2024 01:41
-
-
Save ozthekoder/4e3822eaa8be6f27a51d3e22948a7b1f to your computer and use it in GitHub Desktop.
.vimrc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set nocompatible " be iMproved, required | |
call plug#begin('~/.vim/plugged') | |
Plug 'christoomey/vim-tmux-navigator' | |
Plug 'preservim/nerdtree' " NerdTree | |
Plug 'Xuyuanp/nerdtree-git-plugin' " NerdTree git | |
" Plug 'ryanoasis/vim-devicons' " File type icons in NerdTree | |
Plug 'editorconfig/editorconfig-vim' | |
Plug 'morhetz/gruvbox' | |
Plug 'airblade/vim-gitgutter' " Show git diff of lines edited | |
Plug 'tpope/vim-fugitive' " :Gblame | |
Plug 'tpope/vim-rhubarb' " :GBrowse | |
Plug 'tpope/vim-surround' | |
Plug 'tpope/vim-endwise' " Autocomplete end after a do | |
Plug 'gcmt/taboo.vim' " Tab management | |
Plug 'mileszs/ack.vim' " Use ack in Vim | |
Plug 'pangloss/vim-javascript' " JavaScript support | |
Plug 'leafgarland/typescript-vim' " TypeScript syntax | |
Plug 'maxmellon/vim-jsx-pretty' " JS and JSX syntax | |
Plug 'styled-components/vim-styled-components' | |
Plug 'vim-airline/vim-airline' " Vim powerline | |
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } } | |
Plug 'junegunn/fzf.vim' " Set up fzf and fzf.vim | |
Plug 'neoclide/coc.nvim', { 'branch': 'release' } | |
Plug 'psliwka/vim-smoothie' " Smooth scrolling | |
Plug 'rust-lang/rust.vim' | |
Plug 'elzr/vim-json' | |
Plug 'embear/vim-localvimrc' | |
Plug 'prettier/vim-prettier' | |
Plug 'sjl/gundo.vim' | |
Plug 'jeffkreeftmeijer/vim-numbertoggle' | |
Plug 'cespare/vim-toml' | |
Plug 'Exafunction/codeium.vim', { 'branch': 'main' } | |
call plug#end() | |
filetype plugin indent on | |
" Leader key is SPACE, I find it the best | |
let mapleader = " " | |
" Look and Feel settings | |
syntax enable | |
set re=0 | |
set mmp=50000 | |
set background=dark | |
set wildmenu " when opening a file with e.g. :e ~/.vim<TAB> there is a graphical menu of all the matches | |
set ttyfast | |
set lazyredraw | |
set updatetime=300 | |
set hidden " Open other files if current one is not saved | |
colorscheme gruvbox | |
" Enable Mouse mode in all modes | |
set mouse=a | |
" Numbers | |
set number | |
set numberwidth=4 | |
set ruler | |
" paste mode | |
nnoremap <F5> :set invpaste paste?<CR> | |
set pastetoggle=<F5> | |
set showmode | |
" Treat long lines as break lines | |
map j gj | |
map k gk | |
" Indentation | |
set autoindent | |
set cindent | |
set smartindent | |
" Folding | |
" Enable folding | |
set foldmethod=syntax | |
set foldlevel=99 | |
" Enable folding with the z key | |
nmap z za | |
" Disable all bells and whistles | |
set noerrorbells visualbell t_vb= | |
" RustFmt Setup | |
let g:rustfmt_autosave = 1 | |
" Ack tricks | |
let g:ackprg = 'rg --vimgrep --smart-case --hidden' | |
" Any empty ack search will search for the word the cursor is on | |
let g:ack_use_cword_for_empty_search = 1 | |
nmap <leader>a :Ack!<Space> | |
nmap <leader>A :Ack! <cword><CR> | |
" Tab Options | |
set shiftwidth=2 | |
set tabstop=2 | |
set softtabstop=2 " Number of spaces a tab counts when editing | |
set expandtab | |
set scrolloff=3 | |
let g:NERDTreeChDirMode=2 | |
" If another buffer tries to replace NERDTree, put it in the other window, and bring back NERDTree. | |
autocmd BufEnter * if winnr() == winnr('h') && bufname('#') =~ 'NERD_tree_\d\+' && bufname('%') !~ 'NERD_tree_\d\+' && winnr('$') > 1 | | |
\ let buf=bufnr() | buffer# | execute "normal! \<C-W>w" | execute 'buffer'.buf | endif | |
" Delete empty space from the end of lines on every save | |
autocmd BufWritePre * :%s/\s\+$//e | |
" Set default encoding to utf-8 | |
set encoding=utf-8 | |
set termencoding=utf-8 | |
" Disable backups and swap files | |
set nobackup | |
set nowritebackup | |
set noswapfile | |
set ignorecase " Ignore case when searching | |
set smartcase " When searching try to be smart about cases | |
set nohlsearch " Don't highlight search term | |
set incsearch " Jumping search | |
" Joshy split | |
set splitright | |
set splitbelow | |
" Always show the status line | |
set laststatus=2 | |
" Allow copy and paste from system clipboard | |
set clipboard=unnamed | |
" Spellcheck for features and markdown | |
au BufRead,BufNewFile *.md setlocal spell | |
au BufRead,BufNewFile *.md.erb setlocal spell | |
au BufRead,BufNewFile *.feature setlocal spell | |
" Delete characters outside of insert area | |
set backspace=indent,eol,start | |
" +++ Shortcuts +++ | |
" NerdTree keys | |
nnoremap <leader>n :NERDTreeFocus<CR> | |
nnoremap <C-n> :NERDTree<CR> | |
nnoremap <C-t> :NERDTreeToggle<CR> | |
nnoremap <C-f> :NERDTreeFind<CR> | |
" Open Buffer | |
nnoremap <silent><leader>l :Buffers<CR> | |
" Open test file for a current file | |
nnoremap <silent><leader>s :A<CR> | |
" Open test file for a current file in a vertical window | |
nnoremap <silent><leader>v :AV<CR> | |
" Vertically split screen | |
nnoremap <silent><leader>\ :vs<CR> | |
" Split screen | |
nnoremap <silent><leader>/ :split<CR> | |
" Faster saving and exiting | |
nnoremap <silent><leader>w :w!<CR> | |
nnoremap <silent><leader>q :q!<CR> | |
nnoremap <silent><leader>x :x<CR> | |
" Open Vim configuration file for editing | |
nnoremap <silent><leader>2 :e ~/.vimrc<CR> | |
" Source Vim configuration file and install plugins | |
nnoremap <silent><leader>1 :source ~/.vimrc \| :PlugInstall<CR> | |
" Toggle relative line numbers | |
nnoremap <leader>rn :set relativenumber!<cr> | |
" If fzf installed using git | |
set rtp+=~/.fzf | |
" Map fzf search to CTRL P | |
nnoremap <C-p> :GFiles<Cr> | |
" Map fzf + ag search to CTRL P | |
nnoremap <C-g> :Rg <Cr> | |
" vim-test shortcut for running tests | |
nnoremap <silent><leader>; :TestNearest<CR> | |
nnoremap <silent><leader>' :TestFile<CR> | |
" Extra <CR> is for disabling /"Press ENTER or type command to continue/" | |
nnoremap <silent><leader>e :Exp<CR><CR> | |
" Easier movement between split windows CTRL + {h, j, k, l} | |
nnoremap <c-h> <c-w>h | |
nnoremap <c-j> <c-w>j | |
nnoremap <c-k> <c-w>k | |
nnoremap <c-l> <c-w>l | |
" CoC extensions | |
let g:coc_global_extensions = ['coc-solargraph', 'coc-tsserver', 'coc-json'] | |
" Add CoC Prettier if prettier is installed | |
if isdirectory('./node_modules') && isdirectory('./node_modules/prettier') | |
let g:coc_global_extensions += ['coc-prettier'] | |
endif | |
" Add CoC ESLint if ESLint is installed | |
if isdirectory('./node_modules') && isdirectory('./node_modules/eslint') | |
let g:coc_global_extensions += ['coc-eslint'] | |
endif | |
" Use tab for trigger completion with characters ahead and navigate | |
" NOTE: There's always complete item selected by default, you may want to enable | |
" no select by `"suggest.noselect": true` in your configuration file | |
" NOTE: Use command ':verbose imap <tab>' to make sure tab is not mapped by | |
" other plugin before putting this into your config | |
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>" | |
" Make <CR> to accept selected completion item or notify coc.nvim to format | |
" <C-g>u breaks current undo, please make your own choice | |
inoremap <silent><expr> <CR> coc#pum#visible() ? coc#pum#confirm() | |
\: "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>" | |
imap <script><silent><nowait><expr> <c-h> codeium#Accept() | |
function! CheckBackspace() abort | |
let col = col('.') - 1 | |
return !col || getline('.')[col - 1] =~# '\s' | |
endfunction | |
" Use <c-space> to trigger completion | |
if has('nvim') | |
inoremap <silent><expr> <c-space> coc#refresh() | |
else | |
inoremap <silent><expr> <c-@> coc#refresh() | |
endif | |
" Use `[g` and `]g` to navigate diagnostics | |
" Use `:CocDiagnostics` to get all diagnostics of current buffer in location list | |
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) | |
" Use K to show documentation in preview window | |
nnoremap <silent> K :call ShowDocumentation()<CR> | |
function! ShowDocumentation() | |
if CocAction('hasProvider', 'hover') | |
call CocActionAsync('doHover') | |
else | |
call feedkeys('K', 'in') | |
endif | |
endfunction | |
" Highlight the symbol and its references when holding the cursor | |
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) | |
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 | |
" Applying code actions to the selected code block | |
" Example: `<leader>aap` for current paragraph | |
xmap <leader>a <Plug>(coc-codeaction-selected) | |
nmap <leader>a <Plug>(coc-codeaction-selected) | |
" Remap keys for applying code actions at the cursor position | |
nmap <leader>ac <Plug>(coc-codeaction-cursor) | |
" Remap keys for apply code actions affect whole buffer | |
nmap <leader>as <Plug>(coc-codeaction-source) | |
" Apply the most preferred quickfix action to fix diagnostic on the current line | |
nmap <leader>qf <Plug>(coc-fix-current) | |
" Remap keys for applying refactor code actions | |
nmap <silent> <leader>re <Plug>(coc-codeaction-refactor) | |
xmap <silent> <leader>r <Plug>(coc-codeaction-refactor-selected) | |
nmap <silent> <leader>r <Plug>(coc-codeaction-refactor-selected) | |
" Run the Code Lens action on the current line | |
nmap <leader>cl <Plug>(coc-codelens-action) | |
" Map function and class text objects | |
" NOTE: Requires 'textDocument.documentSymbol' support from the language server | |
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) | |
" Remap <C-f> and <C-b> to scroll float windows/popups | |
if has('nvim-0.4.0') || has('patch-8.2.0750') | |
nnoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? coc#float#scroll(1) : "\<C-f>" | |
nnoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? coc#float#scroll(0) : "\<C-b>" | |
inoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? "\<c-r>=coc#float#scroll(1)\<cr>" : "\<Right>" | |
inoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? "\<c-r>=coc#float#scroll(0)\<cr>" : "\<Left>" | |
vnoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? coc#float#scroll(1) : "\<C-f>" | |
vnoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? coc#float#scroll(0) : "\<C-b>" | |
endif | |
" Use CTRL-S for selections ranges | |
" Requires 'textDocument/selectionRange' support of language server | |
nmap <silent> <C-s> <Plug>(coc-range-select) | |
xmap <silent> <C-s> <Plug>(coc-range-select) | |
" Add `:Format` command to format current buffer | |
command! -nargs=0 Format :call CocActionAsync('format') | |
" Add `:Fold` command to fold current buffer | |
command! -nargs=? Fold :call CocAction('fold', <f-args>) | |
" Add `:OR` command for organize imports of the current buffer | |
command! -nargs=0 OR :call CocActionAsync('runCommand', 'editor.action.organizeImport') | |
" Add (Neo)Vim's native statusline support | |
" NOTE: Please see `:h coc-status` for integrations with external plugins that | |
" provide custom statusline: lightline.vim, vim-airline | |
set statusline^=%{coc#status()}%{get(b:,'coc_current_function','')} | |
" Mappings for CoCList | |
" Show all diagnostics | |
nnoremap <silent><nowait> <space>a :<C-u>CocList diagnostics<cr> | |
" Manage extensions | |
nnoremap <silent><nowait> <space>e :<C-u>CocList extensions<cr> | |
" Show commands | |
nnoremap <silent><nowait> <space>c :<C-u>CocList commands<cr> | |
" Find symbol of current document | |
nnoremap <silent><nowait> <space>o :<C-u>CocList outline<cr> | |
" Search workspace symbols | |
nnoremap <silent><nowait> <space>s :<C-u>CocList -I symbols<cr> | |
" Do default action for next item | |
nnoremap <silent><nowait> <space>j :<C-u>CocNext<CR> | |
" Do default action for previous item | |
nnoremap <silent><nowait> <space>k :<C-u>CocPrev<CR> | |
" Resume latest coc list | |
nnoremap <silent><nowait> <space>p :<C-u>CocListResume<CR>" Format | |
nmap <leader>f :CocCommand prettier.formatFile<CR> | |
" Fix some weird error with Fugitive | |
let g:fugitive_pty = 0 | |
" Just show the filename (no path) in the tab | |
let g:airline#extensions#tabline#fnamemod = ':t' | |
let g:codeium_no_map_tab = 1 | |
" Change cursor to solid vertical line | |
" There are problems with Vim's floating window setting cursor to a solid | |
" block. So these lines below are resetting it to a solid vertical line. | |
let &t_SI.="\e[2 q" "SI = INSERT mode | |
let &t_SR.="\e[2 q" "SR = REPLACE mode | |
let &t_EI.="\e[1 q" "EI = NORMAL mode (ELSE) | |
" Fix syntax highlight for Coc plugin floating errors | |
hi CocErrorFloat guifg=Magenta guibg=Magenta | |
" Use templates https://vimtricks.com/p/automated-file-templates/ | |
" autocmd BufNewFile *.test.tsx 0r ~/Documents/dotfiles/skeletons/react-typescript.test.tsx | |
" autocmd BufNewFile *\(test\)\@<!.tsx 0r ~/Documents/dotfiles/skeletons/react-typescript.tsx | |
" autocmd BufNewFile *content/blog*.md 0r ~/Documents/dotfiles/skeletons/blog-post.md | |
" autocmd BufNewFile *.sh 0r ~/Documents/dotfiles/skeletons/script.sh | |
" autocmd BufNewFile *.html 0r ~/Documents/dotfiles/skeletons/page.html |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment