-
-
Save Jswizzy/9596eae2309bd253508b9cc4d25ec4e0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
filetype plugin indent on | |
" Specify a directory for plugins | |
call plug#begin('~/.vim/plugged') | |
Plug 'Yggdroot/indentLine' | |
Plug 'airblade/vim-gitgutter' | |
Plug 'christoomey/vim-sort-motion' | |
Plug 'editorconfig/editorconfig-vim' | |
" Plug 'edkolev/tmuxline.vim' | |
Plug 'elzr/vim-json' | |
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' } | |
Plug 'junegunn/fzf.vim' | |
Plug 'neoclide/coc.nvim', {'do': 'yarn install --frozen-lockfile'} | |
Plug 'othree/javascript-libraries-syntax.vim' | |
Plug 'scrooloose/nerdcommenter' | |
Plug 'christoomey/vim-tmux-navigator' | |
Plug 'sickill/vim-pasta' | |
Plug 'tpope/vim-vinegar' | |
Plug 'tpope/vim-eunuch' | |
Plug 'tpope/vim-surround' | |
Plug 'tpope/vim-repeat' | |
Plug 'mattn/emmet-vim' | |
Plug 'pangloss/vim-javascript' | |
Plug 'leafgarland/typescript-vim' | |
Plug 'peitalin/vim-jsx-typescript' | |
Plug 'styled-components/vim-styled-components', { 'branch': 'main' } | |
Plug 'jparise/vim-graphql' | |
Plug 'vim-airline/vim-airline' | |
Plug 'vim-airline/vim-airline-themes' | |
Plug 'frazrepo/vim-rainbow' | |
Plug 'arcticicestudio/nord-vim' | |
" Initialize plugin system | |
call plug#end() | |
" Theme | |
colorscheme nord | |
" Vim Airline | |
" Top picks: angr, dark, dark_minimal, durant, minimalist, onedark, ravenpower, term | |
let g:airline_theme = 'base16' | |
let g:airline_powerline_fonts=1 | |
let g:airline_skip_empty_sections=0 | |
let g:airline#extensions#coc#enabled = 1 | |
let g:airline_extensions = ['hunks', 'branch'] | |
" Leader key is SPACE, I find it the best | |
let mapleader = " " | |
let g:user_emmet_leader_key=',' | |
" Delete empty space from the end of lines on every save | |
autocmd BufWritePre * :%s/\s\+$//e | |
autocmd BufEnter *.{js,jsx,ts,tsx} :syntax sync fromstart | |
autocmd BufLeave *.{js,jsx,ts,tsx} :syntax sync clear | |
" Tooltips | |
function! ShowDocIfNoDiagnostic(timer_id) | |
if (coc#util#has_float() == 0) | |
silent call CocActionAsync('doHover') | |
endif | |
endfunction | |
function! s:show_hover_doc() | |
call timer_start(500, 'ShowDocIfNoDiagnostic') | |
endfunction | |
autocmd CursorHoldI * :call <SID>show_hover_doc() | |
autocmd CursorHold * :call <SID>show_hover_doc() | |
set noswapfile | |
" 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 +++ | |
" 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 screeni | |
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> | |
" 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 | |
" Remap keys for applying codeAction to the current line. | |
nmap <leader>ac <Plug>(coc-codeaction) | |
" Apply AutoFix to problem on the current line. | |
nmap <leader>qf <Plug>(coc-fix-current) | |
" Show autocomplete when Tab is pressed | |
inoremap <silent><expr> <Tab> coc#refresh()) | |
" rainbow brackets | |
let g:rainbow_active = 1 | |
" Remap ESC keys | |
inoremap jk <ESC> | |
inoremap kj <ESC> | |
inoremap jj <ESC> | |
" Setup netrw for file browsing | |
let g:netrw_banner = 0 | |
let g:netrw_liststyle = 3 | |
nmap <silent> <C-n> :Explore<CR> | |
nmap <silent> <C-N> :Vex<CR> | |
" j/k will move virtual lines (lines that wrap) | |
noremap <silent> <expr> j (v:count == 0 ? 'gj' : 'j') | |
noremap <silent> <expr> k (v:count == 0 ? 'gk' : 'k') | |
" coc config | |
let g:coc_global_extensions = [ | |
\ 'coc-snippets', | |
\ 'coc-pairs', | |
\ 'coc-html', | |
\ 'coc-emmet', | |
\ 'coc-css', | |
\ 'coc-yank', | |
\ 'coc-highlight', | |
\ 'coc-tsserver', | |
\ 'coc-json', | |
\ 'coc-tabnine' | |
\ ] | |
" don't give |ins-completion-menu| messages. | |
set shortmess+=c | |
" always show signcolumns | |
set signcolumn=yes | |
" Use tab for trigger completion with characters ahead and navigate. | |
" Use command ':verbose imap <tab>' to make sure tab is not mapped by other plugin. | |
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. | |
inoremap <silent><expr> <c-space> coc#refresh() | |
" Use <cr> to confirm completion, `<C-g>u` means break undo chain at current position. | |
" Coc only does snippet and additional edit on confirm. | |
inoremap <expr> <cr> pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>" | |
" Use `[g` and `]g` to navigate diagnostics | |
nmap <silent> [g <Plug>(coc-diagnostic-prev) | |
nmap <silent> ]g <Plug>(coc-diagnostic-next) | |
" Use K to 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>') | |
else | |
call CocAction('doHover') | |
endif | |
endfunction | |
" 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>' | |
" Fuzzy Finder | |
nnoremap <C-p> :FZF<CR> | |
let g:fzf_action = { | |
\ 'ctrl-t': 'tab split', | |
\ 'ctrl-s': 'split', | |
\ 'ctrl-v': 'vsplit' | |
\} | |
let $FZF_DEFAULT_COMMAND = 'ag -g ""' | |
" indentLine | |
let g:indentLine_enabled = 1 | |
let g:indentLine_char = '⎸' | |
let g:indentLine_color_term = 236 | |
" Editorconfig | |
let g:EditorConfig_exec_path = '~/.editorconfig' | |
" GitGutter | |
autocmd VimEnter,Colorscheme * :hi GitGutterAdd ctermbg=233 ctermfg=41 guibg=#121212 guifg=#00d75f | |
autocmd VimEnter,Colorscheme * :hi GitGutterChange ctermbg=233 ctermfg=184 guibg=#121212 guifg=#d7d700 | |
autocmd VimEnter,Colorscheme * :hi GitGutterDelete ctermbg=233 ctermfg=167 guibg=#121212 guifg=#d75f5f | |
autocmd VimEnter,Colorscheme * :hi GitGutterChangeDelete ctermbg=233 ctermfg=30 guibg=#121212 guifg=#008787 | |
" DEFAULT SETTINGS {{{ | |
let g:python2_host_prog = '/usr/bin/python' | |
let g:python3_host_prog = '/usr/bin/python3' | |
filetype plugin on " Detect filetype | |
set nocompatible " Use vim features | |
set encoding=utf-8 " Set encoding | |
set history=5000 " Increase command line history | |
set nobackup " Some servers have issues with backup files | |
set nowritebackup | |
set updatetime=300 " You will have bad experience for diagnostic messages when it's default 4000. | |
set hidden " Enables changing buffers without saving | |
set inccommand=split " Live search and replace | |
set autoindent " Copy indent to the new line | |
set wildmenu " Enhance command-line completion | |
set path+=** " Search down into subfolders | |
set tabstop=2 " Make tabs as wide as two spaces | |
set hlsearch " Highlight searches | |
set ignorecase " Ignore case of searches | |
set noswapfile | |
set incsearch " Search as characters are entered | |
set showmatch " Show matching brackets when text indicator is over them | |
set backupcopy=yes " Prevent VIM from renaming files | |
set scrolloff=5 " Offset top and bottom lines | |
set ttyfast | |
set lazyredraw | |
" Searching for slash as normal text | |
command! -nargs=1 Ss let @/ = <q-args>|set hlsearch | |
" No sound errors | |
set noerrorbells | |
set novisualbell | |
set ai " Auto indent | |
set si " Smart indent | |
" Use relative numbers | |
if exists("&relativenumber") | |
set relativenumber | |
au BufReadPost * set relativenumber | |
endif | |
" Pulls completions from current file, other buffers (closed or still open), | |
" and from the current tags file | |
set complete=.,b,u,] | |
" KEY REMAPING {{{ | |
" Edit vimrc file | |
nmap <leader>ev :edit $MYVIMRC<CR> | |
" Source vimrc | |
nnoremap <leader>sv :source $MYVIMRC<CR> | |
" switch between current and last buffer | |
nmap <leader>. <c-^> | |
" Turn off search highlight | |
nnoremap <leader><space> :nohlsearch<CR><CR>:<backspace> | |
" kill all open buffers | |
nnoremap <leader>bd :bufdo bdelete<CR> | |
" Search and replace binding | |
nnoremap <Leader>sr :%s/\<<C-r><C-w>\>/ | |
" Edit file, starting in same directory as current file. | |
nnoremap <Leader>e :edit <C-R>=expand('%:p:h') . '/'<CR> | |
" Space opens/closes folds | |
nnoremap <space> za | |
" Replace ESC key | |
inoremap jk <ESC> | |
" disable Ex mode | |
noremap Q <NOP> | |
" next quicklist result | |
nnoremap ]q :cnext<CR> | |
" previuos quicklist result | |
nnoremap [q :cprev<CR> | |
" Avoid unintentional switches to Ex mode. | |
nmap Q q | |
" Multi-mode mappings (Normal, Visual, Operating-pending modes). | |
noremap Y y$ | |
" Project finder | |
nmap <Leader>a :Ag<CR> | |
" Buffer finder | |
nmap <Leader>b :Buffers<CR> | |
" Files finder | |
nmap <Leader>f :Files<CR> | |
" Snippets finder | |
nmap <Leader>s :Snippets<CR> | |
" gd - go to definition of word under cursor | |
nmap <silent> gd <Plug>(coc-definition) | |
" rename the current word in the cursor | |
nmap <leader>cr <Plug>(coc-rename) | |
" restart when tsserver gets wonky | |
nnoremap <silent> <leader>cR :<C-u>CocRestart<CR> | |
" Fix autofix problem of current line | |
nmap <leader>qf <Plug>(coc-fix-current) | |
" Show all diagnostics | |
nnoremap <silent> <Leader>ld :<C-u>CocList diagnostics<cr> | |
" Find symbol of current document | |
nnoremap <silent> <Leader>ls :<C-u>CocList outline<cr> | |
" Prev diagnostic | |
nmap <silent> <Leader>k <Plug>(coc-diagnostic-prev) | |
" Next diagnostic | |
nmap <silent> <Leader>j <Plug>(coc-diagnostic-next) | |
" Confirm completion. | |
inoremap <expr> <cr> complete_info()["selected"] != "-1" ? "\<C-y>" : "\<C-g>u\<CR>" | |
" Store relative line number jumps in the jumplist if they exceed a threshold. | |
nnoremap <expr> k (v:count > 5 ? "m'" . v:count : '') . 'k' | |
nnoremap <expr> j (v:count > 5 ? "m'" . v:count : '') . 'j' | |
" Repurpose cursor keys for quicklist navigation. | |
nnoremap <silent> <Up> :cprevious<CR> | |
nnoremap <silent> <Down> :cnext<CR> | |
nnoremap <silent> <Left> :cpfile<CR> | |
nnoremap <silent> <Right> :cnfile<CR> | |
" Quick panel navigation | |
nnoremap <C-h> <C-w>h | |
nnoremap <C-j> <C-w>j | |
nnoremap <C-k> <C-w>k | |
nnoremap <C-l> <C-w>l | |
" Store relative line number jumps in the jumplist if they exceed a threshold. | |
nnoremap <expr> k (v:count > 5 ? "m'" . v:count : '') . 'k' | |
nnoremap <expr> j (v:count > 5 ? "m'" . v:count : '') . 'j' | |
" Line navigation ignores line wrap | |
nnoremap j gj | |
nnoremap k gk | |
vnoremap j gj | |
vnoremap k gk | |
" }}} | |
" FOLDING {{{ | |
set foldenable " Enable folding | |
set foldlevelstart=10 " Open most folds by default | |
set foldnestmax=10 " 10 nested fold max | |
set foldmethod=indent " Fold based on indent level | |
" SILVER SEARCHER {{{ | |
if executable('ag') | |
set grepprg=ag\ --nogroup\ --nocolor\ --vimgrep | |
set grepformat^=%f:%l:%c:%m " file:line:column:message | |
endif | |
set expandtab " insert spaces for tabbed content | |
set smarttab " tab respects 'tabstop', 'shiftwidth', and 'softtabstop' | |
set tabstop=2 " the visible width of tabs | |
set softtabstop=2 " edit as if the tabs are 2 characters wide | |
set shiftwidth=2 " number of spaces to use for indent and unindent | |
set shiftround " round indent to a multiple of 'shiftwidth' | |
set completeopt+=longest | |
" Defines indentation for HTML files | |
autocmd FileType html setlocal expandtab shiftwidth=2 softtabstop=2 | |
syntax on " Enable syntax highlight | |
set termguicolors | |
highlight clear SignColumn | |
highlight Normal cterm=bold ctermfg=white ctermbg=NONE guifg=#ffffff guibg=NONE | |
set laststatus=2 " Show status line | |
set showmode " Show what mode you're currently in | |
set showcmd " Show what commands you're typing | |
set modelines=1 " Enable modelines | |
set number " Show line number | |
" display indentation guides | |
set list | |
set showbreak=↪\ | |
set listchars=tab:┊\ ,eol:¬,nbsp:␣,trail:·,extends:»,precedes:«,nbsp:× | |
set title " Show file title in terminal tab | |
set cursorline " Highlight current line | |
set ruler " Show cursor positionF | |
" vim-prettier | |
let g:prettier#quickfix_enabled = 0 | |
let g:prettier#quickfix_auto_focus = 0 | |
" prettier command for coc | |
command! -nargs=0 Prettier :call CocAction('runCommand', 'prettier.formatFile') | |
" run prettier on save | |
let g:prettier#autoformat = 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment