dotfiles

feels like ${HOME}
Log | Files | Refs | README

init.vim (15088B)


      1 " For Vim
      2 set nocompatible
      3 set encoding=UTF-8
      4 
      5 let s:plugin_location = '~/.vim/plugged'
      6 if has('nvim')
      7   let s:plugin_location = '~/.local/share/nvim/plugged'
      8 endif
      9 
     10 " PlugIns
     11 call plug#begin(s:plugin_location)
     12   Plug 'arzg/vim-colors-xcode'
     13     let g:xcodelighthc_match_paren_style = 1
     14   Plug 'mhartington/oceanic-next'
     15 
     16   " *fzf.vim*
     17   Plug '/usr/local/opt/fzf'
     18   Plug 'junegunn/fzf.vim'
     19     let g:fzf_preview_window = ['down:50%', 'ctrl-/']
     20   source ~/.vim/scripts/fzf_js_import.vim
     21 
     22   " *bufkill*
     23   Plug 'qpkorr/vim-bufkill'
     24 
     25   " *vim-fugitive*
     26   Plug 'tpope/vim-fugitive'
     27   Plug 'tpope/vim-rhubarb'
     28   " Plug 'mhinz/vim-signify'
     29   "   let g:signify_realtime = 1
     30   "   let g:signify_cursorhold_normal = 0
     31   "   let g:signify_cursorhold_insert = 0
     32   "   let g:signify_sign_add    = '█'
     33   "   let g:signify_sign_change = '█'
     34   "   let g:signify_sign_delete = '▂'
     35   "   let g:signify_sign_show_count = 0
     36   "   let g:signify_line_highlight = 0
     37   Plug 'shumphrey/fugitive-gitlab.vim'
     38     let g:fugitive_gitlab_domains = ['https://gitlab.kumparan.com']
     39 
     40   " *git-messenger*
     41   Plug 'rhysd/git-messenger.vim'
     42     let g:git_messenger_git_command = 'hub'
     43     let g:git_messenger_no_default_mappings = v:true
     44 
     45   " *vim-easymotion*
     46   " Plug 'easymotion/vim-easymotion'
     47 
     48   " *vim-searchindex*
     49   " Plug 'google/vim-searchindex'
     50   "   let g:searchindex_line_limit=10000000
     51 
     52   " *vim-sneak*
     53   Plug 'justinmk/vim-sneak'
     54     let g:sneak#absolute_dir = 1
     55 
     56   " *vim-airline*
     57   Plug 'vim-airline/vim-airline'
     58     let g:airline#extensions#tabline#enabled = 1
     59     let g:airline#extensions#tabline#show_tabs = 0
     60     let g:airline#extensions#tabline#buffer_nr_show = 1
     61     let g:airline#extensions#tabline#formatter = 'jsformatter'
     62   Plug 'vim-airline/vim-airline-themes'
     63 
     64     " to enable these, set git.addGBlameToBufferVar true on CocConfig
     65     " function! s:update_git_blame()
     66     "   let g:airline_section_x = "%{get(b:,'coc_git_blame','')}"
     67     " endfunction
     68     " let g:airline_section_x = "%{get(b:,'coc_git_blame','')}"
     69     " autocmd User CocGitStatusChange call s:update_git_blame()
     70 
     71       let g:airline#extensions#default#layout = [
     72       \ [ 'a', 'b', 'c'],
     73       \ [ 'z', 'error', 'warning' ]
     74       \ ]
     75     " let g:airline_section_x = []
     76     " let g:airline_section_y = []
     77 
     78     let g:airline#extensions#coc#enabled = 1
     79     " use error & warning count of diagnostics form coc.nvim
     80     let g:airline_section_error = '%{airline#util#wrap(airline#extensions#coc#get_error(),0)}'
     81     let g:airline_section_warning = '%{airline#util#wrap(airline#extensions#coc#get_warning(),0)}'
     82     " let g:airline_theme = 'xcodelighthc'
     83 
     84   " *tmux*
     85   Plug 'tmux-plugins/vim-tmux'
     86   Plug 'tmux-plugins/vim-tmux-focus-events'
     87 
     88   " *nerdtree*
     89   Plug 'scrooloose/nerdtree'
     90     Plug 'Xuyuanp/nerdtree-git-plugin'
     91     let g:NERDTreeWinPos = "right"
     92 
     93   Plug 'junegunn/vim-peekaboo'
     94   Plug 'machakann/vim-highlightedyank'
     95   " Plug 'jiangmiao/auto-pairs'
     96   "   let g:AutoPairsMultilineClose = 0
     97 
     98   Plug 'tpope/vim-commentary'
     99   Plug 'tpope/vim-surround'
    100   Plug 'tpope/vim-repeat'
    101 
    102   " *coc.nvim*
    103   Plug 'neoclide/coc.nvim', {'branch': 'release'}
    104     function! s:show_documentation()
    105       if &filetype == 'vim'
    106         execute 'h '.expand('<cword>')
    107       else
    108         call CocAction('doHover')
    109       endif
    110     endfunction
    111     au BufNewFile,BufRead *.(c|v|vv|py) setlocal tabstop=4
    112     au BufNewFile,BufRead *.(c|v|vv|py) setlocal shiftwidth=4
    113     au BufNewFile,BufRead *.(c|v|vv|py) setlocal set noexpandtab
    114 
    115   " *vim-clap*
    116   " Plug 'liuchengxu/vim-clap', { 'do': ':Clap install-binary!' }
    117   "   let g:clap_provider_grep_delay = 100
    118   "   let g:clap_disable_run_rooter = v:true
    119   "   let g:clap_layout = { 'relative': 'editor' }
    120 
    121   " LaTeX
    122   Plug 'lervag/vimtex'
    123     let g:vimtex_view_method='zathura'
    124 
    125   " JavaScript
    126   Plug 'pangloss/vim-javascript'
    127     let g:javascript_plugin_flow = 1
    128     let g:javascript_plugin_jsdoc = 1
    129   Plug 'othree/yajs.vim'
    130   Plug 'maxmellon/vim-jsx-pretty'
    131     let g:vim_jsx_pretty_colorful_config = 1
    132     let g:jsx_ext_required = 0
    133 
    134   " styled-components
    135   Plug 'styled-components/vim-styled-components', { 'branch': 'main' }
    136 
    137   " TypeScript
    138   Plug 'leafgarland/typescript-vim'
    139   Plug 'HerringtonDarkholme/yats.vim'
    140 
    141   " Markdown
    142   " Plug 'ybbond/vim-markdown'
    143   "   let g:vim_markdown_folding_disabled = 1
    144   "   let g:vim_markdown_conceal = 0
    145   "   let g:vim_markdown_strikethrough = 1
    146   "   let g:vim_markdown_math = 1
    147   "   let g:vim_markdown_frontmatter = 1  " for YAML format
    148   "   let g:vim_markdown_toml_frontmatter = 1  " for TOML format
    149   "   let g:vim_markdown_json_frontmatter = 1  " for JSON format
    150 
    151   Plug 'cespare/vim-toml'
    152   Plug 'stephpy/vim-yaml'
    153 
    154   " GRAPHQL
    155   Plug 'jparise/vim-graphql'
    156 
    157   " Go
    158   Plug 'fatih/vim-go', { 'do': ':GoUpdateBinaries' }
    159 
    160   " Rust
    161   " Plug 'rust-lang/rust.vim'
    162   "   let g:rustfmt_autosave = 1
    163 
    164   " Reason
    165   Plug 'reasonml-editor/vim-reason-plus'
    166     autocmd BufNewFile,BufRead *.re nnoremap <leader>w :!refmt --in-place %<cr>
    167     let g:LanguageClient_serverCommands = {
    168       \ 'reason': ['/Users/yohanesbandung/bin/reason-language-server']
    169       \ }
    170 
    171   " " vlang
    172   Plug 'ollykel/v-vim'
    173 
    174 call plug#end()
    175 
    176 colorscheme OceanicNext
    177 set background=dark
    178 
    179 " colorscheme xcodelighthc
    180 " set background=light
    181 
    182 set termguicolors
    183 
    184 syntax enable
    185 syntax on
    186 filetype plugin on
    187 filetype plugin indent on
    188 
    189 set nopaste
    190 set pastetoggle=<F2>
    191 
    192 set tabstop=2
    193 set softtabstop=2
    194 set shiftwidth=2
    195 set scrolloff=2
    196 set expandtab
    197 set nowrap
    198 set linebreak
    199 set list
    200 set listchars=tab:▷\ ,trail:◻,nbsp:𐩒
    201 
    202 set mouse=n
    203 set noshowmode
    204 
    205 set number
    206 set relativenumber
    207 
    208 set ruler
    209 set showmatch
    210 set cursorline
    211 
    212 " highlight CursorLine cterm=NONE ctermfg=NONE ctermbg=87 guifg=NONE guibg=#EEF6FF
    213 " autocmd InsertEnter * highlight CursorLine cterm=NONE ctermfg=NONE ctermbg=87 guifg=NONE guibg=#EEF6FF
    214 " autocmd InsertLeave * highlight CursorLine cterm=NONE ctermfg=NONE ctermbg=87 guifg=NONE guibg=#EEF6FF
    215 
    216 set ignorecase
    217 set smartcase
    218 set incsearch
    219 set hlsearch
    220 
    221 if has('nvim')
    222   set inccommand=split
    223 endif
    224 
    225 " Let's save undo info!
    226 if has('nvim')
    227   if has('persistent_undo')
    228     set undofile
    229     set undolevels=250
    230     set undoreload=500
    231   endif
    232 else
    233   if !isdirectory($HOME."/.vim")
    234     call mkdir($HOME."/.vim", "", 0770)
    235   endif
    236   if !isdirectory($HOME."/.vim/undo-dir")
    237     call mkdir($HOME."/.vim/undo-dir", "", 0700)
    238   endif
    239   set undodir=~/.vim/undo-dir
    240   " Then set persistent undo!
    241   if has('persistent_undo')
    242     set undofile
    243     set undolevels=250
    244     set undoreload=500
    245   endif
    246 endif
    247 
    248 nnoremap <expr> j &wrap == 1 ? 'gj' : 'j'
    249 nnoremap <expr> k &wrap == 1 ? 'gk' : 'k'
    250 nnoremap <expr> $ &wrap == 1 ? 'g$' : '$'
    251 nnoremap <expr> 0 &wrap == 1 ? 'g0' : '0'
    252 
    253 
    254 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""
    255 "                      NORMAL MODE
    256 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""
    257 
    258 " keep asterisk and pound to be case sensitive
    259 nnoremap <leader>* :let @/='\C\<' . expand('<cword>') . '\>'<CR>:let v:searchforward=1<CR>n
    260 nnoremap <leader># :let @/='\C\<' . expand('<cword>') . '\>'<CR>:let v:searchforward=0<CR>n
    261 
    262 " reload all opened buffer
    263 nnoremap <leader>br :bufdo e<cr>
    264 
    265 " Copy, Paste and Copy Whole File to clipboard
    266 map <leader>c "+yy
    267 map <leader>v :r !pbpaste<cr><cr>
    268 map <leader>ac :%w !pbcopy<cr><cr>
    269 
    270 " Toggle wrap
    271 map <leader>w :set wrap!<cr>
    272 
    273 " Unhighlight search
    274 nnoremap <silent> <LEADER><SPACE> :nohlsearch<cr>
    275 
    276 " Toggle check spelling
    277 nnoremap <leader>s :set spell! spelllang=en_us<cr>
    278 
    279 map <silent> <A-h> <C-w><
    280 map <silent> <A-k> <C-W>-
    281 map <silent> <A-j> <C-W>+
    282 map <silent> <A-l> <C-w>>
    283 
    284 " Remap leader-% to source %
    285 nnoremap <leader>% :source ~/.config/nvim/init.vim<cr>
    286 
    287 " navigating buffers
    288 nnoremap gb :bnext<cr>
    289 nnoremap gB :bprevious<cr>
    290 
    291 " |vim-sneak|
    292   map f <Plug>Sneak_f
    293   map F <Plug>Sneak_F
    294   map t <Plug>Sneak_t
    295   map T <Plug>Sneak_T
    296   " " 2-character Sneak (default)
    297   " nmap Q <Plug>Sneak_s
    298   " nmap <leader>Q <Plug>Sneak_S
    299   " " visual-mode
    300   " xmap Q <Plug>Sneak_s
    301   " xmap <leader>Q <Plug>Sneak_S
    302   " " operator-pending-mode
    303   " omap Q <Plug>Sneak_s
    304   " omap <leader>Q <Plug>Sneak_S
    305 
    306 " |vim-fugitive|
    307   map <leader>kp :Gdiff!<cr>
    308   map <leader>kb :Git blame<cr>
    309 
    310 " |coc.nvim|
    311   nmap gd <Plug>(coc-definition)
    312   nmap <2-LeftMouse> <Plug>(coc-definition)
    313   nmap gh :call <SID>show_documentation()<cr>
    314   nmap <2-LeftMouse> :call <SID>show_documentation()<cr>
    315   nmap <leader>gd <Plug>(coc-diagnostics-info)
    316   nmap [c <Plug>(coc-git-prevchunk)
    317   nmap ]c <Plug>(coc-git-nextchunk)
    318   nmap <C-w>g <Plug>(coc-git-chunkinfo)
    319   nmap <C-w><C-g> <Plug>(coc-git-chunkinfo)
    320   nmap ]C <Plug>(coc-diagnostic-next)
    321   nmap [C <Plug>(coc-diagnostic-prev)
    322   nmap gi <Plug>(coc-implementation)
    323   nmap gr <Plug>(coc-references)
    324   nmap <leader>. :call CocAction("codeAction")<cr>
    325 
    326   command! CocGstatus CocList gstatus
    327   command! CocBuffers CocList buffers
    328   command! W noa w
    329 
    330 " |git-messenger|
    331   nmap <C-w>m <Plug>(git-messenger)
    332   nmap <C-w><C-m> <Plug>(git-messenger)
    333 
    334 " |bufkill|
    335   nnoremap gx :BD<cr>
    336 
    337 " |fzf.vim|
    338   let g:rg_command = '
    339     \ rg --column --line-number --no-heading --fixed-strings --ignore-case --hidden --follow --color "always"
    340     \ -g "*.{css,js,jsx,ts,tsx,json,re,php,md,styl,jade,html,config,py,cpp,c,go,hs,rb,conf}"
    341     \ -g "!{.git,node_modules,coverage,vendor,build}/*" '
    342 
    343   " NOTES
    344   " the {'options': '-e'} limits to only search literal text https://github.com/BurntSushi/ripgrep/issues/1119
    345   " the {'options': '--delimiter : --nth 4..'} option limit the string search only for file content
    346   command! -bang -nargs=* StringsAll
    347   \ call fzf#vim#grep(
    348   \   'rg --column --line-number --hidden --no-ignore --no-heading --color=always --smart-case -- '.shellescape(<q-args>), 1,
    349   \   fzf#vim#with_preview({'options': '--preview-window=down:50% --layout=reverse --delimiter : --nth 4..'}), <bang>0)
    350   " OLD
    351   " command! -bang -nargs=* Strings call fzf#vim#grep(g:rg_command .shellescape(<q-args>), 1, <bang>0)
    352   command! -bang -nargs=* Strings
    353   \ call fzf#vim#grep(
    354   \   'rg --column --line-number --hidden --glob "!{.git,node_modules,flow-typed,operation-types.flow.js,generatedTypes}" --no-heading --color=always --smart-case -- '.shellescape(<q-args>), 1,
    355   \   fzf#vim#with_preview({'options': '--preview-window=down:50% --layout=reverse --delimiter : --nth 4..'}), <bang>0)
    356   command! -bang -nargs=* StringsWhole
    357   \ call fzf#vim#grep(
    358   \   'rg --column --line-number --hidden --glob "!{.git,node_modules,flow-typed,operation-types.flow.js,generatedTypes}" --no-heading --color=always --smart-case -- '.shellescape(<q-args>), 1,
    359   \   fzf#vim#with_preview({'options': '-e --preview-window=down:50% --layout=reverse --delimiter : --nth 4..'}), <bang>0)
    360   command! -bang -nargs=* StringsAndFileWhole
    361   \ call fzf#vim#grep(
    362   \   'rg --column --line-number --hidden --glob "!{.git,node_modules,flow-typed,operation-types.flow.js,generatedTypes}" --no-heading --color=always --smart-case -- '.shellescape(<q-args>), 1,
    363   \   fzf#vim#with_preview({'options': '-e --preview-window=down:50% --layout=reverse'}), <bang>0)
    364 
    365   command! -bang -nargs=? -complete=dir FilesAll
    366     \ call fzf#vim#files(<q-args>, fzf#vim#with_preview({'options': ['--preview-window=down:50%', '--layout=reverse', '--info=inline']}), <bang>0)
    367   command! -bang -nargs=? -complete=dir Files
    368     \ call fzf#vim#gitfiles(<q-args>, fzf#vim#with_preview({'options': ['--preview-window=down:50%', '--layout=reverse', '--info=inline']}), <bang>0)
    369 
    370   " nnoremap <C-o> :Strings<cr>
    371   " nnoremap <C-i> :Files<cr>
    372   noremap <C-i> :Strings<cr>
    373   noremap <C-s> :StringsWhole<cr>
    374   noremap <leader><C-s> :StringsAndFileWhole<cr>
    375   noremap <leader><C-i> :StringsAll<cr>
    376   noremap <C-p> :Files --cached --others --exclude-standard<cr>
    377   noremap <leader><C-p> :FilesAll<cr>
    378   " noremap <C-b> :Buffers<CR>
    379   noremap <C-g> :CocGstatus<CR>
    380   noremap <C-b> :CocBuffers<CR>
    381 
    382 " |vim-clap|
    383   " nnoremap <C-i> :Clap!! grep ++opt=--hidden ++opt=-g=!.git<cr>
    384   " nnoremap <leader><C-i> :Clap grep ++opt=--hidden ++opt=-g=!.git<cr>
    385   " nnoremap <C-p> :Clap!! files --hidden<cr>
    386   " nnoremap <leader><C-p> :Clap files --hidden<cr>
    387   " nnoremap <leader>* :Clap!! grep ++query=<cword> ++opt=--hidden ++opt=-g=!.git<cr>
    388   " nnoremap <leader><leader>* :Clap grep ++query=<cword> ++opt=--hidden ++opt=-g=!.git<cr>
    389   " vnoremap <leader>* :Clap!! grep ++query=@visual ++opt=--hidden ++opt=-g=!.git<cr>
    390   " vnoremap <leader><leader>* :Clap grep ++query=@visual ++opt=--hidden ++opt=-g=!.git<cr>
    391   " nnoremap <C-b> :Clap buffers<cr>
    392 
    393 " |nerdtree|
    394   map <leader>e :NERDTreeToggle<cr>
    395   map <leader>r :NERDTreeFind<cr>
    396 
    397 
    398 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""
    399 "                      INSERT MODE
    400 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""
    401 
    402 " Remap <c-d> to delete
    403 inoremap <C-d> <Del>
    404 
    405 " Remap escape to j + k
    406 inoremap jk <ESC>
    407 inoremap <C-c> <ESC>
    408 
    409 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""
    410 "                      APPEARANCE
    411 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""
    412 
    413 augroup numbertoggle
    414   if &number == 1
    415     autocmd!
    416     autocmd BufEnter,FocusGained,InsertLeave * set relativenumber
    417     autocmd BufLeave,FocusLost,InsertEnter * set norelativenumber
    418   endif
    419 augroup end
    420 
    421 function ToggleNumberToggle(numberVar)
    422   " Reset group
    423   augroup numbertoggle
    424     autocmd!
    425   augroup end
    426 
    427   " Enable if toggled on
    428   if a:numberVar
    429     augroup numbertoggle
    430       if &number == 1
    431         autocmd!
    432         autocmd BufEnter,FocusGained,InsertLeave * set relativenumber
    433         autocmd BufLeave,FocusLost,InsertEnter * set norelativenumber
    434       endif
    435     augroup end
    436   endif
    437 endfunction
    438 
    439 " change cursor in different mode
    440 if has('nvim')
    441   " make the ^[ sign with:
    442   " (INSERT MODE) <C-v><ESC>
    443   " make sure it shows different color than the rest
    444   set t_SI=[5\ q
    445   set t_SR=[4\ q
    446   set t_EI=[1\ q
    447 else
    448   if exists('$TMUX')
    449       " tmux will only forward escape sequences to the terminal if surrounded by a DCS sequence
    450       let &t_SI .= "\<Esc>Ptmux;\<Esc>\<Esc>[5 q\<Esc>\\"
    451       let &t_SR .= "\<Esc>Ptmux;\<Esc>\<Esc>[4 q\<Esc>\\"
    452       let &t_EI .= "\<Esc>Ptmux;\<Esc>\<Esc>[1 q\<Esc>\\"
    453       autocmd VimLeave * silent !echo -ne "\033Ptmux;\033\033[0 q\033\\"
    454   else
    455       " make the ^[ sign with:
    456       " (INSERT MODE) <C-v><ESC>
    457       " make sure it shows different color than the rest
    458       set t_SI=[5\ q
    459       set t_SR=[4\ q
    460       set t_EI=[1\ q
    461       autocmd VimLeave * silent !echo -ne "\033[0 q"
    462   endif
    463 endif
    464 
    465 " |vim-fugitive|
    466 set diffopt+=vertical
    467 
    468 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""
    469 "                      COLOR RELATED
    470 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""
    471 
    472 " TODO highlight
    473 " FIXME highlight
    474 " XXX highlight
    475 
    476 " Change comment color
    477 " hi Comment guifg=LightBlue
    478 hi Comment gui=italic cterm=italic
    479 " hi htmlStrike gui=strikethrough cterm=strikethrough guibg=Black ctermbg=Black
    480 " hi Todo guibg=Black ctermbg=Black guifg=White ctermfg=White gui=bold,italic cterm=bold,italic
    481 " hi NonText guifg=#4a4a59 ctermfg=Gray
    482 " hi SpecialKey guifg=#4a4a59 ctermfg=Gray
    483 hi SignColumn ctermbg=NONE cterm=NONE guibg=NONE gui=NONE