self-bootstrapping vimrc's
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

277 lines
6.2 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. filetype plugin indent on
  2. filetype on
  3. syntax on
  4. set nocompatible hidden laststatus=2
  5. set backspace=indent,eol,start
  6. let g:mapleader=" "
  7. let g:just_installed = 0
  8. function! InstallPlug()
  9. if !filereadable(expand("~/.vim/autoload/plug.vim"))
  10. " try to install plug using curl and wget
  11. " If installation succeeds, we should source vim plug.
  12. if !executable('git')
  13. echom 'git not found.'
  14. finish
  15. endif
  16. if executable('curl')
  17. let result = system('curl -fLo ~/.vim/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim')
  18. if v:shell_error == 0
  19. let g:just_installed = 1
  20. return
  21. endif
  22. endif
  23. echom 'curl failed, trying wget. ' . result
  24. if executable('wget') && executable('mkdir')
  25. let result = system('mkdir -p ~/.vim/autoload && wget -O ~/.vim/autoload/plug.vim https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim')
  26. if v:shell_error == 0
  27. let g:just_installed = 1
  28. return
  29. endif
  30. endif
  31. echom 'wget failed too. ' . result
  32. finish
  33. endif
  34. endfu
  35. call InstallPlug()
  36. if g:just_installed == 1
  37. source ~/.vim/autoload/plug.vim
  38. endif
  39. call plug#begin()
  40. Plug 'catppuccin/vim'
  41. Plug 'lifepillar/vim-solarized8'
  42. Plug 'morhetz/gruvbox'
  43. Plug 'junegunn/seoul256.vim'
  44. Plug 'junegunn/fzf'
  45. Plug 'junegunn/fzf.vim'
  46. Plug 'prabirshrestha/vim-lsp'
  47. Plug 'mattn/vim-lsp-settings'
  48. Plug 'prabirshrestha/asyncomplete.vim'
  49. Plug 'prabirshrestha/asyncomplete-lsp.vim'
  50. Plug 'Townk/vim-autoclose'
  51. Plug 'tpope/vim-fugitive'
  52. Plug 'vim-airline/vim-airline'
  53. Plug 'vim-airline/vim-airline-themes'
  54. Plug 'junegunn/goyo.vim'
  55. Plug 'junegunn/limelight.vim'
  56. call plug#end()
  57. " options
  58. set nu
  59. set rnu
  60. set mouse+=a
  61. set linebreak
  62. set shiftwidth=2
  63. set tabstop=2
  64. set softtabstop=2
  65. set expandtab
  66. set smarttab
  67. set shiftround
  68. set autoindent
  69. set textwidth=80
  70. set colorcolumn=80
  71. set nowrap
  72. set undodir=~/.vim/undofiles
  73. set undofile nohlsearch incsearch
  74. set scrolloff=7
  75. set wildmode=longest,list,full
  76. set wildmenu
  77. autocmd FileType tex,text set nosmarttab autoindent
  78. autocmd Filetype python set textwidth=0 formatprg=autopep8 shiftwidth=4 tabstop=4 softtabstop=4
  79. autocmd FileType c,cpp,slang set nosmarttab autoindent
  80. autocmd Filetype markdown set nosmarttab shiftwidth=4 tabstop=4 softtabstop=4 autoindent
  81. autocmd BufReadPost *
  82. \ if line("'\"") >= 1 && line("'\"") <= line("$") && &ft !~# 'commit'
  83. \ | exe "normal! g`\""
  84. \ | endif
  85. " Remaps
  86. nnoremap j gj
  87. nnoremap k gk
  88. nnoremap <C-h> <C-w>h
  89. nnoremap <C-j> <C-w>j
  90. nnoremap <C-k> <C-w>k
  91. nnoremap <C-l> <C-w>l
  92. nnoremap <C-h> <C-w>h
  93. nnoremap <C-j> <C-w>j
  94. nnoremap <C-k> <C-w>k
  95. nnoremap <C-l> <C-w>l
  96. inoremap <A-a> ā
  97. inoremap <A-e> ē
  98. inoremap <A-i> ī
  99. inoremap <A-o> ō
  100. inoremap <A-u> ū
  101. nnoremap <F12> :w<BAR>:!texbld run compile<CR>
  102. nnoremap <F5> :w<BAR>:!./test.sh<CR>
  103. vnoremap J :m '>+1<CR>gv=gv
  104. vnoremap K :m '<-2<CR>gv=gv
  105. nnoremap J mzJ`z
  106. nnoremap <C-d> <C-d>zz
  107. nnoremap <C-u> <C-u>zz
  108. nnoremap n nzzzv
  109. nnoremap N Nzzzv
  110. xnoremap <leader>p _dP
  111. vnoremap <leader>y +y
  112. nnoremap <leader>y +y
  113. nnoremap <leader>Y +Y
  114. nnoremap <leader>x :!chmod +x %:p<CR>
  115. nnoremap <leader>X :!chmod -x %<CR>
  116. nnoremap <leader>e :! %:p<CR>
  117. nnoremap <leader>1 1gt
  118. nnoremap <leader>2 2gt
  119. nnoremap <leader>3 3gt
  120. nnoremap <leader>4 4gt
  121. nnoremap <leader>5 5gt
  122. nnoremap <leader>6 6gt
  123. nnoremap <leader>7 7gt
  124. nnoremap <leader>8 8gt
  125. nnoremap <leader>9 9gt
  126. nnoremap <leader>c :tabclose<CR>
  127. nnoremap <leader>b :wprev<CR>
  128. nnoremap <leader>n :wnext<CR>
  129. " netrw
  130. nnoremap <C-n> :20Lexplore<CR>
  131. nnoremap <leader>pv :Explore<CR>
  132. " Plugin options must go at the bottom of the file.
  133. " install plugins
  134. if g:just_installed == 1
  135. echom 'Installing Plugins...'
  136. PlugInstall
  137. endif
  138. " Goyo and themes
  139. function! Catppuccin()
  140. set background=dark
  141. colorscheme catppuccin_frappe
  142. let g:airline_theme = "catppuccin_frappe"
  143. endfu
  144. function! SolarizedLight()
  145. colorscheme solarized8
  146. set background=light
  147. let g:airline_theme = "solarized"
  148. endfu
  149. function! SolarizedDark()
  150. colorscheme solarized8
  151. set background=dark
  152. let g:airline_theme = "solarized"
  153. let g:airline_solarized_bg='dark'
  154. endfu
  155. function! Gruvbox()
  156. set background=dark
  157. colorscheme gruvbox
  158. let g:airline_theme = "gruvbox"
  159. endfu
  160. function! Seoul256()
  161. let g:seoul256_background = 234
  162. let g:airline_theme = "seoul256"
  163. set background=dark
  164. colorscheme seoul256
  165. endfu
  166. if has('termguicolors')
  167. set termguicolors
  168. let &t_8f = "\<Esc>[38;2;%lu;%lu;%lum"
  169. let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum"
  170. call Gruvbox()
  171. else
  172. call Seoul256()
  173. endif
  174. autocmd! User GoyoEnter Limelight
  175. autocmd! User GoyoLeave Limelight!
  176. let g:airline_powerline_fonts = 1
  177. let g:airline#extensions#tabline#enabled = 1
  178. nnoremap <leader>z :Goyo <CR>
  179. nnoremap <leader>gs :Git <CR>
  180. nnoremap <leader>ff :Files<CR>
  181. nnoremap <C-p> :GFiles<CR>
  182. " lsp
  183. set cot+=preview
  184. function! s:on_lsp_buffer_enabled() abort
  185. setlocal omnifunc=lsp#complete
  186. setlocal signcolumn=yes
  187. if exists('+tagfunc') | setlocal tagfunc=lsp#tagfunc | endif
  188. nmap <buffer> gd <plug>(lsp-definition)
  189. nmap <buffer> gs <plug>(lsp-document-symbol-search)
  190. nmap <buffer> gS <plug>(lsp-workspace-symbol-search)
  191. nmap <buffer> gr <plug>(lsp-references)
  192. nmap <buffer> gi <plug>(lsp-implementation)
  193. nmap <buffer> gt <plug>(lsp-type-definition)
  194. nmap <buffer> <leader>rn <plug>(lsp-rename)
  195. nmap <buffer> [g <plug>(lsp-previous-diagnostic)
  196. nmap <buffer> ]g <plug>(lsp-next-diagnostic)
  197. nmap <buffer> K <plug>(lsp-hover)
  198. nnoremap <leader>ft :LspDocumentFormat<CR>
  199. let g:lsp_format_sync_timeout = 1000
  200. endfunction
  201. if exists('*prop_add') && has('patch-9.0.0178')
  202. let g:lsp_diagnostics_virtual_text_enabled = 1
  203. let g:lsp_diagnostics_virtual_text_align = "after"
  204. let g:lsp_diagnostics_virtual_text_padding_left = 5
  205. else
  206. let g:lsp_diagnostics_float_cursor = 1
  207. let g:lsp_diagnostics_float_delay = 1
  208. endif
  209. augroup lsp_install
  210. au!
  211. autocmd User lsp_buffer_enabled call s:on_lsp_buffer_enabled()
  212. augroup END
  213. imap <c-space> <Plug>(asyncomplete_force_refresh)
  214. inoremap <expr> <Tab> pumvisible() ? "\<C-n>" : "\<Tab>"
  215. inoremap <expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<S-Tab>"
  216. inoremap <expr> <cr> pumvisible() ? "\<C-y>\<cr>" : "\<cr>"
  217. autocmd! CompleteDone * if pumvisible() == 0 | pclose | endif