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.

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