Guest User

Untitled

a guest
Oct 16th, 2023
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VIM 15.75 KB | None | 0 0
  1. " vim-bootstrap 2022-10-10 13:46:47
  2.  
  3. "*****************************************************************************
  4. "" Vim-Plug core
  5. "*****************************************************************************
  6. let vimplug_exists=expand('~/.vim/autoload/plug.vim')
  7. if has('win32')&&!has('win64')
  8.   let curl_exists=expand('C:\Windows\Sysnative\curl.exe')
  9. else
  10.   let curl_exists=expand('curl')
  11. endif
  12.  
  13. let g:vim_bootstrap_langs = "go,lua"
  14. let g:vim_bootstrap_editor = "vim"              " nvim or vim
  15. let g:vim_bootstrap_theme = "sonokai"
  16. let g:vim_bootstrap_frams = ""
  17.  
  18. if !filereadable(vimplug_exists)
  19.   if !executable(curl_exists)
  20.     echoerr "You have to install curl or first install vim-plug yourself!"
  21.     execute "q!"
  22.   endif
  23.   echo "Installing Vim-Plug..."
  24.   echo ""
  25.   silent exec "!"curl_exists" -fLo " . shellescape(vimplug_exists) . " --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim"
  26.   let g:not_finish_vimplug = "yes"
  27.  
  28.   autocmd VimEnter * PlugInstall
  29. endif
  30.  
  31. " Required:
  32. call plug#begin(expand('~/.vim/plugged'))
  33.  
  34. "*****************************************************************************
  35. "" Plug install packages
  36. "*****************************************************************************
  37. Plug 'scrooloose/nerdtree'
  38. Plug 'jistr/vim-nerdtree-tabs'
  39. Plug 'tpope/vim-commentary'
  40. Plug 'tpope/vim-fugitive'
  41. Plug 'vim-airline/vim-airline'
  42. Plug 'vim-airline/vim-airline-themes'
  43. Plug 'airblade/vim-gitgutter'
  44. Plug 'vim-scripts/grep.vim'
  45. Plug 'vim-scripts/CSApprox'
  46. Plug 'Raimondi/delimitMate'
  47. Plug 'majutsushi/tagbar'
  48. Plug 'dense-analysis/ale'
  49. Plug 'Yggdroot/indentLine'
  50. Plug 'editor-bootstrap/vim-bootstrap-updater'
  51. Plug 'tpope/vim-rhubarb' " required by fugitive to :Gbrowse
  52. Plug 'sainnhe/sonokai'
  53. Plug 'maralla/completor.vim'
  54.  
  55. if isdirectory('/usr/local/opt/fzf')
  56.   Plug '/usr/local/opt/fzf' | Plug 'junegunn/fzf.vim'
  57. else
  58.   Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --bin' }
  59.   Plug 'junegunn/fzf.vim'
  60. endif
  61. let g:make = 'gmake'
  62. if exists('make')
  63.         let g:make = 'make'
  64. endif
  65. Plug 'Shougo/vimproc.vim', {'do': g:make}
  66.  
  67. "" Vim-Session
  68. Plug 'xolox/vim-misc'
  69. Plug 'xolox/vim-session'
  70.  
  71. "" Snippets
  72. Plug 'SirVer/ultisnips'
  73. Plug 'honza/vim-snippets'
  74.  
  75.  
  76. set viminfo='100,<300,s10,h
  77.  
  78. "*****************************************************************************
  79. "" Custom bundles
  80. "*****************************************************************************
  81.  
  82. " go
  83. "" Go Lang Bundle
  84. Plug 'fatih/vim-go', {'do': ':GoInstallBinaries'}
  85.  
  86.  
  87. " lua
  88. "" Lua Bundle
  89. "Plug 'xolox/vim-lua-ftplugin'
  90. "Plug 'xolox/vim-lua-inspect'
  91.  
  92.  
  93. "*****************************************************************************
  94. "*****************************************************************************
  95.  
  96. "" Include user's extra bundle
  97. if filereadable(expand("~/.vimrc.local.bundles"))
  98.   source ~/.vimrc.local.bundles
  99. endif
  100.  
  101.   let g:indentLine_enabled = 0
  102.  
  103. call plug#end()
  104.  
  105. " Required:
  106. filetype plugin indent on
  107.  
  108.  
  109. "*****************************************************************************
  110. "" Basic Setup
  111. "*****************************************************************************"
  112. "" Encoding
  113. set encoding=utf-8
  114. set fileencoding=utf-8
  115. set fileencodings=utf-8
  116. set ttyfast
  117.  
  118. "" Fix backspace indent
  119. set backspace=indent,eol,start
  120.  
  121. "" Tabs. May be overridden by autocmd rules
  122. set tabstop=4
  123. set softtabstop=0
  124. set shiftwidth=4
  125.  
  126. "" Map leader to ,
  127. let mapleader=','
  128.  
  129. "" Enable hidden buffers
  130. set hidden
  131.  
  132. "" Searching
  133. set hlsearch
  134. set incsearch
  135. set ignorecase
  136. set smartcase
  137.  
  138. set fileformats=unix,dos,mac
  139.  
  140. if exists('$SHELL')
  141.     set shell=$SHELL
  142. else
  143.     set shell=/bin/sh
  144. endif
  145.  
  146. " session management
  147. let g:session_directory = "~/.vim/session"
  148. let g:session_autoload = "no"
  149. let g:session_autosave = "no"
  150. let g:session_command_aliases = 1
  151.  
  152. "*****************************************************************************
  153. "" Visual Settings
  154. "*****************************************************************************
  155. syntax on
  156. set ruler
  157. set number
  158.  
  159. let no_buffers_menu=1
  160. colorscheme sonokai
  161.  
  162. " Better command line completion
  163. set wildmenu
  164.  
  165. " mouse support
  166. " set mouse=a
  167.  
  168. set mousemodel=popup
  169. set t_Co=256
  170. set guioptions=egmrti
  171. set gfn=Monospace\ 10
  172.  
  173. if has("gui_running")
  174.   if has("gui_mac") || has("gui_macvim")
  175.     set guifont=Menlo:h12
  176.     set transparency=7
  177.   endif
  178. else
  179.   let g:CSApprox_loaded = 1
  180.  
  181.   " IndentLine
  182.  
  183.  
  184.   if $COLORTERM == 'gnome-terminal'
  185.     set term=gnome-256color
  186.   else
  187.     if $TERM == 'xterm'
  188.       set term=xterm-256color
  189.     endif
  190.   endif
  191.  
  192. endif
  193.  
  194.  
  195. if &term =~ '256color'
  196.   set t_ut=
  197. endif
  198.  
  199.  
  200. "" Disable the blinking cursor.
  201. set gcr=a:blinkon0
  202.  
  203. set scrolloff=3
  204.  
  205.  
  206. "" Status bar
  207. set laststatus=2
  208.  
  209. "" Use modeline overrides
  210. set modeline
  211. set modelines=10
  212.  
  213. set title
  214. set titleold="Terminal"
  215. set titlestring=%F
  216.  
  217. set statusline=%F%m%r%h%w%=(%{&ff}/%Y)\ (line\ %l\/%L,\ col\ %c)\
  218.  
  219. " Search mappings: These will make it so that going to the next one in a
  220. " search will center on the line it's found in.
  221. nnoremap n nzzzv
  222. nnoremap N Nzzzv
  223.  
  224. if exists("*fugitive#statusline")
  225.   set statusline+=%{fugitive#statusline()}
  226. endif
  227.  
  228. " vim-airline
  229. let g:airline_theme = 'powerlineish'
  230. let g:airline#extensions#branch#enabled = 1
  231. let g:airline#extensions#ale#enabled = 1
  232. let g:airline#extensions#tabline#enabled = 1
  233. let g:airline#extensions#tagbar#enabled = 1
  234. let g:airline_skip_empty_sections = 1
  235.  
  236. "*****************************************************************************
  237. "" Abbreviations
  238. "*****************************************************************************
  239. "" no one is really happy until you have this shortcuts
  240. cnoreabbrev W! w!
  241. cnoreabbrev Q! q!
  242. cnoreabbrev Qall! qall!
  243. cnoreabbrev Wq wq
  244. cnoreabbrev Wa wa
  245. cnoreabbrev wQ wq
  246. cnoreabbrev WQ wq
  247. cnoreabbrev W w
  248. cnoreabbrev Q q
  249. cnoreabbrev Qall qall
  250.  
  251. "" NERDTree configuration
  252. let g:NERDTreeChDirMode=2
  253. let g:NERDTreeIgnore=['node_modules','\.rbc$', '\~$', '\.pyc$', '\.db$', '\.sqlite$', '__pycache__']
  254. let g:NERDTreeSortOrder=['^__\.py$', '\/$', '*', '\.swp$', '\.bak$', '\~$']
  255. let g:NERDTreeShowBookmarks=1
  256. let g:nerdtree_tabs_focus_on_files=1
  257. let g:NERDTreeMapOpenInTabSilent = '<RightMouse>'
  258. let g:NERDTreeWinSize = 50
  259. set wildignore+=*/tmp/*,*.so,*.swp,*.zip,*.pyc,*.db,*.sqlite,*node_modules/
  260. nnoremap <silent> <F2> :NERDTreeFind<CR>
  261. nnoremap <silent> <F3> :NERDTreeToggle<CR>
  262.  
  263. " grep.vim
  264. nnoremap <silent> <leader>f :Rgrep<CR>
  265. let Grep_Default_Options = '-IR'
  266. let Grep_Skip_Files = '*.log *.db'
  267. let Grep_Skip_Dirs = '.git node_modules'
  268.  
  269. " terminal emulation
  270. nnoremap <silent> <leader>sh :terminal<CR>
  271.  
  272. "*****************************************************************************
  273. "" Commands
  274. "*****************************************************************************
  275. " remove trailing whitespaces
  276. command! FixWhitespace :%s/\s\+$//e
  277.  
  278. "*****************************************************************************
  279. "" Functions
  280. "*****************************************************************************
  281. "if !exists('*s:setupWrapping')
  282. "  function s:setupWrapping()
  283. "    set wrap
  284. "    set wm=2
  285. "    set textwidth=79
  286. "  endfunction
  287. "endif
  288.  
  289. "*****************************************************************************
  290. "" Autocmd Rules
  291. "*****************************************************************************
  292. "" The PC is fast enough, do syntax highlight syncing from start unless 200 lines
  293. augroup vimrc-sync-fromstart
  294.   autocmd!
  295.   autocmd BufEnter * :syntax sync maxlines=200
  296. augroup END
  297.  
  298. "" Remember cursor position
  299. augroup vimrc-remember-cursor-position
  300.   autocmd!
  301.   autocmd BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g`\"" | endif
  302. augroup END
  303.  
  304.  
  305. "" make/cmake
  306. augroup vimrc-make-cmake
  307.   autocmd!
  308.   autocmd FileType make setlocal noexpandtab
  309.   autocmd BufNewFile,BufRead CMakeLists.txt setlocal filetype=cmake
  310. augroup END
  311.  
  312. set autoread
  313.  
  314. "*****************************************************************************
  315. "" Mappings
  316. "*****************************************************************************
  317.  
  318. "" Split
  319. noremap <Leader>h :<C-u>split<CR>
  320. noremap <Leader>j :<C-u>vsplit<CR>
  321.  
  322. "" Git
  323. noremap <Leader>ga :Gwrite<CR>
  324. noremap <Leader>gc :Git commit --verbose<CR>
  325. noremap <Leader>gsh :Git push<CR>
  326. noremap <Leader>gll :Git pull<CR>
  327. noremap <Leader>gs :Git<CR>
  328. noremap <Leader>gb :Git blame<CR>
  329. noremap <Leader>gd :Gvdiffsplit<CR>
  330. noremap <Leader>gr :GRemove<CR>
  331.  
  332. " session management
  333. nnoremap <leader>so :OpenSession<Space>
  334. nnoremap <leader>ss :SaveSession<Space>
  335. nnoremap <leader>sd :DeleteSession<CR>
  336. nnoremap <leader>sc :CloseSession<CR>
  337.  
  338. "" Tabs
  339. nnoremap <Tab> gt
  340. nnoremap <S-Tab> gT
  341. nnoremap <silent> <S-t> :tabnew<CR>
  342.  
  343. "" Set working directory
  344. nnoremap <leader>. :lcd %:p:h<CR>
  345.  
  346. "" Opens an edit command with the path of the currently edited file filled in
  347. noremap <Leader>e :e <C-R>=expand("%:p:h") . "/" <CR>
  348.  
  349. "" Opens a tab edit command with the path of the currently edited file filled
  350. noremap <Leader>te :tabe <C-R>=expand("%:p:h") . "/" <CR>
  351.  
  352. "" fzf.vim
  353. set wildmode=list:longest,list:full
  354. set wildignore+=*.o,*.obj,.git,*.rbc,*.pyc,__pycache__
  355. let $FZF_DEFAULT_COMMAND =  "find * -path '*/\.*' -prune -o -path 'node_modules/**' -prune -o -path 'target/**' -prune -o -path 'dist/**' -prune -o  -type f -print -o -type l -print 2> /dev/null"
  356.  
  357. " The Silver Searcher
  358. if executable('ag')
  359.   let $FZF_DEFAULT_COMMAND = 'ag --hidden --ignore .git -g ""'
  360.   set grepprg=ag\ --nogroup\ --nocolor
  361. endif
  362.  
  363. " ripgrep
  364. if executable('rg')
  365.   let $FZF_DEFAULT_COMMAND = 'rg --files --hidden --follow --glob "!.git/*"'
  366.   set grepprg=rg\ --vimgrep
  367.   command! -bang -nargs=* Find call fzf#vim#grep('rg --column --line-number --no-heading --fixed-strings --ignore-case --hidden --follow --glob "!.git/*" --color "always" '.shellescape(<q-args>).'| tr -d "\017"', 1, <bang>0)
  368. endif
  369.  
  370. cnoremap <C-P> <C-R>=expand("%:p:h") . "/" <CR>
  371. nnoremap <silent> <leader>b :Buffers<CR>
  372. nnoremap <silent> <leader>e :FZF -m<CR>
  373. "Recovery commands from history through FZF
  374. nmap <leader>y :History:<CR>
  375.  
  376. " snippets
  377. let g:UltiSnipsExpandTrigger="<tab>"
  378. let g:UltiSnipsJumpForwardTrigger="<tab>"
  379. let g:UltiSnipsJumpBackwardTrigger="<c-b>"
  380. let g:UltiSnipsEditSplit="vertical"
  381.  
  382. " ale
  383. let g:ale_linters = {}
  384.  
  385. " Tagbar
  386. nmap <silent> <F4> :TagbarToggle<CR>
  387. let g:tagbar_autofocus = 1
  388.  
  389. " Disable visualbell
  390. set noerrorbells visualbell t_vb=
  391. if has('autocmd')
  392.   autocmd GUIEnter * set visualbell t_vb=
  393. endif
  394.  
  395. "" Copy/Paste/Cut
  396. if has('unnamedplus')
  397.   set clipboard=unnamed,unnamedplus
  398. endif
  399.  
  400. noremap YY "+y<CR>
  401. noremap <leader>p "+gP<CR>
  402. noremap XX "+x<CR>
  403.  
  404. if has('macunix')
  405.   " pbcopy for OSX copy/paste
  406.   vmap <C-x> :!pbcopy<CR>
  407.   vmap <C-c> :w !pbcopy<CR><CR>
  408. endif
  409.  
  410. "" Buffer nav
  411. noremap <leader>z :bp<CR>
  412. noremap <leader>q :bp<CR>
  413. noremap <leader>x :bn<CR>
  414. noremap <leader>w :bn<CR>
  415.  
  416. "" Close buffer
  417. noremap <leader>c :bd<CR>
  418.  
  419. "" Clean search (highlight)
  420. nnoremap <silent> <leader><space> :noh<cr>
  421.  
  422. "" Switching windows
  423. noremap <C-j> <C-w>j
  424. noremap <C-k> <C-w>k
  425. noremap <C-l> <C-w>l
  426. noremap <C-h> <C-w>h
  427.  
  428. "" Vmap for maintain Visual Mode after shifting > and <
  429. vmap < <gv
  430. vmap > >gv
  431.  
  432. "" Move visual block
  433. vnoremap J :m '>+1<CR>gv=gv
  434. vnoremap K :m '<-2<CR>gv=gv
  435.  
  436. "" Open current line on GitHub
  437. nnoremap <Leader>o :.Gbrowse<CR>
  438.  
  439. "*****************************************************************************
  440. "" Custom configs
  441. "*****************************************************************************
  442.  
  443. " go
  444. " vim-go
  445. " run :GoBuild or :GoTestCompile based on the go file
  446. function! s:build_go_files()
  447.   let l:file = expand('%')
  448.   if l:file =~# '^\f\+_test\.go$'
  449.     call go#test#Test(0, 1)
  450.   elseif l:file =~# '^\f\+\.go$'
  451.     call go#cmd#Build(0)
  452.   endif
  453. endfunction
  454.  
  455. let g:go_list_type = "quickfix"
  456. let g:go_fmt_command = "goimports"
  457. let g:go_fmt_fail_silently = 1
  458.  
  459. let g:go_highlight_types = 1
  460. let g:go_highlight_fields = 1
  461. let g:go_highlight_functions = 1
  462. let g:go_highlight_methods = 1
  463. let g:go_highlight_operators = 1
  464. let g:go_highlight_build_constraints = 1
  465. let g:go_highlight_structs = 1
  466. let g:go_highlight_generate_tags = 1
  467. let g:go_highlight_space_tab_error = 0
  468. let g:go_highlight_array_whitespace_error = 0
  469. let g:go_highlight_trailing_whitespace_error = 0
  470. let g:go_highlight_extra_types = 1
  471.  
  472. autocmd BufNewFile,BufRead *.go setlocal noexpandtab tabstop=4 shiftwidth=4 softtabstop=4
  473.  
  474. " Enable lsp for go by using gopls
  475. let g:completor_filetype_map = {}
  476. let g:completor_filetype_map.go = {'ft': 'lsp', 'cmd': 'gopls -remote=auto'}"
  477.  
  478. augroup completion_preview_close
  479.   autocmd!
  480.   if v:version > 703 || v:version == 703 && has('patch598')
  481.     autocmd CompleteDone * if !&previewwindow && &completeopt =~ 'preview' | silent! pclose | endif
  482.   endif
  483. augroup END
  484.  
  485. augroup go
  486.  
  487.   au!
  488.   au Filetype go command! -bang A call go#alternate#Switch(<bang>0, 'edit')
  489.   au Filetype go command! -bang AV call go#alternate#Switch(<bang>0, 'vsplit')
  490.   au Filetype go command! -bang AS call go#alternate#Switch(<bang>0, 'split')
  491.   au Filetype go command! -bang AT call go#alternate#Switch(<bang>0, 'tabe')
  492.  
  493.   au FileType go nmap <Leader>dd <Plug>(go-def-vertical)
  494.   au FileType go nmap <Leader>dv <Plug>(go-doc-vertical)
  495.   au FileType go nmap <Leader>db <Plug>(go-doc-browser)
  496.  
  497.   au FileType go nmap <leader>r  <Plug>(go-run)
  498.   au FileType go nmap <leader>n  <Plug>(go-build)
  499.   au FileType go nmap <leader>t  <Plug>(go-test)
  500.   au FileType go nmap <leader>v  <Plug>(go-vet)
  501.   au FileType go nmap <Leader>gt <Plug>(go-coverage-toggle)
  502.   au FileType go nmap <Leader>i <Plug>(go-info)
  503.   au FileType go nmap <silent> <Leader>l <Plug>(go-metalinter)
  504.   au FileType go nmap <C-g> :GoDecls<cr>
  505.   au FileType go nmap <leader>dr :GoDeclsDir<cr>
  506.   au FileType go imap <C-g> <esc>:<C-u>GoDecls<cr>
  507.   au FileType go imap <leader>dr <esc>:<C-u>GoDeclsDir<cr>
  508.   au FileType go nmap <leader>rb :<C-u>call <SID>build_go_files()<CR>
  509.  
  510. augroup END
  511.  
  512. " ale
  513. :call extend(g:ale_linters, {
  514.     \"go": ['golint', 'go vet'], })
  515.  
  516.  
  517. " lua
  518.  
  519.  
  520.  
  521. "*****************************************************************************
  522. "*****************************************************************************
  523.  
  524. "" Include user's local vim config
  525. if filereadable(expand("~/.vimrc.local"))
  526.  source ~/.vimrc.local
  527. endif
  528.  
  529. "*****************************************************************************
  530. "" Convenience variables
  531. "*****************************************************************************
  532.  
  533. " vim-airline
  534. if !exists('g:airline_symbols')
  535.  let g:airline_symbols = {}
  536. endif
  537.  
  538. if !exists('g:airline_powerline_fonts')
  539.  let g:airline#extensions#tabline#left_sep = ' '
  540.  let g:airline#extensions#tabline#left_alt_sep = '|'
  541.  let g:airline_left_sep          = ''
  542.  let g:airline_left_alt_sep      = '»'
  543.  let g:airline_right_sep         = ''
  544.  let g:airline_right_alt_sep     = '«'
  545.  let g:airline#extensions#branch#prefix     = '' "➔, ➥, ⎇
  546.  let g:airline#extensions#readonly#symbol   = ''
  547.  let g:airline#extensions#linecolumn#prefix = ''
  548.  let g:airline#extensions#paste#symbol      = 'ρ'
  549.  let g:airline_symbols.linenr    = ''
  550.  let g:airline_symbols.branch    = ''
  551.  let g:airline_symbols.paste     = 'ρ'
  552.  let g:airline_symbols.paste     = 'Þ'
  553.  let g:airline_symbols.paste     = ''
  554.  let g:airline_symbols.whitespace = 'Ξ'
  555. else
  556.  let g:airline#extensions#tabline#left_sep = ''
  557.  let g:airline#extensions#tabline#left_alt_sep = ''
  558.  
  559.  " powerline symbols
  560.  let g:airline_left_sep = ''
  561.  let g:airline_left_alt_sep = ''
  562.  let g:airline_right_sep = ''
  563.  let g:airline_right_alt_sep = ''
  564.  let g:airline_symbols.branch = ''
  565.  let g:airline_symbols.readonly = ''
  566.  let g:airline_symbols.linenr = ''
  567. endif
  568. let timeoutlen = 200
  569.  
Advertisement
Add Comment
Please, Sign In to add comment