Skip to content

Instantly share code, notes, and snippets.

@cipriantarta
Last active March 25, 2022 11:56
Show Gist options
  • Save cipriantarta/7103e8f248ad119fca9f730310a292bb to your computer and use it in GitHub Desktop.
Save cipriantarta/7103e8f248ad119fca9f730310a292bb to your computer and use it in GitHub Desktop.
Vimrc
" let g:ale_disable_lsp = 1
"""""""""""""""""""""""""" PLUGINS BEGIN """""""""""""""""""""""""""""
call plug#begin('~/.vim/plugins')
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'junegunn/fzf.vim'
" Plug 'neoclide/coc.nvim', {'branch': 'release'}
" Plug 'dense-analysis/ale'
Plug 'preservim/nerdcommenter'
Plug 'preservim/nerdtree'
Plug 'Xuyuanp/nerdtree-git-plugin'
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
Plug 'ryanoasis/vim-devicons'
Plug 'tpope/vim-fugitive'
" colorscheme
Plug 'mhartington/oceanic-next'
Plug 'joshdick/onedark.vim'
Plug 'dracula/vim'
" Python
Plug 'vim-python/python-syntax'
" Golang
Plug 'sebdah/vim-delve'
" Web Plugins
Plug 'othree/html5.vim'
Plug 'pangloss/vim-javascript'
Plug 'leafgarland/typescript-vim'
" Plug 'HerringtonDarkholme/yats.vim'
Plug 'maxmellon/vim-jsx-pretty'
Plug 'peitalin/vim-jsx-typescript'
" Swift
Plug 'keith/swift.vim'
" Presentation
" Plug 'vim-scripts/SyntaxRange'
" Plug 'inkarkat/vim-ingo-library'
call plug#end()
"""""""""""""""""""""""""" PLUGINS END """""""""""""""""""""""""""""""
""""""""""""""""""""""""""" SETTINGS BEGIN """""""""""""""""""""""""""
if (has("termguicolors"))
set termguicolors
endif
set encoding=UTF-8
set nocompatible
set nobackup " do not keep a backup file, use versions instead
set nowritebackup
set history=100 " keep 50 lines of command line history
set ruler " show the cursor position all the time
set showcmd " display incomplete commands
set incsearch " do incremental searching
set clipboard=unnamed
set rnu
set nu
set numberwidth=5
set nowrap
set expandtab
set shiftwidth=4
set scrolloff=5
set laststatus=2
set hidden
set backspace=indent,eol,start
set updatetime=300
set shortmess+=c
syntax enable
if &t_Co > 2 || has("gui_running")
set hlsearch
hi Search cterm=bold ctermfg=white ctermbg=black
hi MatchParen cterm=bold ctermbg=black ctermfg=white
highlight Pmenu ctermfg=252 ctermbg=black guifg=#ffffff guibg=#000000
endi
autocmd CursorMovedI * if pumvisible() == 0|silent! pclose|endif
autocmd InsertLeave * if pumvisible() == 0|silent! pclose|endif
autocmd FileType yaml setlocal ts=2 sts=2 sw=2 expandtab
autocmd FileType typescript,javascript,typescript.tsx,javascript.tsx setlocal ts=2 sts=2 sw=2 expandtab
autocmd FileType go setlocal ts=8 sts=8 sw=8 expandtab
autocmd FileType proto setlocal ts=2 sts=2 sw=2 expandtab
filetype plugin on
let g:python_highlight_all = 1
"""""""""""""""""""""""""" SETTINGS END """"""""""""""""""""""""""""""
"""""""""""""""""""""""""" THEME BEGIN """""""""""""""""""""""""""""""
colorscheme dracula
let g:airline_theme='dracula'
let g:oceanic_next_terminal_bold = 1
let g:oceanic_next_terminal_italic = 1
"""""""""""""""""""""""""" THEME END """""""""""""""""""""""""""""""""
"""""""""""""""""""""""""" MAPPINGS BEGIN """"""""""""""""""""""""""""
" Don't use Ex mode, use Q for formatting
map Q gq
" CTRL-U in insert mode deletes a lot. Use CTRL-G u to first break undo,
" so that you can undo CTRL-U after inserting a line break.
inoremap <C-U> <C-G>u<C-U>
nnoremap <silent> <Right> :bn<CR>
nnoremap <silent> <Left> :bp<CR>
nnoremap <silent> <Leader>w :bd<CR>
nnoremap <silent> <C-x> :q!<CR>
nnoremap <silent> <C-s> :w<CR>
inoremap <silent> <C-s> <Esc>:w<CR>
"""""""""""""""""""""""""" MAPPINGS END """"""""""""""""""""""""""""
"""""""""""""""""""""""""" FZF BEGIN """""""""""""""""""""""""""""
command! LS call fzf#run(fzf#wrap({'source': 'git ls-files', 'sink': 'e', 'options': '--reverse'}))
nnoremap <silent><c-o> :LS<CR>
nnoremap <silent> ø :Ag<cr>
"""""""""""""""""""""""""" FZF END """""""""""""""""""""""""""""""
"""""""""""""""""""""""""" AIRLINE BEGIN """""""""""""""""""""""""
let g:airline_powerline_fonts = 1
let g:airline#extensions#tabline#enabled = 1
let g:airline#extensions#tabline#show_tab_nr = 1
"""""""""""""""""""""""""" AIRLINE END """""""""""""""""""""""""""
"""""""""""""""""""""""""" ALE BEGIN """""""""""""""""""""""""""""
let g:ale_set_highlights = 0
let g:ale_fixers = {
\ '*': ['remove_trailing_lines', 'trim_whitespace'],
\ 'javascript': ['eslint', 'prettier'],
\ 'css': ['eslint', 'prettier'],
\ 'typescript': ['tslint', 'prettier'],
\ 'python': ['black', 'isort'],
\ 'go': ['gofmt', 'gofumpt', 'goimports', 'golines', 'remove_trailing_lines', 'trim_whitespace'],
\ 'swift': ['swiftformat'],
\ 'html': ['prettier', 'html-beautify'],
\}
let g:ale_linter_aliases = {
\ 'typescriptreact': ['typescript', 'tsx'],
\ 'javascriptreact': ['javascript','jsx']
\}
let g:ale_linters = {
\ 'go': ['bingo', 'cspell', 'gobuild', 'gofmt', 'golangci-lint', 'golint', 'gometalinter', 'gopls', 'gosimple', 'gotype', 'govet', 'golangserver', 'revive', 'staticcheck']
\}
let g:ale_fix_on_save = 1
"""""""""""""""""""""""""" ALE END """""""""""""""""""""""""""""""
""""""""""""""""""""""""" NERDCommenter BEGIN """"""""""""""""""""
let g:NERDSpaceDelims = 1
let g:NERDCompactSexyComs = 1
let g:NERDDefaultAlign = 'left'
let g:NERDCommentEmptyLines = 1
let g:NERDTrimTrailingWhitespace = 1
nnoremap <silent> <C-n> :NERDTreeToggle<CR>
""""""""""""""""""""""""" NERDCommenter END """"""""""""""""""""""
""""""""""""""""""""""""" CoC BEGIN """"""""""""""""""""""""""""""
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.
if has('patch8.1.1068')
" Use `complete_info` if your (Neo)Vim version supports it.
inoremap <expr> <cr> complete_info()["selected"] != "-1" ? "\<C-y>" : "\<C-g>u\<CR>"
else
imap <expr> <cr> pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>"
endif
" Use `[g` and `]g` to 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)
" 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 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 line.
nmap <leader>ac <Plug>(coc-codeaction)
" Apply AutoFix to problem on the current line.
nmap <leader>qf <Plug>(coc-fix-current)
" Introduce function text object
" NOTE: Requires 'textDocument.documentSymbol' support from the language server.
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 <TAB> for selections ranges.
" NOTE: Requires 'textDocument/selectionRange' support from the language server.
" coc-tsserver, coc-python are the examples of servers that support it.
nmap <silent> <TAB> <Plug>(coc-range-select)
xmap <silent> <TAB> <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 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>
""""""""""""""""""""""""" CoC END """"""""""""""""""""""""""""""""
"""""""""""""""""""""""""" TYPESCRIPT BEING """"""""""""""""""""""""
" set filetypes as typescript.tsx
autocmd BufNewFile,BufRead *.tsx,*.jsx set filetype=typescript.tsx
" dark red
hi tsxTagName guifg=#E06C75
hi tsxComponentName guifg=#E06C75
hi tsxCloseComponentName guifg=#E06C75
" orange
hi tsxCloseString guifg=#F99575
hi tsxCloseTag guifg=#F99575
hi tsxCloseTagName guifg=#F99575
hi tsxAttributeBraces guifg=#F99575
hi tsxEqual guifg=#F99575
" yellow
hi tsxAttrib guifg=#F8BD7F cterm=italic
" light-grey
hi tsxTypeBraces guifg=#999999
" dark-grey
hi tsTypes guifg=#666666
"""""""""""""""""""""""""" TYPESCRIPT END """"""""""""""""""""""""""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment