.vimrc 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. " Run the following git commands to get the plugins
  2. " Plugin manager
  3. if empty(glob('~/.vim/autoload/plug.vim'))
  4. silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs
  5. \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
  6. autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
  7. endif
  8. " Pre-plugin calls
  9. let g:ale_completion_enabled = 1
  10. let g:ale_hover_to_floating_preview = 1
  11. let g:ale_floating_preview = 1
  12. " Plugins
  13. call plug#begin('~/.vim/plugged')
  14. Plug 'preservim/nerdtree'
  15. Plug 'tpope/vim-fugitive'
  16. Plug 'tpope/vim-commentary'
  17. Plug 'fatih/vim-go', { 'do': ':GoUpdateBinaries' }
  18. Plug 'itchyny/lightline.vim'
  19. Plug 'dikiaap/minimalist'
  20. Plug 'morhetz/gruvbox'
  21. Plug 'dense-analysis/ale'
  22. Plug 'maximbaz/lightline-ale'
  23. Plug 'preservim/tagbar'
  24. Plug 'vim-php/tagbar-phpctags.vim'
  25. Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
  26. Plug 'junegunn/fzf.vim'
  27. call plug#end()
  28. filetype plugin indent on
  29. syntax on
  30. set autoindent
  31. set backspace=2
  32. set background=dark
  33. set cursorcolumn
  34. set cursorline
  35. set expandtab
  36. set history=1000
  37. set hlsearch
  38. set incsearch
  39. set nowrap
  40. set number
  41. set numberwidth=4
  42. set pastetoggle=<F12> "Press <F12> when paste-alot
  43. set preserveindent
  44. set ruler
  45. set shiftround
  46. set shiftwidth=2
  47. set shortmess=atI
  48. set showcmd
  49. set showmatch
  50. set smartindent
  51. set smarttab
  52. set tabstop=2
  53. set whichwrap+=<,>,[,],h,l
  54. set undofile
  55. set undodir=~/.vim/undo
  56. " Gruvbox
  57. let g:gruvbox_italic = 1
  58. let g:gruvbox_bold = 1
  59. let g:gruvbox_transparent_bg = 1
  60. colorscheme gruvbox
  61. " ALE completion
  62. let g:ale_completion_autoimport = 1
  63. set omnifunc=ale#completion#OmniFunc
  64. " Ale keymaps
  65. nnoremap <C-a>g :ALEGoToDefinition -tab<CR>
  66. nnoremap <C-a>G :ALEGoToDefinition<CR>
  67. nnoremap <C-a>h :ALEHover<CR>
  68. nnoremap <C-a>f :ALEFindReferences<CR>
  69. " ALE navigation
  70. nmap <silent> <C-k> <Plug>(ale_previous_wrap)
  71. nmap <silent> <C-j> <Plug>(ale_next_wrap)
  72. " Lightline
  73. set laststatus=2
  74. set noshowmode
  75. let g:lightline = {
  76. \ 'colorscheme': 'gruvbox',
  77. \ 'active': {
  78. \ 'left': [
  79. \ [ 'mode', 'paste' ],
  80. \ [ 'gitbranch', 'readonly', 'filename', 'tagbar', 'modified' ]
  81. \ ],
  82. \ 'right': [
  83. \ [ 'linter_checking', 'linter_errors', 'linter_warnings', 'linter_infos', 'linter_ok' ],
  84. \ [ 'percent', 'lineinfo', 'offset' ],
  85. \ [ 'fileformat', 'fileencoding', 'filetype' ]
  86. \ ]
  87. \ },
  88. \ 'component': {
  89. \ 'tagbar': '%{tagbar#currenttag("%s", "", "f", "nearest-stl")}',
  90. \ },
  91. \ 'component_function': {
  92. \ 'gitbranch': 'FugitiveHead',
  93. \ 'offset': 'FileOffset'
  94. \ },
  95. \ 'component_expand': {
  96. \ 'linter_checking': 'lightline#ale#checking',
  97. \ 'linter_infos': 'lightline#ale#infos',
  98. \ 'linter_warnings': 'lightline#ale#warnings',
  99. \ 'linter_errors': 'lightline#ale#errors',
  100. \ 'linter_ok': 'lightline#ale#ok'
  101. \ },
  102. \ 'component_type': {
  103. \ 'linter_checking': 'right',
  104. \ 'linter_infos': 'right',
  105. \ 'linter_warnings': 'warning',
  106. \ 'linter_errors': 'error',
  107. \ 'linter_ok': 'right'
  108. \ }
  109. \ }
  110. function! FileOffset()
  111. return line2byte(line('.')) + col('.') - 1
  112. endfunction
  113. " NERDtree
  114. " Start NERDTree if no file was specified
  115. autocmd StdinReadPre * let s:std_in=1
  116. " autocmd VimEnter * if argc() == 0 && !exists("s:std_in") | call NERDTreeToggleCustom() | endif
  117. " Close NERDTree on opening file
  118. let NERDTreeQuitOnOpen=1
  119. " Show hidden files
  120. let NERDTreeShowHidden=1
  121. function! NERDTreeToggleCustom()
  122. " If NERDTree is open in the current buffer
  123. if (exists("t:NERDTreeBufName") && bufwinnr(t:NERDTreeBufName) != -1)
  124. exe ":NERDTreeClose"
  125. elseif bufname('%') != ""
  126. exe ":NERDTreeFind"
  127. else
  128. exe ":NERDTreeCWD"
  129. endif
  130. endfunction
  131. " Toggle NERDTree on <space>-o
  132. map <Space>o :call NERDTreeToggleCustom()<CR>
  133. " Tagbar
  134. let g:tagbar_autoclose = 1
  135. let g:tagbar_autofocus = 1
  136. let g:tagbar_map_showproto = ''
  137. " Toggle transparent background
  138. let g:is_transparent = 0
  139. function! Toggle_transparent()
  140. echo g:is_transparent
  141. if g:is_transparent == 0
  142. hi Normal guibg=NONE ctermbg=NONE
  143. let g:is_transparent = 1
  144. else
  145. set background=dark
  146. let g:is_transparent = 0
  147. endif
  148. endfunction
  149. nnoremap <Space>T :call Toggle_transparent()<CR>
  150. " vim-go
  151. let g:go_highlight_types = 1
  152. let g:go_highlight_fields = 1
  153. let g:go_highlight_functions = 1
  154. let g:go_highlight_function_calls = 1
  155. let g:go_highlight_operators = 1
  156. let g:go_auto_type_info = 1
  157. let g:go_fmt_command = "goimports"
  158. " let g:go_list_type = "quickfix"
  159. map <C-g>v :GoVet<CR>
  160. map <C-g>r :GoRun<CR>
  161. map <C-g>b :GoBuild<CR>
  162. " Key mappings
  163. map <C-l>n :cnext<CR>
  164. map <C-l>p :cprevious<CR>
  165. nnoremap <C-l>c :cclose<CR>
  166. nmap <Space>t :TagbarToggle<CR>
  167. nmap <Space>f :Files<CR>
  168. nmap <Space>r :Rg<CR>
  169. function! PrettyXML()
  170. set filetype=xml
  171. silent %!xmllint --format --encode UTF-8 --recover - 2>/dev/null
  172. endfunction
  173. function! PrettyJSON()
  174. set filetype=json
  175. silent %!python3 -m json.tool
  176. endfunction
  177. command! PrettyXml call PrettyXML()
  178. command! PrettyJson call PrettyJSON()