.vimrc 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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 'itchyny/lightline.vim'
  18. Plug 'dikiaap/minimalist'
  19. Plug 'morhetz/gruvbox'
  20. Plug 'dense-analysis/ale'
  21. Plug 'maximbaz/lightline-ale'
  22. Plug 'preservim/tagbar'
  23. Plug 'vim-php/tagbar-phpctags.vim'
  24. Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
  25. Plug 'junegunn/fzf.vim'
  26. Plug 'arcticicestudio/nord-vim'
  27. Plug 'airblade/vim-gitgutter'
  28. call plug#end()
  29. filetype plugin indent on
  30. syntax on
  31. set autoindent
  32. set backspace=2
  33. set background=dark
  34. set cursorcolumn
  35. set cursorline
  36. set expandtab
  37. set history=1000
  38. set hlsearch
  39. set incsearch
  40. set nowrap
  41. set number
  42. set numberwidth=4
  43. set pastetoggle=<F12> "Press <F12> when paste-alot
  44. set preserveindent
  45. set ruler
  46. set shiftround
  47. set shiftwidth=2
  48. set shortmess=atI
  49. set showcmd
  50. set showmatch
  51. set smartindent
  52. set smarttab
  53. set splitright
  54. set tabstop=2
  55. set whichwrap+=<,>,[,],h,l
  56. set undofile
  57. set undodir=~/.vim/undo
  58. " Gruvbox
  59. let g:gruvbox_italic = 1
  60. let g:gruvbox_bold = 1
  61. let g:gruvbox_transaprent_bg = 1
  62. colorscheme gruvbox
  63. " ALE completion
  64. let g:ale_completion_autoimport = 1
  65. set omnifunc=ale#completion#OmniFunc
  66. " Ale keymaps
  67. nnoremap <C-a>g :ALEGoToDefinition -tab<CR>
  68. nnoremap <C-a>G :ALEGoToDefinition<CR>
  69. nnoremap <C-a>h :ALEHover<CR>
  70. nnoremap <C-a>f :ALEFindReferences<CR>
  71. " ALE navigation
  72. nmap <silent> <C-k> <Plug>(ale_previous_wrap)
  73. nmap <silent> <C-j> <Plug>(ale_next_wrap)
  74. " Lightline
  75. set laststatus=2
  76. set noshowmode
  77. let g:lightline = {
  78. \ 'colorscheme': 'gruvbox',
  79. \ 'active': {
  80. \ 'left': [
  81. \ [ 'mode', 'paste' ],
  82. \ [ 'gitbranch', 'readonly', 'filename', 'tagbar', 'modified' ]
  83. \ ],
  84. \ 'right': [
  85. \ [ 'linter_checking', 'linter_errors', 'linter_warnings', 'linter_infos', 'linter_ok' ],
  86. \ [ 'percent', 'lineinfo', 'offset' ],
  87. \ [ 'fileformat', 'fileencoding', 'filetype' ]
  88. \ ]
  89. \ },
  90. \ 'component': {
  91. \ 'tagbar': '%{tagbar#currenttag("%s", "", "f", "nearest-stl")}',
  92. \ },
  93. \ 'component_function': {
  94. \ 'gitbranch': 'FugitiveHead',
  95. \ 'offset': 'FileOffset'
  96. \ },
  97. \ 'component_expand': {
  98. \ 'linter_checking': 'lightline#ale#checking',
  99. \ 'linter_infos': 'lightline#ale#infos',
  100. \ 'linter_warnings': 'lightline#ale#warnings',
  101. \ 'linter_errors': 'lightline#ale#errors',
  102. \ 'linter_ok': 'lightline#ale#ok'
  103. \ },
  104. \ 'component_type': {
  105. \ 'linter_checking': 'right',
  106. \ 'linter_infos': 'right',
  107. \ 'linter_warnings': 'warning',
  108. \ 'linter_errors': 'error',
  109. \ 'linter_ok': 'right'
  110. \ }
  111. \ }
  112. function! FileOffset()
  113. return line2byte(line('.')) + col('.') - 1
  114. endfunction
  115. " NERDtree
  116. " Start NERDTree if no file was specified
  117. autocmd StdinReadPre * let s:std_in=1
  118. " autocmd VimEnter * if argc() == 0 && !exists("s:std_in") | call NERDTreeToggleCustom() | endif
  119. " Close NERDTree on opening file
  120. let NERDTreeQuitOnOpen=1
  121. " Show hidden files
  122. let NERDTreeShowHidden=1
  123. function! NERDTreeToggleCustom()
  124. " If NERDTree is open in the current buffer
  125. if (exists("t:NERDTreeBufName") && bufwinnr(t:NERDTreeBufName) != -1)
  126. exe ":NERDTreeClose"
  127. elseif bufname('%') != ""
  128. exe ":NERDTreeFind"
  129. else
  130. exe ":NERDTreeCWD"
  131. endif
  132. endfunction
  133. " Toggle NERDTree on <space>-o
  134. map <Space>o :call NERDTreeToggleCustom()<CR>
  135. " Tagbar
  136. let g:tagbar_autoclose = 1
  137. let g:tagbar_autofocus = 1
  138. let g:tagbar_map_showproto = ''
  139. " Toggle transparent background
  140. let g:is_transparent = 0
  141. function! Toggle_transparent()
  142. echo g:is_transparent
  143. if g:is_transparent == 0
  144. hi Normal guibg=NONE ctermbg=NONE
  145. let g:is_transparent = 1
  146. else
  147. set background=dark
  148. let g:is_transparent = 0
  149. endif
  150. endfunction
  151. nnoremap <Space>T :call Toggle_transparent()<CR>
  152. " Location list
  153. autocmd BufEnter * if !exists("b:location_list") | let b:location_list = 0 | endif
  154. let b:location_list = 0
  155. function! Toggle_location_list()
  156. if b:location_list == 0
  157. lopen
  158. let b:location_list = 1
  159. else
  160. lclose
  161. let b:location_list = 0
  162. endif
  163. endfunction
  164. nnoremap <Space>l :call Toggle_location_list()<CR>
  165. " Location list
  166. autocmd BufEnter * if !exists("b:quick_list") | let b:quick_list = 0 | endif
  167. let b:quick_list = 0
  168. function! Toggle_quick_list()
  169. if b:quick_list == 0
  170. copen
  171. let b:quick_list = 1
  172. else
  173. cclose
  174. let b:quick_list = 0
  175. endif
  176. endfunction
  177. nnoremap <Space>c :call Toggle_quick_list()<CR>
  178. " Git blame
  179. autocmd BufEnter * if !exists("b:git_blame") | let b:git_blame = 0 | endif
  180. function! Toggle_git_blame()
  181. if b:git_blame == 0
  182. :Git blame
  183. let b:git_blame = 1
  184. else
  185. let winIndex = 1
  186. let winCnt = winnr('$')
  187. while winIndex <= winCnt
  188. if expand('%:e') == "fugitiveblame"
  189. :close
  190. else
  191. :wincmd w
  192. endif
  193. let winIndex += 1
  194. endwhile
  195. let b:git_blame = 0
  196. endif
  197. endfunction
  198. nnoremap <Space>b :call Toggle_git_blame()<CR>
  199. " Key mappings
  200. map <C-l>n :cnext<CR>
  201. map <C-l>p :cprevious<CR>
  202. nnoremap <C-l>c :cclose<CR>
  203. nmap <Space>t :TagbarToggle<CR>
  204. nmap <Space>f :Files<CR>
  205. nmap <Space>r :Rg<CR>
  206. nmap <Space>n :GitGutterNextHunk<CR>
  207. nmap <Space>p :GitGutterPrevHunk<CR>
  208. " Setting title to enable better tmux titling
  209. if exists('$TMUX')
  210. autocmd BufReadPost,FileReadPost,BufNewFile,BufEnter * call system("tmux rename-window 'vim | " . expand("%:t") . "'")
  211. autocmd VimLeave * call system("tmux setw automatic-rename")
  212. endif
  213. function! PrettyXML()
  214. set filetype=xml
  215. silent %!xmllint --format --encode UTF-8 --recover - 2>/dev/null
  216. endfunction
  217. function! PrettyJSON()
  218. set filetype=json
  219. silent %!python3 -m json.tool
  220. endfunction
  221. command! PrettyXml call PrettyXML()
  222. command! PrettyJson call PrettyJSON()
  223. nmap <Space>j call PrettyXml()
  224. nmap <Space>x call PrettyJSON()