Created
April 26, 2021 02:41
-
-
Save ngnmtl/756c68307f7639277c2ce67e61c30a6b to your computer and use it in GitHub Desktop.
.vimrc
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
set nocompatible " be iMproved, required | |
filetype off " required | |
set rtp+=~/.vim/bundle/Vundle.vim | |
call vundle#begin() | |
Plugin 'VundleVim/Vundle.vim' | |
" plugin on GitHub repo | |
Plugin 'mhinz/vim-startify' | |
Plugin 'dense-analysis/ale' | |
Plugin 'neoclide/coc.nvim', {'branch': 'release'} | |
Plugin 'scrooloose/nerdtree.git' | |
Plugin 'jistr/vim-nerdtree-tabs' | |
Plugin 'scrooloose/nerdcommenter' | |
Plugin 'vim-airline/vim-airline' | |
Plugin 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --bin' } | |
Plugin 'junegunn/fzf.vim' | |
Plugin 'benmills/vimux' | |
Plugin 'tpope/vim-fugitive' | |
Plugin 'airblade/vim-gitgutter' | |
Plugin 'tpope/vim-commentary' | |
Plugin 'valloric/matchtagalways' | |
Plugin 'alvan/vim-closetag' | |
Plugin 'pangloss/vim-javascript' | |
Plugin 'posva/vim-vue' | |
Plugin 'othree/html5.vim' | |
Plugin 'hail2u/vim-css3-syntax', { 'for': 'css' } | |
Plugin 'cakebaker/scss-syntax.vim' | |
Plugin 'jelera/vim-javascript-syntax' | |
Plugin 'ekalinin/Dockerfile.vim', {'for' : 'Dockerfile'} | |
Plugin 'cespare/vim-toml' | |
Plugin 'mxw/vim-jsx' | |
Plugin 'elzr/vim-json' | |
Plugin 'tpope/vim-surround' | |
Plugin 'sheerun/vim-polyglot' | |
Plugin 'plasticboy/vim-markdown' | |
Plugin 'majutsushi/tagbar' | |
Plugin 'mattn/emmet-vim' | |
Plugin 'severin-lemaignan/vim-minimap' | |
Plugin 'tomasr/molokai' | |
Plugin 'morhetz/gruvbox' | |
let g:jsx_ext_required = 0 | |
" Snippets: | |
Plugin 'MarcWeber/vim-addon-mw-utils' | |
Plugin 'tomtom/tlib_vim' | |
Plugin 'garbas/vim-snipmate' | |
Plugin 'honza/vim-snippets' | |
call vundle#end() " required | |
filetype plugin indent on " required | |
filetype indent on | |
syntax enable | |
syntax on | |
" ---- CUSTOM SETTINGS ------- | |
let mapleader=',' | |
"" Encoding | |
set encoding=utf-8 | |
set fileencoding=utf-8 | |
set fileencodings=utf-8 | |
set ttyfast | |
set nu! | |
set rnu! | |
set wrap! | |
set number | |
set showcmd | |
set cursorline | |
set wildmenu | |
set wildchar=<Tab> | |
set wildmode=list:longest,full | |
set showmatch | |
set hlsearch | |
set incsearch | |
set lazyredraw | |
set mouse=a | |
set laststatus=2 | |
set noswapfile | |
set backspace=2 | |
set ruler | |
set tabstop=2 | |
set shiftwidth=2 | |
set laststatus=2 | |
set autoread | |
set autoindent | |
set backspace=indent,eol,start | |
set noerrorbells | |
set nobackup | |
set splitright | |
set splitbelow | |
set autowrite | |
set fileformats=unix,dos,mac | |
set noshowmatch | |
set noshowmode | |
set ignorecase | |
set smartcase | |
set completeopt=menu,menuone | |
set nocursorcolumn | |
set nocursorline | |
set updatetime=300 | |
set pumheight=10 | |
set conceallevel=2 | |
set shortmess+=c | |
set belloff+=ctrlg | |
set clipboard^=unnamed | |
set clipboard^=unnamedplus | |
set maxmempattern=20000 | |
" ~/.viminfo needs to be writable and readable. Set oldfiles to 1000 last | |
" recently opened files, :FzfHistory uses it | |
set viminfo='1000 | |
" for vim 8 | |
if (has("termguicolors")) | |
set termguicolors | |
endif | |
" colorscheme | |
set t_Co=256 | |
set background=dark | |
"let g:rehash256 = 1 | |
colorscheme gruvbox | |
"colorscheme molokai | |
"let g:molokai_original = 1 | |
set guifont=Source\ Code\ Pro\ 12 | |
" Time out on key codes but not mappings. | |
" Basically this makes terminal Vim work sanely. | |
if !has('gui_running') | |
set notimeout | |
set ttimeout | |
set ttimeoutlen=10 | |
augroup FastEscape | |
autocmd! | |
au InsertEnter * set timeoutlen=0 | |
au InsertLeave * set timeoutlen=1000 | |
augroup END | |
endif | |
" Visual Mode */# from Scrooloose {{{ | |
function! s:VSetSearch() | |
let temp = @@ | |
norm! gvy | |
let @/ = '\V' . substitute(escape(@@, '\'), '\n', '\\n', 'g') | |
let @@ = temp | |
endfunction | |
"" Enable hidden buffers | |
set hidden | |
" set paste | |
set tabstop=2 softtabstop=2 shiftwidth=2 expandtab | |
autocmd BufWritePre *.js %s/\s\+$//e | |
"" Tabs | |
nnoremap <Tab> :bnext<CR> | |
nnoremap <S-Tab> gt | |
nnoremap <silent> <S-n> :tabnew<CR> | |
"" Split | |
noremap <Leader>h :<C-u>split<CR> | |
noremap <Leader>v :<C-u>vsplit<CR> | |
"" open-browser | |
let g:netrw_nogx = 1 " disable netrw's gx mapping. | |
nmap gx <Plug>(openbrowser-smart-search) | |
vmap gx <Plug>(openbrowser-smart-search) | |
"" Airline | |
let g:airline#extensions#tabline#enabled = 1 | |
let g:airline#extensions#tabline#left_sep = ' ' | |
let g:airline#extensions#tabline#left_alt_sep = '|' | |
"" emmet | |
let g:user_emmet_install_global = 0 | |
autocmd FileType html,css EmmetInstall | |
" vim-javascript | |
augroup vimrc-javascript | |
autocmd! | |
autocmd FileType javascript setl tabstop=4|setl shiftwidth=4|setl expandtab softtabstop=4 | |
augroup END | |
" When editing a file, always jump to the last cursor position | |
autocmd BufReadPost * | |
\ if ! exists("g:leave_my_cursor_position_alone") | | |
\ if line("'\"") > 0 && line ("'\"") <= line("$") | | |
\ exe "normal g'\"" | | |
\ endif | | |
\ endif | |
" GitGutter | |
if exists('&signcolumn') " Vim 7.4.2201 | |
set signcolumn=yes | |
else | |
let g:gitgutter_sign_column_always = 1 | |
endif | |
let g:gitgutter_highlight_lines = 1 | |
set updatetime=100 " default is 4000 | |
" Jump between hunks | |
nmap <Leader>gn <Plug>GitGutterNextHunk " git next | |
nmap <Leader>gp <Plug>GitGutterPrevHunk " git previous | |
" Hunk-add and hunk-revert for chunk staging | |
nmap <Leader>ga <Plug>GitGutterStageHunk " git add (chunk) | |
nmap <Leader>gu <Plug>GitGutterUndoHunk " git undo (chunk) | |
" Use fontawesome icons as signs | |
let g:gitgutter_sign_added = '+' | |
let g:gitgutter_sign_modified = '>' | |
let g:gitgutter_sign_removed = '-' | |
let g:gitgutter_sign_removed_first_line = '^' | |
let g:gitgutter_sign_modified_removed = '<' | |
"" NERDTree | |
let NERDTreeIgnore=['\.pyc', '\~$', '\.swo$', '\.swp$', '\.git', '\.hg', '\.svn', '\.bzr'] | |
let g:NERDTreeWinSize=25 | |
let NERDTreeShowHidden=1 | |
let NERDTreeKeepTreeInNewTab=1 | |
let g:NERDTreeIndicatorMapCustom = { | |
\ "Modified" : "✹", | |
\ "Staged" : "✚", | |
\ "Untracked" : "✭", | |
\ "Renamed" : "➜", | |
\ "Unmerged" : "═", | |
\ "Deleted" : "✖", | |
\ "Dirty" : "✗", | |
\ "Clean" : "✔︎", | |
\ "Unknown" : "?" | |
\ } | |
cd /mnt/DATA/htdocs/ | |
map <F2> :NERDTreeToggle<CR> | |
" open Nerd Tree in folder of file in active buffer | |
map <Leader>nt :NERDTree %:p:h<CR> | |
map <F5> :TagbarToggle <CR> | |
function! StartUp() | |
if !argc() && !exists("s:std_in") | |
NERDTree | |
end | |
if argc() && isdirectory(argv()[0]) && !exists("s:std_in") | |
exe 'NERDTree' argv()[0] | |
wincmd p | |
ene | |
end | |
endfunction | |
" Edit Vim config file in a new tab. | |
map <Leader>ev :tabnew ~/.vimrc<CR> | |
"startify | |
let g:startify_custom_header = | |
\ map(split(system('fortune ~/.vim/fortunes | cowsay -W 60'), '\n'), '" ". v:val') + ['',''] | |
let g:ale_sign_error = '>>' | |
let g:ale_sign_warning = '--' | |
let g:ale_linters = { | |
\ 'python': ['flake8', 'pylint'], | |
\ 'javascript': ['eslint'], | |
\ 'vue': ['eslint'] | |
\} | |
let g:ale_fixers = { | |
\ 'javascript': ['eslint'], | |
\ 'vue': ['eslint'], | |
\ 'scss': ['prettier'] | |
\} | |
let g:ale_fix_on_save = 1 | |
" ==================== vim-go ==================== | |
let g:go_fmt_fail_silently = 1 | |
let g:go_debug_windows = { | |
\ 'vars': 'leftabove 35vnew', | |
\ 'stack': 'botright 10new', | |
\ } | |
let g:go_test_show_name = 1 | |
let g:go_list_type = "quickfix" | |
let g:go_autodetect_gopath = 1 | |
let g:go_metalinter_autosave_enabled = ['vet', 'golint'] | |
let g:go_metalinter_enabled = ['vet', 'golint'] | |
let g:go_gopls_complete_unimported = 1 | |
" 2 is for errors and warnings | |
let g:go_diagnostics_level = 2 | |
let g:go_doc_popup_window = 1 | |
let g:go_imports_mode="gopls" | |
let g:go_imports_autosave=1 | |
let g:go_highlight_build_constraints = 1 | |
let g:go_highlight_operators = 1 | |
let g:go_fold_enable = [] | |
nmap <C-g> :GoDecls<cr> | |
imap <C-g> <esc>:<C-u>GoDecls<cr> | |
" run :GoBuild or :GoTestCompile based on the go file | |
function! s:build_go_files() | |
let l:file = expand('%') | |
if l:file =~# '^\f\+_test\.go$' | |
call go#test#Test(0, 1) | |
elseif l:file =~# '^\f\+\.go$' | |
call go#cmd#Build(0) | |
endif | |
endfunction | |
augroup go | |
autocmd! | |
autocmd FileType go nmap <silent> <Leader>v <Plug>(go-def-vertical) | |
autocmd FileType go nmap <silent> <Leader>s <Plug>(go-def-split) | |
autocmd FileType go nmap <silent> <Leader>d <Plug>(go-def-tab) | |
autocmd FileType go nmap <silent> <Leader>x <Plug>(go-doc-vertical) | |
autocmd FileType go nmap <silent> <Leader>i <Plug>(go-info) | |
autocmd FileType go nmap <silent> <Leader>l <Plug>(go-metalinter) | |
autocmd FileType go nmap <silent> <leader>b :<C-u>call <SID>build_go_files()<CR> | |
autocmd FileType go nmap <silent> <leader>t <Plug>(go-test) | |
autocmd FileType go nmap <silent> <leader>r <Plug>(go-run) | |
autocmd FileType go nmap <silent> <leader>e <Plug>(go-install) | |
autocmd FileType go nmap <silent> <Leader>c <Plug>(go-coverage-toggle) | |
" I like these more! | |
autocmd Filetype go command! -bang A call go#alternate#Switch(<bang>0, 'edit') | |
autocmd Filetype go command! -bang AV call go#alternate#Switch(<bang>0, 'vsplit') | |
autocmd Filetype go command! -bang AS call go#alternate#Switch(<bang>0, 'split') | |
autocmd Filetype go command! -bang AT call go#alternate#Switch(<bang>0, 'tabe') | |
augroup END | |
" ==================== COC ==================== | |
" Use tab for trigger completion with characters ahead and navigate. | |
" 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> | |
\ 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. | |
if has('nvim') | |
inoremap <silent><expr> <c-space> coc#refresh() | |
else | |
inoremap <silent><expr> <c-@> coc#refresh() | |
endif | |
" Make <CR> auto-select the first completion item and notify coc.nvim to | |
" format on enter, <cr> could be remapped by other vim plugin | |
inoremap <silent><expr> <cr> pumvisible() ? coc#_select_confirm() | |
\: "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>" | |
" 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 <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 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 codeAction to the selected region. | |
" Example: `<leader>aap` for current paragraph | |
xmap <leader>a <Plug>(coc-codeaction-selected) | |
nmap <leader>a <Plug>(coc-codeaction-selected) | |
" Remap keys for applying codeAction to the current buffer. | |
nmap <leader>ac <Plug>(coc-codeaction) | |
" Apply AutoFix to problem on the current line. | |
nmap <leader>qf <Plug>(coc-fix-current) | |
" 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> for 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 CocAction('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 CocAction('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> | |
" ==================== FZF ==================== | |
let g:fzf_command_prefix = 'Fzf' | |
let g:fzf_layout = { 'down': '~35%' } | |
" search | |
nmap <C-p> :FzfHistory<cr> | |
imap <C-p> <esc>:<C-u>FzfHistory<cr> | |
" search across files in the current directory | |
nmap <C-b> :FzfFiles<cr> | |
imap <C-b> <esc>:<C-u>FzfFiles<cr> | |
let g:rg_command = ' | |
\ rg --column --line-number --no-heading --fixed-strings --ignore-case --no-ignore --hidden --follow --color "always" | |
\ -g "*.{js,json,php,md,styl,jade,html,config,py,cpp,c,go,hs,rb,conf}" | |
\ -g "!{.git,node_modules,vendor}/*" ' | |
command! -bang -nargs=* Rg | |
\ call fzf#vim#grep( | |
\ 'rg --column --line-number --no-heading --color=always '.shellescape(<q-args>), 1, | |
\ <bang>0 ? fzf#vim#with_preview('up:60%') | |
\ : fzf#vim#with_preview('right:50%:hidden', '?'), | |
\ <bang>0) | |
command! -bang -nargs=* F call fzf#vim#grep(g:rg_command .shellescape(<q-args>), 1, <bang>0) | |
let g:snipMate = {'snippet_version': 1} | |
" Snippets: | |
imap <C-J> <esc>a<Plug>snipMateNextOrTrigger | |
smap <C-J> <Plug>snipMateNextOrTrigger | |
set backup | |
set backupdir=~/.vim-tmp,~/.tmp,~/tmp,/var/tmp,/tmp | |
set backupskip=/tmp/*,/private/tmp/* | |
set directory=~/.vim-tmp,~/.tmp,~/tmp,/var/tmp,/tmp | |
set writebackup |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment