.vimrc 6.5 KB

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