Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
3,012
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VIM 16.13 KB | None | 0 0
  1. " Vim-PLug Core {{{
  2. "*****************************************************************************
  3. let vimplug_exists=expand('~/.config/nvim/autoload/plug.vim')
  4.  
  5. if !filereadable(vimplug_exists)
  6.   if !executable("curl")
  7.     echoerr "You have to install curl or first install vim-plug yourself!"
  8.     execute "q!"
  9.   endif
  10.   echo "Installing Vim-Plug..."
  11.   echo ""
  12.   silent exec "!\curl -fLo " . vimplug_exists . " --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim"
  13.   let g:not_finish_vimplug = "yes"
  14.  
  15.   autocmd VimEnter * PlugInstall
  16. endif
  17.  
  18. " Required:
  19. call plug#begin(expand('~/.config/nvim/plugged'))
  20. " }}}
  21. " Plug install packages {{{
  22. "*****************************************************************************
  23. Plug 'scrooloose/nerdtree'
  24. Plug 'scrooloose/nerdcommenter'
  25. Plug 'tpope/vim-surround'
  26. Plug 'airblade/vim-gitgutter'
  27. Plug 'Raimondi/delimitMate'
  28. Plug 'w0rp/ale'
  29. Plug 'sheerun/vim-polyglot'
  30. Plug 'neoclide/coc.nvim', {'branch': 'release'}
  31. Plug 'ryanoasis/vim-devicons'
  32. Plug 'heavenshell/vim-jsdoc'
  33. Plug 'majutsushi/tagbar'
  34. Plug 'tpope/vim-fugitive'
  35. Plug 'mhinz/vim-startify'
  36. Plug 'wellle/targets.vim'
  37. Plug 'rhysd/git-messenger.vim'
  38. Plug 'dracula/vim',{'name':'dracula'}
  39.  
  40. if isdirectory('/usr/local/opt/fzf')
  41.   Plug '/usr/local/opt/fzf' | Plug 'junegunn/fzf.vim'
  42. else
  43.   Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --bin' }
  44.   Plug 'junegunn/fzf.vim'
  45. endif
  46. let g:make = 'gmake'
  47. if exists('make')
  48.   let g:make = 'make'
  49. endif
  50. Plug 'Shougo/vimproc.vim', {'do': g:make}
  51.  
  52. "" Snippets
  53. Plug 'SirVer/ultisnips'
  54. Plug 'honza/vim-snippets'
  55. " }}}
  56. " Custom bundles {{{
  57. "*****************************************************************************
  58.  
  59. " html
  60. "" HTML Bundle
  61. Plug 'hail2u/vim-css3-syntax'
  62. "Plug 'gorodinskiy/vim-coloresque'
  63. Plug 'tpope/vim-haml'
  64. Plug 'mattn/emmet-vim'
  65.  
  66.  
  67. " javascript
  68. "" Javascript Bundle
  69. Plug 'jelera/vim-javascript-syntax'
  70.  
  71. "" Include user's extra bundle
  72. if filereadable(expand("~/.config/nvim/local_bundles.vim"))
  73.  source ~/.config/nvim/local_bundles.vim
  74. endif
  75.  
  76. call plug#end()
  77.  
  78. " Required:
  79. filetype plugin indent on
  80.  
  81. " }}}
  82. " Basic Setup {{{
  83. "*****************************************************************************"
  84. "" Sync and syntax refresh stuff
  85. syntax sync fromstart
  86. set redrawtime=10000
  87.  
  88. "" Encoding
  89. set encoding=utf-8
  90. set fileencoding=utf-8
  91. set fileencodings=utf-8
  92.  
  93. "" Disable soft wrapping
  94. set wrap!
  95.  
  96. "" automatically mkview and loadview on exit/open
  97. "" TODO: fix when using things like CTRL+P
  98. "" au BufWinLeave * mkview
  99. "" au BufWinEnter * silent loadview
  100.  
  101. "" Marker fold method
  102. set foldmethod=marker
  103.  
  104. "" Enable line numbers
  105. set number
  106.  
  107. "" Highlight the line on which the cursor lives
  108. set nocursorline
  109.  
  110. "" Map leader to ,
  111. let mapleader=' '
  112.  
  113. " Always show at least one line above/below the cursor.
  114. set scrolloff=2
  115. " Always show at least one line left/right of the cursor.
  116. set sidescrolloff=5
  117.  
  118. " Highlight matching pairs of brackets. Use the '%' character to jump between them.
  119. set matchpairs+=<:>
  120.  
  121. " Display different types of white spaces.
  122. set list
  123. set listchars=tab:›\ ,trail:•,extends:#,nbsp:.
  124.  
  125. " Use system clipboard
  126. set clipboard=unnamedplus
  127.  
  128. " Remove timeout for partially typed commands
  129. set notimeout
  130.  
  131. " F keys
  132. " Quick write session with F2
  133. map <F2> :mksession! ~/.vim_session<cr>
  134. " And load session with F3
  135. map <F3> :source ~/.vim_session<cr>
  136.  
  137. " Fix indentation
  138. map <F7> gg=G<C-o><C-o>
  139. " Toggle auto change directory
  140. map <F8> :set autochdir! autochdir?<CR>
  141.  
  142. " Indentation
  143. set smarttab
  144. set expandtab
  145. set tabstop=2
  146. set softtabstop=4
  147. set shiftwidth=2
  148.  
  149. "set smartindent
  150. set autoindent
  151. "set cindent
  152.  
  153. set nocompatible
  154. filetype plugin indent on
  155.  
  156. " Relative line numbers
  157. set number relativenumber
  158.  
  159. " Toggle vertical line
  160. set colorcolumn=
  161. set cc=
  162. fun! ToggleCC()
  163.  if &cc == ''
  164.    " set cc=1,4,21
  165.    set cc=80
  166.  else
  167.    set cc=
  168.  endif
  169. endfun
  170. nnoremap <silent> <F9> :call ToggleCC()<CR>
  171.  
  172. " Allow switching between buffers without saving
  173. set hidden
  174.  
  175. " Mouse support
  176. set mouse=a
  177.  
  178. "Case insensitive searching
  179. set ignorecase
  180.  
  181. "Will automatically switch to case sensitive if you use any capitals
  182. set smartcase
  183.  
  184. " Auto toggle smart case of for ex commands
  185. " Assumes 'set ignorecase smartcase'
  186. augroup dynamic_smartcase
  187.  autocmd!
  188.  autocmd CmdLineEnter : set nosmartcase
  189.  autocmd CmdLineLeave : set smartcase
  190. augroup END
  191.  
  192. " Substitute live preview
  193. set inccommand=nosplit
  194.  
  195. " Highlighted yank (-1 for persistent)
  196. let g:highlightedyank_highlight_duration = 400
  197.  
  198. " If lightline/airline is enabled, don't show mode under it
  199. set noshowmode
  200.  
  201. set fileformats=unix,dos,mac
  202.  
  203. if exists('$SHELL')
  204.   set shell=$SHELL
  205. else
  206.   set shell=/bin/sh
  207. endif
  208.  
  209. set background=dark
  210. syntax enable
  211.  
  212. " Clear search highlighting with Escape key
  213. nnoremap <silent><esc> :noh<return><esc>
  214.  
  215. " Allow color schemes to do bright colors without forcing bold.
  216. if &t_Co == 8 && $TERM !~# '^linux\|^Eterm'
  217.   set t_Co=16
  218. endif
  219.  
  220. set wildmenu
  221.  
  222. " remove trailing whitespaces
  223. command! FixWhitespace :%s/\s\+$//e
  224.  
  225. " Restore last cursor position and marks on open
  226. au BufReadPost *
  227.       \ if line("'\"") > 1 && line("'\"") <= line("$") && &ft !~# 'commit'
  228.       \ |   exe "normal! g`\""
  229.       \ | endif
  230.  
  231. " }}}
  232. " NERD Tree {{{
  233. "*****************************************************************************
  234.  
  235. "" NERDTree configuration
  236. let g:NERDTreeChDirMode=2
  237. let g:NERDTreeIgnore=['\.rbc$', '\~$', '\.pyc$', '\.db$', '\.sqlite$', '__pycache__']
  238. let g:NERDTreeSortOrder=['^__\.py$', '\/$', '*', '\.swp$', '\.bak$', '\~$']
  239. let g:NERDTreeShowBookmarks=1
  240. let g:nerdtree_tabs_focus_on_files=1
  241. let g:NERDTreeMapOpenInTabSilent = '<RightMouse>'
  242. let g:NERDTreeWinSize = 35
  243. let NERDTreeMinimalUI=1
  244. set wildignore+=*/tmp/*,*.so,*.swp,*.zip,*.pyc,*.db,*.sqlite
  245. nnoremap <silent> <C-b> :NERDTreeToggle<CR>
  246. nnoremap <silent> <leader>doc :JsDoc<CR>
  247.  
  248. "" NERDTree + Startify
  249.  "autocmd VimEnter *
  250.   "\   if !argc()
  251.   "\ |   Startify
  252.   "\ |   NERDTree
  253.   "\ |   wincmd w
  254.  " \ | endif
  255.  
  256. " grep.vim
  257. nnoremap <silent> <leader>s :Rgrep<CR>
  258. let Grep_Default_Options = '-IR'
  259. let Grep_Skip_Files = '*.log *.db'
  260. let Grep_Skip_Dirs = '.git node_modules'
  261.  
  262. " terminal emulation
  263. nnoremap <silent> <leader>sh :terminal<CR>
  264.  
  265. " }}}
  266. " Mappings {{{
  267. "*****************************************************************************
  268. "" allows navigating soft wraps with j and k but 10j still uses lines
  269. nnoremap <expr> j v:count ? 'j' : 'gj'
  270. nnoremap <expr> k v:count ? 'k' : 'gk'
  271.  
  272. "" Quick exit insert mode with jk
  273. inoremap jk <ESC>
  274.  
  275. "" Split
  276. noremap <Leader>h :<C-u>split<CR>
  277. noremap <Leader>v :<C-u>vsplit<CR>
  278. set splitbelow
  279. set splitright
  280.  
  281. "" Tabs
  282. nnoremap <C-Left>  :tabprevious<CR>
  283. nnoremap <C-Right> :tabnext<CR>
  284. nnoremap <C-t>     :e<CR>
  285.  
  286. "" Set working directory
  287. nnoremap <leader>. :lcd %:p:h<CR>
  288.  
  289. "" Opens an edit command with the path of the currently edited file filled in
  290. noremap <Leader>e :e <C-R>=expand("%:p:h") . "/" <CR>
  291.  
  292. "" Opens a tab edit command with the path of the currently edited file filled
  293. noremap <Leader>te :tabe <C-R>=expand("%:p:h") . "/" <CR>
  294.  
  295. "" Tag bar
  296. nmap <Leader># :TagbarToggle<CR>
  297.  
  298. " }}}
  299. " Plugin-specific Settings {{{
  300. "*****************************************************************************
  301. "" fzf.vim
  302. set wildmode=list:longest,list:full
  303. set wildignore+=*.o,*.obj,.git,*.rbc,*.pyc,__pycache__
  304. 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"
  305. let $FZF_DEFAULT_OPTS=' --color=dark --color=fg:15,bg:-1,hl:1,fg+:#ffffff,bg+:0,hl+:1 --color=info:0,prompt:0,pointer:12,marker:4,spinner:11,header:-1 --layout=reverse  --margin=1,4'
  306. let g:fzf_layout = { 'window': 'call FloatingFZF()' }
  307.  
  308. function! FloatingFZF()
  309.   let buf = nvim_create_buf(v:false, v:true)
  310.   call setbufvar(buf, '&signcolumn', 'no')
  311.  
  312.   let height = float2nr(10)
  313.   let width = float2nr(80)
  314.   let horizontal = float2nr((&columns - width) / 2)
  315.   let vertical = 1
  316.  
  317.   let opts = {
  318.         \ 'relative': 'editor',
  319.         \ 'row': vertical,
  320.         \ 'col': horizontal,
  321.         \ 'width': width,
  322.         \ 'height': height,
  323.         \ 'style': 'minimal'
  324.         \ }
  325.  
  326.   call nvim_open_win(buf, v:true, opts)
  327. endfunction
  328.  
  329. " Startify
  330. let g:startify_bookmarks=['~/.bashrc', '~/.config/nvim/init.vim', '~/.config/awesome', '~/Projects']
  331. let g:startify_lists = [
  332.           \ { 'type': 'sessions',  'header': ['   Sessions']       },
  333.           \ { 'type': 'files',     'header': ['   Recent Files']   },
  334.           \ { 'type': 'dir',       'header': ['   Recent Files in: '. getcwd()] },
  335.           \ { 'type': 'bookmarks', 'header': ['   Bookmarks']      },
  336.           \ { 'type': 'commands',  'header': ['   Commands']       },
  337.           \ ]
  338.  
  339. let g:startify_custom_header = systemlist('motivate --no-colors')
  340.  
  341. cnoremap <C-P> <C-R>=expand("%:p:h") . "/" <CR>
  342. nnoremap <silent> <leader>b :Buffers<CR>
  343. nnoremap <silent> <C-o> :Buffers<CR>
  344. nnoremap <silent> <C-f> :BLines<CR>
  345. nnoremap <silent> <leader>f :Lines<CR>
  346. nnoremap <silent> <leader>t :BTags<CR>
  347. nnoremap <silent> <C-p> :call fzf#vim#files('.', {'options': '--prompt ""'})<CR>
  348. "Recovery commands from history through FZF
  349. nmap <leader>y :History:<CR>
  350.  
  351. " snippets
  352. let g:UltiSnipsExpandTrigger="<tab>"
  353. let g:UltiSnipsJumpForwardTrigger="<tab>"
  354. let g:UltiSnipsJumpBackwardTrigger="<c-b>"
  355. let g:UltiSnipsEditSplit="vertical"
  356.  
  357. " ale
  358. let g:ale_sign_highlight_linenrs = 1
  359. let g:ale_linters = {}
  360. let g:ale_sign_error = ""
  361. let g:ale_sign_warning = ""
  362. let g:airline#extensions#ale#enabled = 1
  363. let g:formatdef_eslint = '"eslint-formatter"'
  364. let g:formatters_javascript = ['prettier', 'eslint']
  365. let g:ale_fix_on_save = 1
  366. let g:ale_fixers = {'javascript': ['eslint'], 'json': ['jq'], 'html': ['prettier'] }
  367. let g:ale_set_highlights = 0
  368. let g:ale_lint_on_text_changed = 'always'
  369. let g:ale_sign_column_always = 1
  370. let g:ale_echo_cursor = 1
  371. nmap <F5> <Plug>(ale_fix)
  372.  
  373. " vim workspace
  374. let g:workspace_session_directory = $HOME . '/.vim/sessions/'
  375.  
  376. " vim-devicons
  377. let g:webdevicons_enable = 1
  378. let g:webdevicons_enable_nerdtree = 1
  379. let g:webdevicons_enable_airline_statusline = 1
  380. let g:webdevicons_enable_airline_tabline = 1
  381. let g:WebDevIconsNerdTreeGitPluginForceVAlign = 1
  382.  
  383. " Disable visualbell
  384. set noerrorbells visualbell t_vb=
  385. if has('autocmd')
  386.   autocmd GUIEnter * set visualbell t_vb=
  387. endif
  388.  
  389. "" Copy/Paste/Cut
  390. if has('unnamedplus')
  391.   set clipboard=unnamed,unnamedplus
  392. endif
  393.  
  394. noremap YY "+y<CR>
  395. noremap <leader>p "+gP<CR>
  396. noremap XX "+x<CR>
  397.  
  398. if has('macunix')
  399.   " pbcopy for OSX copy/paste
  400.   vmap <C-x> :!pbcopy<CR>
  401.   vmap <C-c> :w !pbcopy<CR><CR>
  402. endif
  403.  
  404. "" Buffer nav
  405. noremap <leader>z :bp<CR>
  406. noremap <leader>q :bp<CR>
  407. noremap <leader>x :bn<CR>
  408. noremap <leader>w :bn<CR>
  409.  
  410. "" Close buffer
  411. noremap <leader>c :bd<CR>
  412.  
  413. "" Clean search (highlight)
  414. nnoremap <silent> <leader><space> :noh<cr>
  415.  
  416. "" Switching windows
  417. noremap <C-j> <C-w>j
  418. noremap <C-k> <C-w>k
  419. noremap <C-l> <C-w>l
  420. noremap <C-h> <C-w>h
  421.  
  422. "" Vmap for maintain Visual Mode after shifting > and <
  423. vmap < <gv
  424. vmap > >gv
  425.  
  426. "" Move visual block
  427. vnoremap J :m '>+1<CR>gv=gv
  428. vnoremap K :m '<-2<CR>gv=gv
  429.  
  430. " }}}
  431. " Coc-specific Settings {{{
  432. "*****************************************************************************
  433.  
  434. let g:airline#extensions#coc#enabled = 1
  435.  
  436. " if hidden is not set, TextEdit might fail.
  437. set hidden
  438.  
  439. " Some servers have issues with backup files, see #649
  440. set nobackup
  441. set nowritebackup
  442.  
  443. " Better display for messages
  444. set cmdheight=1
  445.  
  446. " You will have bad experience for diagnostic messages when it's default 4000.
  447. set updatetime=300
  448.  
  449. " don't give |ins-completion-menu| messages.
  450. set shortmess+=c
  451.  
  452. " always show signcolumns
  453. set signcolumn=yes
  454.  
  455. " Use tab for trigger completion with characters ahead and navigate.
  456. " Use command ':verbose imap <tab>' to make sure tab is not mapped by other plugin.
  457. inoremap <silent><expr> <TAB>
  458.       \ pumvisible() ? "\<C-n>" :
  459.       \ <SID>check_back_space() ? "\<TAB>" :
  460.       \ coc#refresh()
  461. inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"
  462.  
  463. function! s:check_back_space() abort
  464.   let col = col('.') - 1
  465.   return !col || getline('.')[col - 1]  =~# '\s'
  466. endfunction
  467.  
  468. " Use <c-space> to trigger completion.
  469. inoremap <silent><expr> <c-space> coc#refresh()
  470.  
  471. " Use <cr> to confirm completion, `<C-g>u` means break undo chain at current position.
  472. " Coc only does snippet and additional edit on confirm.
  473. inoremap <expr> <cr> pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>"
  474.  
  475. " Use `[c` and `]c` to navigate diagnostics
  476. nmap <silent> [c <Plug>(coc-diagnostic-prev)
  477. nmap <silent> ]c <Plug>(coc-diagnostic-next)
  478.  
  479. " Remap keys for gotos
  480. nmap <silent> gd <Plug>(coc-definition)
  481. nmap <silent> gy <Plug>(coc-type-definition)
  482. nmap <silent> gi <Plug>(coc-implementation)
  483. nmap <silent> gr <Plug>(coc-references)
  484.  
  485. " Use K to show documentation in preview window
  486. nnoremap <silent> K :call <SID>show_documentation()<CR>
  487.  
  488. function! s:show_documentation()
  489.   if (index(['vim','help'], &filetype) >= 0)
  490.     execute 'h '.expand('<cword>')
  491.   else
  492.     call CocAction('doHover')
  493.   endif
  494. endfunction
  495.  
  496. " Highlight symbol under cursor on CursorHold
  497. " autocmd CursorHold * silent call CocActionAsync('highlight')
  498.  
  499. " Remap for rename current word
  500. nmap <leader>rn <Plug>(coc-rename)
  501.  
  502. " Remap for format selected region
  503. xmap <leader>format  <Plug>(coc-format-selected)
  504. nmap <leader>format  <Plug>(coc-format-selected)
  505.  
  506. augroup mygroup
  507.   autocmd!
  508.   " Setup formatexpr specified filetype(s).
  509.   autocmd FileType typescript,json setl formatexpr=CocAction('formatSelected')
  510.   " Update signature help on jump placeholder
  511.   autocmd User CocJumpPlaceholder call CocActionAsync('showSignatureHelp')
  512. augroup end
  513.  
  514. " Remap for do codeAction of selected region, ex: `<leader>aap` for current paragraph
  515. xmap <leader>a  <Plug>(coc-codeaction-selected)
  516. nmap <leader>a  <Plug>(coc-codeaction-selected)
  517.  
  518. " Remap for do codeAction of current line
  519. nmap <leader>ac  <Plug>(coc-codeaction)
  520. " Fix autofix problem of current line
  521. nmap <leader>qf  <Plug>(coc-fix-current)
  522.  
  523. " Use `:Format` to format current buffer
  524. command! -nargs=0 Format :call CocAction('format')
  525.  
  526. " Use `:Fold` to fold current buffer
  527. command! -nargs=? Fold :call     CocAction('fold', <f-args>)
  528.  
  529. " use `:OR` for organize import of current buffer
  530. command! -nargs=0 OR   :call     CocAction('runCommand', 'editor.action.organizeImport')
  531.  
  532. " Add status line support, for integration with other plugin, checkout `:h coc-status`
  533. set statusline^=%{coc#status()}%{get(b:,'coc_current_function','')}
  534.  
  535. " Using CocList
  536. " Show all diagnostics
  537. "nnoremap <silent> <space>a  :<C-u>CocList diagnostics<cr>
  538. " Manage extensions
  539. "nnoremap <silent> <space>e  :<C-u>CocList extensions<cr>
  540. " Show commands
  541. "nnoremap <silent> <space>c  :<C-u>CocList commands<cr>
  542. " Find symbol of current document
  543. "nnoremap <silent> <space>o  :<C-u>CocList outline<cr>
  544. " Search workspace symbols
  545. "nnoremap <silent> <space>s  :<C-u>CocList -I symbols<cr>
  546. " Do default action for next item.
  547. "nnoremap <silent> <space>j  :<C-u>CocNext<CR>
  548. " Do default action for previous item.
  549. "nnoremap <silent> <space>k  :<C-u>CocPrev<CR>
  550. " Resume latest coc list
  551. "nnoremap <silent> <space>p  :<C-u>CocListResume<CR>
  552.  
  553. " }}}
  554. " Theme {{{
  555. "*****************************************************************************
  556. " Colorscheme
  557. "if empty($DISPLAY)
  558.   "colorscheme lena
  559.   "else
  560.   "colorscheme onehalfdark
  561. "endif
  562. colorscheme ephemanord
  563. "colorscheme dracula
  564. set fillchars=vert::
  565.  
  566. source $HOME/.config/nvim/statusline.vim
  567.  
  568. " }}}
  569. " AutoCMDs {{{
  570. "*****************************************************************************
  571. command! -complete=customlist,s:project_complete -nargs=1 Project cd <args>
  572.  
  573. function! s:project_complete(lead, cmdline, _) abort
  574.   let results = keys(get(g:, 'PROJECTS', {}))
  575.  
  576.   " use projectionist if available
  577.   if exists('*projectionist#completion_filter')
  578.     return projectionist#completion_filter(results, a:lead, '/')
  579.   endif
  580.  
  581.   " fallback to cheap fuzzy matching
  582.   let regex = substitute(a:lead, '.', '[&].*', 'g')
  583.   return filter(results, 'v:val =~ regex')
  584. endfunction
  585.  
  586. " }}}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement