.vimrc 6.5 KB

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