.vimrc 6.1 KB

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