Advertisement
Guest User

init.vim

a guest
Mar 30th, 2021
468
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VIM 13.93 KB | None | 0 0
  1. " vim-bootstrap
  2.  
  3. "*****************************************************************************
  4. "" Vim-PLug core
  5. "*****************************************************************************
  6. let vimplug_exists=expand('~/.config/nvim/autoload/plug.vim')
  7.  
  8. let g:vim_bootstrap_langs = "html,javascript,php,typescript"
  9. let g:vim_bootstrap_editor = "nvim"             " nvim or vim
  10.  
  11. if !filereadable(vimplug_exists)
  12.   if !executable("curl")
  13.     echoerr "You have to install curl or first install vim-plug yourself!"
  14.     execute "q!"
  15.   endif
  16.   echo "Installing Vim-Plug..."
  17.   echo ""
  18.   silent exec "!\curl -fLo " . vimplug_exists . " --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim"
  19.   let g:not_finish_vimplug = "yes"
  20.  
  21.   autocmd VimEnter * PlugInstall
  22. endif
  23.  
  24. " Required:
  25. call plug#begin(expand('~/.config/nvim/plugged'))
  26.  
  27. "*****************************************************************************
  28. "" Plug install packages
  29. "*****************************************************************************
  30. Plug 'scrooloose/nerdtree'
  31. Plug 'jistr/vim-nerdtree-tabs'
  32. Plug 'tpope/vim-commentary'
  33. Plug 'tpope/vim-fugitive'
  34. Plug 'vim-airline/vim-airline'
  35. Plug 'vim-airline/vim-airline-themes'
  36. Plug 'airblade/vim-gitgutter'
  37. Plug 'vim-scripts/grep.vim'
  38. Plug 'vim-scripts/CSApprox'
  39. Plug 'Raimondi/delimitMate'
  40. Plug 'majutsushi/tagbar'
  41. Plug 'w0rp/ale'
  42. Plug 'Yggdroot/indentLine'
  43. Plug 'avelino/vim-bootstrap-updater'
  44. Plug 'sheerun/vim-polyglot'
  45. Plug 'tpope/vim-rhubarb' " required by fugitive to :Gbrowse
  46.  
  47. if isdirectory('/usr/local/opt/fzf')
  48.   Plug '/usr/local/opt/fzf' | Plug 'junegunn/fzf.vim'
  49. else
  50.   Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --bin' }
  51.   Plug 'junegunn/fzf.vim'
  52. endif
  53. let g:make = 'gmake'
  54. if exists('make')
  55.         let g:make = 'make'
  56. endif
  57. Plug 'Shougo/vimproc.vim', {'do': g:make}
  58.  
  59. "" Vim-Session
  60. Plug 'xolox/vim-misc'
  61. Plug 'xolox/vim-session'
  62.  
  63. "" Snippets
  64. Plug 'SirVer/ultisnips'
  65. Plug 'honza/vim-snippets'
  66.  
  67. "" Color
  68. Plug 'tomasr/molokai'
  69. Plug 'joshdick/onedark.vim'
  70.  
  71. "*****************************************************************************
  72. "" Custom bundles
  73. "*****************************************************************************
  74.  
  75. " html
  76. "" HTML Bundle
  77. Plug 'hail2u/vim-css3-syntax'
  78. Plug 'gorodinskiy/vim-coloresque'
  79. Plug 'tpope/vim-haml'
  80. Plug 'mattn/emmet-vim'
  81.  
  82.  
  83. " javascript
  84. "" Javascript Bundle
  85. Plug 'jelera/vim-javascript-syntax'
  86.  
  87.  
  88. " php
  89. "" PHP Bundle
  90. Plug 'arnaud-lb/vim-php-namespace'
  91.  
  92.  
  93. " typescript
  94. Plug 'leafgarland/typescript-vim'
  95. Plug 'HerringtonDarkholme/yats.vim'
  96.  
  97.  
  98. " vuejs
  99. Plug 'posva/vim-vue'
  100. Plug 'leafOfTree/vim-vue-plugin'
  101.  
  102.  
  103.  
  104. "*****************************************************************************
  105. "*****************************************************************************
  106.  
  107. "" Include user's extra bundle
  108. if filereadable(expand("~/.config/nvim/local_bundles.vim"))
  109.  source ~/.config/nvim/local_bundles.vim
  110. endif
  111.  
  112. call plug#end()
  113.  
  114. " Required:
  115. filetype plugin indent on
  116.  
  117.  
  118. "*****************************************************************************
  119. "" Basic Setup
  120. "*****************************************************************************"
  121. "" Encoding
  122. set encoding=utf-8
  123. set fileencoding=utf-8
  124. set fileencodings=utf-8
  125.  
  126.  
  127. "" Fix backspace indent
  128. set backspace=indent,eol,start
  129.  
  130. "" Tabs. May be overridden by autocmd rules
  131. set tabstop=2
  132. set softtabstop=0
  133. set shiftwidth=2
  134. set expandtab
  135.  
  136. "" Map leader to ,
  137. let mapleader=','
  138.  
  139. "" Enable hidden buffers
  140. set hidden
  141.  
  142. "" Searching
  143. set hlsearch
  144. set incsearch
  145. set ignorecase
  146. set smartcase
  147.  
  148. set fileformats=unix,dos,mac
  149.  
  150. if exists('$SHELL')
  151.    set shell=$SHELL
  152. else
  153.    set shell=/bin/sh
  154. endif
  155.  
  156. " session management
  157. let g:session_directory = "~/.config/nvim/session"
  158. let g:session_autoload = "no"
  159. let g:session_autosave = "no"
  160. let g:session_command_aliases = 1
  161.  
  162. "*****************************************************************************
  163. "" Visual Settings
  164. "*****************************************************************************
  165. syntax on
  166. set ruler
  167. set number
  168.  
  169. let no_buffers_menu=1
  170. silent! colorscheme onedark
  171.  
  172. set mousemodel=popup
  173. set t_Co=256
  174. set guioptions=egmrti
  175. set gfn=Monospace\ 10
  176.  
  177. if has("gui_running")
  178.  if has("gui_mac") || has("gui_macvim")
  179.    set guifont=Menlo:h12
  180.    set transparency=7
  181.  endif
  182. else
  183.  let g:CSApprox_loaded = 1
  184.  
  185.  " IndentLine
  186.  let g:indentLine_enabled = 1
  187.  let g:indentLine_concealcursor = 0
  188.  let g:indentLine_char = ''
  189.  let g:indentLine_faster = 1
  190.  
  191.  
  192. endif
  193.  
  194.  
  195.  
  196. "" Disable the blinking cursor.
  197. set gcr=a:blinkon0
  198. set scrolloff=3
  199.  
  200. "" Status bar
  201. set laststatus=2
  202.  
  203. "" Use modeline overrides
  204. set modeline
  205. set modelines=10
  206.  
  207. set title
  208. set titleold="Terminal"
  209. set titlestring=%F
  210.  
  211. set statusline=%F%m%r%h%w%=(%{&ff}/%Y)\ (line\ %l\/%L,\ col\ %c)\
  212.  
  213. " Search mappings: These will make it so that going to the next one in a
  214. " search will center on the line it's found in.
  215. nnoremap n nzzzv
  216. nnoremap N Nzzzv
  217.  
  218. if exists("*fugitive#statusline")
  219.   set statusline+=%{fugitive#statusline()}
  220. endif
  221.  
  222. " vim-airline
  223. let g:airline_theme = 'onedark'
  224. let g:airline#extensions#branch#enabled = 1
  225. let g:airline#extensions#ale#enabled = 1
  226. let g:airline#extensions#tabline#enabled = 1
  227. let g:airline#extensions#tagbar#enabled = 1
  228. let g:airline_skip_empty_sections = 1
  229.  
  230. "*****************************************************************************
  231. "" Abbreviations
  232. "*****************************************************************************
  233. "" no one is really happy until you have this shortcuts
  234. cnoreabbrev W! w!
  235. cnoreabbrev Q! q!
  236. cnoreabbrev Qall! qall!
  237. cnoreabbrev Wq wq
  238. cnoreabbrev Wa wa
  239. cnoreabbrev wQ wq
  240. cnoreabbrev WQ wq
  241. cnoreabbrev W w
  242. cnoreabbrev Q q
  243. cnoreabbrev Qall qall
  244.  
  245. "" NERDTree configuration
  246. let g:NERDTreeChDirMode=2
  247. let g:NERDTreeIgnore=['\.rbc$', '\~$', '\.pyc$', '\.db$', '\.sqlite$', '__pycache__']
  248. let g:NERDTreeSortOrder=['^__\.py$', '\/$', '*', '\.swp$', '\.bak$', '\~$']
  249. let g:NERDTreeShowBookmarks=1
  250. let g:nerdtree_tabs_focus_on_files=1
  251. let g:NERDTreeMapOpenInTabSilent = '<RightMouse>'
  252. let g:NERDTreeWinSize = 50
  253. set wildignore+=*/tmp/*,*.so,*.swp,*.zip,*.pyc,*.db,*.sqlite
  254. nnoremap <silent> <F2> :NERDTreeFind<CR>
  255. nnoremap <silent> <F3> :NERDTreeToggle<CR>
  256.  
  257. " grep.vim
  258. nnoremap <silent> <leader>f :Rgrep<CR>
  259. let Grep_Default_Options = '-IR'
  260. let Grep_Skip_Files = '*.log *.db'
  261. let Grep_Skip_Dirs = '.git node_modules'
  262.  
  263. " terminal emulation
  264. nnoremap <silent> <leader>sh :terminal<CR>
  265.  
  266.  
  267. "*****************************************************************************
  268. "" Commands
  269. "*****************************************************************************
  270. " remove trailing whitespaces
  271. command! FixWhitespace :%s/\s\+$//e
  272.  
  273. "*****************************************************************************
  274. "" Functions
  275. "*****************************************************************************
  276. if !exists('*s:setupWrapping')
  277.   function s:setupWrapping()
  278.     set wrap
  279.     set wm=2
  280.     set textwidth=79
  281.   endfunction
  282. endif
  283.  
  284. "*****************************************************************************
  285. "" Autocmd Rules
  286. "*****************************************************************************
  287. "" The PC is fast enough, do syntax highlight syncing from start unless 200 lines
  288. augroup vimrc-sync-fromstart
  289.   autocmd!
  290.   autocmd BufEnter * :syntax sync maxlines=200
  291. augroup END
  292.  
  293. "" Remember cursor position
  294. augroup vimrc-remember-cursor-position
  295.   autocmd!
  296.   autocmd BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g`\"" | endif
  297. augroup END
  298.  
  299. "" txt
  300. augroup vimrc-wrapping
  301.   autocmd!
  302.   autocmd BufRead,BufNewFile *.txt call s:setupWrapping()
  303. augroup END
  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>v :<C-u>vsplit<CR>
  321.  
  322. "" Git
  323. noremap <Leader>ga :Gwrite<CR>
  324. noremap <Leader>gc :Gcommit<CR>
  325. noremap <Leader>gsh :Gpush<CR>
  326. noremap <Leader>gll :Gpull<CR>
  327. noremap <Leader>gs :Gstatus<CR>
  328. noremap <Leader>gb :Gblame<CR>
  329. noremap <Leader>gd :Gvdiff<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. " html
  444. " for html files, 2 spaces
  445. autocmd Filetype html setlocal ts=2 sw=2 expandtab
  446.  
  447.  
  448. " javascript
  449. let g:javascript_enable_domhtmlcss = 1
  450.  
  451. " vim-javascript
  452. augroup vimrc-javascript
  453.   autocmd!
  454.   autocmd FileType javascript setl tabstop=4|setl shiftwidth=4|setl expandtab softtabstop=4
  455. augroup END
  456.  
  457.  
  458. " php
  459.  
  460.  
  461. " typescript
  462. let g:yats_host_keyword = 1
  463.  
  464.  
  465.  
  466. " vuejs
  467. " vim vue
  468. let g:vue_disable_pre_processors=1
  469. " vim vue plugin
  470. let g:vim_vue_plugin_load_full_syntax = 1
  471.  
  472.  
  473. "*****************************************************************************
  474. "*****************************************************************************
  475.  
  476. "" Include user's local vim config
  477. if filereadable(expand("~/.config/nvim/local_init.vim"))
  478.  source ~/.config/nvim/local_init.vim
  479. endif
  480.  
  481. "*****************************************************************************
  482. "" Convenience variables
  483. "*****************************************************************************
  484.  
  485. " vim-airline
  486. if !exists('g:airline_symbols')
  487.  let g:airline_symbols = {}
  488. endif
  489.  
  490. if !exists('g:airline_powerline_fonts')
  491.  let g:airline#extensions#tabline#left_sep = ' '
  492.  let g:airline#extensions#tabline#left_alt_sep = '|'
  493.  let g:airline_left_sep          = ''
  494.  let g:airline_left_alt_sep      = '»'
  495.  let g:airline_right_sep         = ''
  496.  let g:airline_right_alt_sep     = '«'
  497.  let g:airline#extensions#branch#prefix     = '' "➔, ➥, ⎇
  498.  let g:airline#extensions#readonly#symbol   = ''
  499.  let g:airline#extensions#linecolumn#prefix = ''
  500.  let g:airline#extensions#paste#symbol      = 'ρ'
  501.  let g:airline_symbols.linenr    = ''
  502.  let g:airline_symbols.branch    = ''
  503.  let g:airline_symbols.paste     = 'ρ'
  504.  let g:airline_symbols.paste     = 'Þ'
  505.  let g:airline_symbols.paste     = ''
  506.  let g:airline_symbols.whitespace = 'Ξ'
  507. else
  508.  let g:airline#extensions#tabline#left_sep = ''
  509.  let g:airline#extensions#tabline#left_alt_sep = ''
  510.  
  511.  " powerline symbols
  512.  let g:airline_left_sep = ''
  513.  let g:airline_left_alt_sep = ''
  514.  let g:airline_right_sep = ''
  515.  let g:airline_right_alt_sep = ''
  516.  let g:airline_symbols.branch = ''
  517.  let g:airline_symbols.readonly = ''
  518.  let g:airline_symbols.linenr = ''
  519. endif
  520.  
  521. " Python path
  522. let g:python_host_prog = '/usr/bin/python2'
  523. let g:python3_host_prog = '/usr/bin/python3'
  524.  
  525. set guicursor=n-v-c-sm:block
  526. set guicursor+=i-ci:block
  527. set guicursor+=i-ci:blinkon175
  528. set guicursor+=ve:ver25
  529. set guicursor+=r-cr-o:hor20
  530.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement