.vimrc 6.2 KB

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