.vimrc 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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 'fatih/vim-go', { 'do': ':GoUpdateBinaries' }
  18. Plug 'itchyny/lightline.vim'
  19. Plug 'dikiaap/minimalist'
  20. Plug 'morhetz/gruvbox'
  21. Plug 'dense-analysis/ale'
  22. Plug 'maximbaz/lightline-ale'
  23. Plug 'preservim/tagbar'
  24. Plug 'vim-php/tagbar-phpctags.vim'
  25. call plug#end()
  26. filetype plugin indent on
  27. syntax on
  28. set autoindent
  29. set backspace=2
  30. set background=dark
  31. set cursorcolumn
  32. set cursorline
  33. set expandtab
  34. set history=1000
  35. set hlsearch
  36. set incsearch
  37. set nowrap
  38. set number
  39. set numberwidth=4
  40. set pastetoggle=<F12> "Press <F12> when paste-alot
  41. set preserveindent
  42. set ruler
  43. set shiftround
  44. set shiftwidth=2
  45. set shortmess=atI
  46. set showcmd
  47. set showmatch
  48. set smartindent
  49. set smarttab
  50. set tabstop=2
  51. set whichwrap+=<,>,[,],h,l
  52. set undofile
  53. set undodir=~/.vim/undo
  54. " Gruvbox
  55. let g:gruvbox_italic = 1
  56. let g:gruvbox_bold = 1
  57. let g:gruvbox_transparent_bg = 1
  58. colorscheme gruvbox
  59. " ALE completion
  60. let g:ale_completion_autoimport = 1
  61. set omnifunc=ale#completion#OmniFunc
  62. " Ale keymaps
  63. nnoremap <C-a>g :ALEGoToDefinition -tab<CR>
  64. nnoremap <C-a>G :ALEGoToDefinition<CR>
  65. nnoremap <C-a>h :ALEHover<CR>
  66. nnoremap <C-a>f :ALEFindReferences<CR>
  67. " ALE navigation
  68. nmap <silent> <C-k> <Plug>(ale_previous_wrap)
  69. nmap <silent> <C-j> <Plug>(ale_next_wrap)
  70. " Lightline
  71. set laststatus=2
  72. set noshowmode
  73. let g:lightline = {
  74. \ 'colorscheme': 'gruvbox',
  75. \ 'active': {
  76. \ 'left': [
  77. \ [ 'mode', 'paste' ],
  78. \ [ 'gitbranch', 'readonly', 'filename', 'tagbar', 'modified' ]
  79. \ ],
  80. \ 'right': [
  81. \ [ 'linter_checking', 'linter_errors', 'linter_warnings', 'linter_infos', 'linter_ok' ],
  82. \ [ 'percent', 'lineinfo', 'offset' ],
  83. \ [ 'fileformat', 'fileencoding', 'filetype' ]
  84. \ ]
  85. \ },
  86. \ 'component': {
  87. \ 'tagbar': '%{tagbar#currenttag("%s", "", "f", "nearest-stl")}',
  88. \ },
  89. \ 'component_function': {
  90. \ 'gitbranch': 'FugitiveHead',
  91. \ 'offset': 'FileOffset'
  92. \ },
  93. \ 'component_expand': {
  94. \ 'linter_checking': 'lightline#ale#checking',
  95. \ 'linter_infos': 'lightline#ale#infos',
  96. \ 'linter_warnings': 'lightline#ale#warnings',
  97. \ 'linter_errors': 'lightline#ale#errors',
  98. \ 'linter_ok': 'lightline#ale#ok'
  99. \ },
  100. \ 'component_type': {
  101. \ 'linter_checking': 'right',
  102. \ 'linter_infos': 'right',
  103. \ 'linter_warnings': 'warning',
  104. \ 'linter_errors': 'error',
  105. \ 'linter_ok': 'right'
  106. \ }
  107. \ }
  108. function! FileOffset()
  109. return line2byte(line('.')) + col('.') - 1
  110. endfunction
  111. " NERDtree
  112. " Start NERDTree if no file was specified
  113. autocmd StdinReadPre * let s:std_in=1
  114. " autocmd VimEnter * if argc() == 0 && !exists("s:std_in") | call NERDTreeToggleCustom() | endif
  115. " Close NERDTree on opening file
  116. let NERDTreeQuitOnOpen=1
  117. " Show hidden files
  118. let NERDTreeShowHidden=1
  119. function! NERDTreeToggleCustom()
  120. " If NERDTree is open in the current buffer
  121. if (exists("t:NERDTreeBufName") && bufwinnr(t:NERDTreeBufName) != -1)
  122. exe ":NERDTreeClose"
  123. elseif bufname('%') != ""
  124. exe ":NERDTreeFind"
  125. else
  126. exe ":NERDTreeCWD"
  127. endif
  128. endfunction
  129. " Toggle NERDTree on <space>-o
  130. map <Space>o :call NERDTreeToggleCustom()<CR>
  131. " Tagbar
  132. let g:tagbar_autoclose = 1
  133. let g:tagbar_autofocus = 1
  134. let g:tagbar_map_showproto = ''
  135. " Toggle transparent background
  136. let g:is_transparent = 0
  137. function! Toggle_transparent()
  138. echo g:is_transparent
  139. if g:is_transparent == 0
  140. hi Normal guibg=NONE ctermbg=NONE
  141. let g:is_transparent = 1
  142. else
  143. set background=dark
  144. let g:is_transparent = 0
  145. endif
  146. endfunction
  147. nnoremap <Space>T :call Toggle_transparent()<CR>
  148. " vim-go
  149. let g:go_highlight_types = 1
  150. let g:go_highlight_fields = 1
  151. let g:go_highlight_functions = 1
  152. let g:go_highlight_function_calls = 1
  153. let g:go_highlight_operators = 1
  154. let g:go_auto_type_info = 1
  155. let g:go_fmt_command = "goimports"
  156. " let g:go_list_type = "quickfix"
  157. map <C-g>v :GoVet<CR>
  158. map <C-g>r :GoRun<CR>
  159. map <C-g>b :GoBuild<CR>
  160. " Key mappings
  161. map <C-l>n :cnext<CR>
  162. map <C-l>p :cprevious<CR>
  163. nnoremap <C-l>c :cclose<CR>
  164. nmap <Space>t :TagbarToggle<CR>