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.

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