vimrc 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. " -----------------------------------------------------------------------------
  2. " Status line
  3. " -----------------------------------------------------------------------------
  4. " Heavily inspired by: https://github.com/junegunn/dotfiles/blob/master/vimrc
  5. function! s:statusline_expr()
  6. let mod = "%{&modified ? '[+] ' : !&modifiable ? '[x] ' : ''}"
  7. let ro = "%{&readonly ? '[RO] ' : ''}"
  8. let ft = "%{len(&filetype) ? '['.&filetype.'] ' : ''}"
  9. let fug = "%{exists('g:loaded_fugitive') ? fugitive#statusline() : ''}"
  10. let sep = ' %= '
  11. let pos = ' %-12(%l : %c%V%) '
  12. let pct = ' %P'
  13. return '[%n] %f %<'.mod.ro.ft.fug.sep.pos.'%*'.pct
  14. endfunction
  15. let &statusline = s:statusline_expr()
  16. " Use a line cursor within insert mode and a block cursor everywhere else.
  17. "
  18. " Reference chart of values:
  19. " Ps = 0 -> blinking block.
  20. " Ps = 1 -> blinking block (default).
  21. " Ps = 2 -> steady block.
  22. " Ps = 3 -> blinking underline.
  23. " Ps = 4 -> steady underline.
  24. " Ps = 5 -> blinking bar (xterm).
  25. " Ps = 6 -> steady bar (xterm).
  26. let &t_SI = "\e[6 q"
  27. let &t_EI = "\e[2 q"
  28. set rtp+=/usr/share/vim/addons/plugin/powerline.vim
  29. set t_Co=256
  30. syntax on
  31. set autoindent
  32. set smartindent
  33. set autoread
  34. set backspace=indent,eol,start
  35. set backupdir=/tmp//,.
  36. set clipboard=unnamedplus,unnamed
  37. set complete+=kspell
  38. set completeopt=menuone,longest
  39. set cursorline
  40. set directory=/tmp//,.
  41. set encoding=utf-8
  42. set expandtab
  43. set smarttab
  44. set formatoptions=tcqrn1
  45. set hidden
  46. set hlsearch
  47. set ignorecase
  48. set incsearch
  49. set laststatus=2
  50. set matchpairs+=<:> " Use % to jump between pairs
  51. set mmp=5000
  52. set modelines=2
  53. set mouse=a
  54. set nocompatible
  55. set noerrorbells visualbell t_vb=
  56. set noshiftround
  57. set nospell
  58. set nostartofline
  59. set number relativenumber
  60. set regexpengine=1
  61. set ruler
  62. set scrolloff=0
  63. set shiftwidth=2
  64. set showcmd
  65. set showmatch
  66. set shortmess+=c
  67. set showmode
  68. set smartcase
  69. set softtabstop=2
  70. set spelllang=en_us
  71. set splitbelow
  72. set splitright
  73. set tabstop=2
  74. set history=1000
  75. set updatetime=500
  76. " WSL yank support
  77. " Ref: https://superuser.com/questions/1291425/windows-subsystem-linux-make-vim-use-the-clipboard
  78. let s:clip = '/mnt/c/Windows/System32/clip.exe' " change this path according to your mount point
  79. if executable(s:clip)
  80. augroup WSLYank
  81. autocmd!
  82. autocmd TextYankPost * if v:event.operator ==# 'y' | call system(s:clip, @0) | endif
  83. augroup END
  84. endif
  85. " --[ Plug-vim
  86. let data_dir = has('nvim') ? stdpath('data') . '/site' : '~/.vim'
  87. if empty(glob(data_dir . '/autoload/plug.vim'))
  88. silent execute '!curl -fLo '.data_dir.'/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim'
  89. autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
  90. endif
  91. call plug#begin()
  92. " Syntastic is a syntax checking plugin for Vim
  93. Plug 'vim-syntastic/syntastic'
  94. " Fugitive is the premier Vim plugin for Git.
  95. Plug 'tpope/vim-fugitive'
  96. " Lean & mean status/tabline for vim that's light as air.
  97. Plug 'vim-airline/vim-airline'
  98. Plug 'vim-airline/vim-airline-themes'
  99. " Sometimes, it's useful to line up text.
  100. Plug 'https://github.com/godlygeek/tabular'
  101. " Go plug in
  102. Plug 'fatih/vim-go', { 'do': ':GoUpdateBinaries' }
  103. " Go plug in
  104. " Plug 'govim/govim'
  105. " If you've ever tried using the . command after a plugin map
  106. Plug 'tpope/vim-repeat'
  107. " EasyClip is a plugin for Vim which contains a collection of clipboard related functionality
  108. " Plug 'svermeulen/vim-easyclip'
  109. " Powerline for vim
  110. Plug 'powerline/powerline'
  111. " Terraform
  112. Plug 'hashivim/vim-terraform'
  113. " Comment lines
  114. Plug 'tpope/vim-commentary'
  115. " Completion
  116. Plug 'ervandew/supertab'
  117. " Markdown TOC
  118. Plug 'mzlogin/vim-markdown-toc'
  119. " Nerdtree
  120. Plug 'preservim/nerdtree'
  121. " Theme Iceberg
  122. Plug 'cocopon/iceberg.vim'
  123. " Theme Nord
  124. Plug 'arcticicestudio/nord-vim'
  125. " Theme Solarized8
  126. Plug 'lifepillar/vim-solarized8'
  127. " Them Hybrid
  128. Plug 'w0ng/vim-hybrid'
  129. " NERDTree plugin that highlights all visible nodes
  130. " Plug 'PhilRunninger/nerdtree-buffer-ops'
  131. " Buffergator is a plugin for listing, navigating between buffers
  132. Plug 'jeetsukumaran/vim-buffergator'
  133. " A plugin of NERDTree showing git status flags
  134. Plug 'Xuyuanp/nerdtree-git-plugin'
  135. " Git diff display tools
  136. Plug 'airblade/vim-gitgutter'
  137. " Conventional git message
  138. Plug 'jmauro/vim-conventional-commits'
  139. call plug#end()
  140. " --[ NERDTree
  141. " Start NERDTree. If a file is specified, move the cursor to its window.
  142. autocmd StdinReadPre * let s:std_in=1
  143. autocmd VimEnter * NERDTree | if argc() > 0 || exists("s:std_in") | wincmd p | endif
  144. " Exit Vim if NERDTree is the only window remaining in the only tab.
  145. autocmd BufEnter * if tabpagenr('$') == 1 && winnr('$') == 1 && exists('b:NERDTree') && b:NERDTree.isTabTree() | quit | endif
  146. " Show hidden files by default with NERDTree
  147. let NERDTreeShowHidden=1
  148. let g:NERDTreeWinSize = 35
  149. " Map NERDTree mapping
  150. nnoremap <leader>n :NERDTreeFocus<CR>
  151. nnoremap <C-n> :NERDTree<CR>
  152. " --[ Airline
  153. " let g:airline_theme='cobalt2'
  154. let g:airline_theme='molokai'
  155. let g:buffergator_viewport_split_policy = "B"
  156. " --[ Solarized Theme
  157. set background=dark
  158. colorscheme solarized8
  159. " --[ Powerline
  160. let g:airline_powerline_fonts = 1
  161. " --[ Syntastic
  162. " Display configuration
  163. let g:syntastic_always_populate_loc_list = 1
  164. let g:syntastic_auto_loc_list = 1
  165. let g:syntastic_check_on_open = 1
  166. let g:syntastic_check_on_wq = 0
  167. " Language checker
  168. "let g:syntastic_go_checkers = ['golangci-lint', 'gofmt']
  169. "let g:syntastic_go_golangci_lint_args = ['run']
  170. let g:syntastic_yaml_checkers = [ "yamllint" ]
  171. " let g:syntastic_terraform_checkers = ['terragrunt']
  172. " let g:syntastic_terraform_terragrunt_lint_args = ['hclfmt']
  173. " --[ gitgutter
  174. let g:gitgutter_preview_win_floating = 1
  175. " --[ Terraform
  176. let g:hcl_align = 1
  177. let g:terraform_align = 1
  178. let g:terraform_fmt_on_save = 1
  179. " --[ Shortcut remap
  180. " Autoformat F12
  181. map <F12> gg=C<C-o><C-o>
  182. let g:go_auto_sameids = 1
  183. let g:go_highlight_array_whitespace_error = 1
  184. let g:go_highlight_chan_whitespace_error = 1
  185. let g:go_highlight_extra_types = 1
  186. let g:go_highlight_space_tab_error = 1
  187. let g:go_highlight_trailing_whitespace_error = 0
  188. let g:go_highlight_operators = 1
  189. let g:go_highlight_functions = 1
  190. let g:go_highlight_function_parameters = 1
  191. let g:go_highlight_function_calls = 1
  192. let g:go_highlight_types = 1
  193. let g:go_highlight_fields = 1
  194. let g:go_highlight_build_constraints = 1
  195. let g:go_highlight_generate_tags = 1
  196. let g:go_highlight_string_spellcheck = 1
  197. let g:go_highlight_format_strings = 1
  198. let g:go_highlight_variable_declarations = 1
  199. let g:go_highlight_variable_assignments = 1
  200. let g:go_fmt_experimental = 1
  201. let g:go_metalinter_autosave=1
  202. let g:go_metalinter_autosave_enabled=['golint', 'govet']