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.

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