.vimrc 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  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. \ 'active': {
  96. \ 'left': [
  97. \ [ 'mode', 'paste' ],
  98. \ [ 'gitbranch', 'readonly', 'filename', 'tagbar', 'modified' ]
  99. \ ],
  100. \ 'right': [
  101. \ [ 'linter_checking', 'linter_errors', 'linter_warnings', 'linter_infos', 'linter_ok' ],
  102. \ [ 'percent', 'lineinfo', 'offset' ],
  103. \ [ 'fileformat', 'fileencoding', 'filetype' ]
  104. \ ]
  105. \ },
  106. \ 'component': {
  107. \ 'tagbar': '%{tagbar#currenttag("%s", "", "f", "nearest-stl")}',
  108. \ },
  109. \ 'component_function': {
  110. \ 'gitbranch': 'FugitiveHead',
  111. \ 'offset': 'FileOffset'
  112. \ },
  113. \ 'component_expand': {
  114. \ 'linter_checking': 'lightline#ale#checking',
  115. \ 'linter_infos': 'lightline#ale#infos',
  116. \ 'linter_warnings': 'lightline#ale#warnings',
  117. \ 'linter_errors': 'lightline#ale#errors',
  118. \ 'linter_ok': 'lightline#ale#ok'
  119. \ },
  120. \ 'component_type': {
  121. \ 'linter_checking': 'right',
  122. \ 'linter_infos': 'right',
  123. \ 'linter_warnings': 'warning',
  124. \ 'linter_errors': 'error',
  125. \ 'linter_ok': 'right'
  126. \ }
  127. \ }
  128. function! FileOffset()
  129. return line2byte(line('.')) + col('.') - 1
  130. endfunction
  131. " NERDtree
  132. " Close NERDTree on opening file
  133. let NERDTreeQuitOnOpen=1
  134. " Show hidden files
  135. let NERDTreeShowHidden=1
  136. function! NERDTreeToggleCustom()
  137. " If NERDTree is open in the current buffer
  138. if (exists("t:NERDTreeBufName") && bufwinnr(t:NERDTreeBufName) != -1)
  139. exe ":NERDTreeClose"
  140. elseif bufname('%') != ""
  141. exe ":NERDTreeFind"
  142. else
  143. exe ":NERDTreeCWD"
  144. endif
  145. endfunction
  146. " Toggle NERDTree on <space>-o
  147. map <Space>o :call NERDTreeToggleCustom()<CR>
  148. " Tagbar
  149. let g:tagbar_autoclose = 1
  150. let g:tagbar_autofocus = 1
  151. let g:tagbar_map_showproto = ''
  152. " Toggle transparent background
  153. let g:is_transparent = 0
  154. function! Toggle_transparent()
  155. echo g:is_transparent
  156. if g:is_transparent == 0
  157. hi Normal guibg=NONE ctermbg=NONE
  158. let g:is_transparent = 1
  159. else
  160. set background=dark
  161. let g:is_transparent = 0
  162. endif
  163. endfunction
  164. nnoremap <Space>T :call Toggle_transparent()<CR>
  165. " Location list
  166. autocmd BufEnter * if !exists("b:location_list") | let b:location_list = 0 | endif
  167. let b:location_list = 0
  168. function! Toggle_location_list()
  169. if b:location_list == 0
  170. lopen
  171. let b:location_list = 1
  172. else
  173. lclose
  174. let b:location_list = 0
  175. endif
  176. endfunction
  177. nnoremap <Space>l :call Toggle_location_list()<CR>
  178. " Location list
  179. autocmd BufEnter * if !exists("b:quick_list") | let b:quick_list = 0 | endif
  180. let b:quick_list = 0
  181. function! Toggle_quick_list()
  182. if b:quick_list == 0
  183. copen
  184. let b:quick_list = 1
  185. else
  186. cclose
  187. let b:quick_list = 0
  188. endif
  189. endfunction
  190. nnoremap <Space>c :call Toggle_quick_list()<CR>
  191. " Git blame
  192. autocmd BufEnter * if !exists("b:git_blame") | let b:git_blame = 0 | endif
  193. function! Toggle_git_blame()
  194. if b:git_blame == 0
  195. :Git blame
  196. let b:git_blame = 1
  197. else
  198. let winIndex = 1
  199. let winCnt = winnr('$')
  200. while winIndex <= winCnt
  201. if expand('%:e') == "fugitiveblame"
  202. :close
  203. else
  204. :wincmd w
  205. endif
  206. let winIndex += 1
  207. endwhile
  208. let b:git_blame = 0
  209. endif
  210. endfunction
  211. nnoremap <Space>b :call Toggle_git_blame()<CR>
  212. " Key mappings
  213. map <C-l>n :cnext<CR>
  214. map <C-l>p :cprevious<CR>
  215. nnoremap <C-l>c :cclose<CR>
  216. nmap <Space>t :TagbarToggle<CR>
  217. nmap <Space>f :Files<CR>
  218. nmap <Space>r :Rg<CR>
  219. nmap <Space>n :GitGutterNextHunk<CR>
  220. nmap <Space>p :GitGutterPrevHunk<CR>
  221. " Setting title to enable better tmux titling
  222. if exists('$TMUX')
  223. autocmd BufReadPost,FileReadPost,BufNewFile,BufEnter * call system("tmux rename-window 'vim | " . expand("%:t") . "'")
  224. autocmd VimLeave * call system("tmux setw automatic-rename")
  225. endif
  226. function! PrettyXML()
  227. set filetype=xml
  228. silent %!xmllint --format --encode UTF-8 --recover - 2>/dev/null
  229. endfunction
  230. function! PrettyJSON()
  231. set filetype=json
  232. silent %!python3 -m json.tool
  233. endfunction
  234. command! PrettyXml call PrettyXML()
  235. command! PrettyJson call PrettyJSON()
  236. nmap <Space>x :call PrettyXML()<CR>
  237. nmap <Space>j :call PrettyJSON()<CR>
  238. " Disable bad default keybindings
  239. inoremap <C-w> <Nop>