dotfiles

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

init.vim (14610B)


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