Repository für den Vim Workshop in der O-Phase 2019
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.

205 lines
6.9 KiB

  1. set nocompatible " be iMproved, required
  2. filetype off " required
  3. " Plugins
  4. " Load vim-plug
  5. if empty(glob("~/.config/nvim/autoload/plug.vim"))
  6. execute '!curl -fLo ~/.config/nvim/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim'
  7. endif
  8. call plug#begin()
  9. Plug 'tpope/vim-fugitive' " Git integration
  10. Plug 'tpope/vim-sensible' " Defaults everyone can agree on
  11. Plug 'tpope/vim-surround' " better handling of surrounding markers
  12. Plug 'tpope/vim-ragtag' " Enhancement of surround for html
  13. Plug 'tpope/vim-repeat' " repeat last command with .
  14. Plug 'scrooloose/nerdcommenter' " better commenting
  15. Plug 'neoclide/coc.nvim', {'branch': 'release'} " coc - completion
  16. Plug 'easymotion/vim-easymotion' " better motion with leader
  17. Plug 'bling/vim-airline' " statusline
  18. Plug 'w0rp/ale' " asynchronous linting engine
  19. Plug 'godlygeek/tabular' " Align text on symbols
  20. Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' } " fuzzy file finder
  21. Plug 'junegunn/fzf.vim' " vim integration for fzf
  22. Plug 'airblade/vim-gitgutter' " git status in gutter column
  23. Plug 'honza/vim-snippets' " Collection of Snippets, used by coc-snippet
  24. " All of your Plugins must be added before the following line
  25. call plug#end() " required
  26. filetype plugin indent on " required
  27. " SETTINGS
  28. set number " line numbers
  29. set autoread " reload file automatically
  30. set history=1000
  31. set autoindent " automatically set indent of new line
  32. set smartindent
  33. set tabstop=4
  34. set shiftwidth=4
  35. set expandtab
  36. set ttyfast " faster redrawing
  37. set diffopt+=vertical
  38. set laststatus=2 " show the satus line all the time
  39. set so=7 " set 7 lines to the cursors - when moving vertical
  40. set wildmenu " enhanced command line completion
  41. set hidden " current buffer can be put into background
  42. set showcmd " show incomplete commands
  43. set wildmode=list:longest " complete files like a shell
  44. set scrolloff=3 " lines of text around cursor
  45. set shell=$SHELL
  46. set cmdheight=1 " command bar height
  47. set title " set terminal title
  48. set foldmethod=marker" " folds are marked with {{{}}}
  49. " Uncomment the following to have Vim jump to the last position when
  50. " reopening a file
  51. if has("autocmd")
  52. au BufReadPost * if line("'\"") > 0 && line("'\"") <= line("$")
  53. \| exe "normal! g'\"" | endif
  54. endif
  55. " SETTINGS
  56. let mapleader = ","
  57. " fzf bindings
  58. nmap <C-p> :Files<CR>
  59. nmap <leader><C-p> :Tags<CR>
  60. " Allow saving of files as sudo when I forgot to start vim using sudo.
  61. cmap w!! w !sudo tee > /dev/null %
  62. " Show Infos from ALE in Airline
  63. let g:airline#extensions#ale#enabled = 1
  64. " Completion settings
  65. " if hidden is not set, TextEdit might fail.
  66. set hidden
  67. " Some servers have issues with backup files, see #649
  68. set nobackup
  69. set nowritebackup
  70. " Better display for messages
  71. set cmdheight=2
  72. " You will have bad experience for diagnostic messages when it's default 4000.
  73. set updatetime=300
  74. " don't give |ins-completion-menu| messages.
  75. set shortmess+=c
  76. " always show signcolumns
  77. set signcolumn=yes
  78. " Use tab for trigger completion with characters ahead and navigate.
  79. " Use command ':verbose imap <tab>' to make sure tab is not mapped by other plugin.
  80. inoremap <silent><expr> <TAB>
  81. \ pumvisible() ? "\<C-n>" :
  82. \ <SID>check_back_space() ? "\<TAB>" :
  83. \ coc#refresh()
  84. inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"
  85. function! s:check_back_space() abort
  86. let col = col('.') - 1
  87. return !col || getline('.')[col - 1] =~# '\s'
  88. endfunction
  89. " Use <c-space> to trigger completion.
  90. inoremap <silent><expr> <c-space> coc#refresh()
  91. " Use <cr> to confirm completion, `<C-g>u` means break undo chain at current position.
  92. " Coc only does snippet and additional edit on confirm.
  93. inoremap <expr> <cr> pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>"
  94. " Use `[c` and `]c` to navigate diagnostics
  95. nmap <silent> [c <Plug>(coc-diagnostic-prev)
  96. nmap <silent> ]c <Plug>(coc-diagnostic-next)
  97. " Remap keys for gotos
  98. nmap <silent> gd <Plug>(coc-definition)
  99. nmap <silent> gy <Plug>(coc-type-definition)
  100. nmap <silent> gi <Plug>(coc-implementation)
  101. nmap <silent> gr <Plug>(coc-references)
  102. " Use K to show documentation in preview window
  103. nnoremap <silent> K :call <SID>show_documentation()<CR>
  104. function! s:show_documentation()
  105. if (index(['vim','help'], &filetype) >= 0)
  106. execute 'h '.expand('<cword>')
  107. else
  108. call CocAction('doHover')
  109. endif
  110. endfunction
  111. " Highlight symbol under cursor on CursorHold
  112. autocmd CursorHold * silent call CocActionAsync('highlight')
  113. " Remap for rename current word
  114. nmap <leader>rn <Plug>(coc-rename)
  115. " Remap for format selected region
  116. xmap <leader>f <Plug>(coc-format-selected)
  117. nmap <leader>f <Plug>(coc-format-selected)
  118. augroup mygroup
  119. autocmd!
  120. " Setup formatexpr specified filetype(s).
  121. autocmd FileType typescript,json setl formatexpr=CocAction('formatSelected')
  122. " Update signature help on jump placeholder
  123. autocmd User CocJumpPlaceholder call CocActionAsync('showSignatureHelp')
  124. augroup end
  125. " Remap for do codeAction of selected region, ex: `<leader>aap` for current paragraph
  126. xmap <leader>a <Plug>(coc-codeaction-selected)
  127. nmap <leader>a <Plug>(coc-codeaction-selected)
  128. " Remap for do codeAction of current line
  129. nmap <leader>ac <Plug>(coc-codeaction)
  130. " Fix autofix problem of current line
  131. nmap <leader>qf <Plug>(coc-fix-current)
  132. " Use <tab> for select selections ranges, needs server support, like: coc-tsserver, coc-python
  133. nmap <silent> <TAB> <Plug>(coc-range-select)
  134. xmap <silent> <TAB> <Plug>(coc-range-select)
  135. xmap <silent> <S-TAB> <Plug>(coc-range-select-backword)
  136. " Use `:Format` to format current buffer
  137. command! -nargs=0 Format :call CocAction('format')
  138. " Use `:Fold` to fold current buffer
  139. command! -nargs=? Fold :call CocAction('fold', <f-args>)
  140. " use `:OR` for organize import of current buffer
  141. command! -nargs=0 OR :call CocAction('runCommand', 'editor.action.organizeImport')
  142. " Add status line support, for integration with other plugin, checkout `:h coc-status`
  143. set statusline^=%{coc#status()}%{get(b:,'coc_current_function','')}
  144. " Using CocList
  145. " Show all diagnostics
  146. nnoremap <silent> <space>a :<C-u>CocList diagnostics<cr>
  147. " Manage extensions
  148. nnoremap <silent> <space>e :<C-u>CocList extensions<cr>
  149. " Show commands
  150. nnoremap <silent> <space>c :<C-u>CocList commands<cr>
  151. " Find symbol of current document
  152. nnoremap <silent> <space>o :<C-u>CocList outline<cr>
  153. " Search workspace symbols
  154. nnoremap <silent> <space>s :<C-u>CocList -I symbols<cr>
  155. " Do default action for next item.
  156. nnoremap <silent> <space>j :<C-u>CocNext<CR>
  157. " Do default action for previous item.
  158. nnoremap <silent> <space>k :<C-u>CocPrev<CR>
  159. " Resume latest coc list
  160. nnoremap <silent> <space>p :<C-u>CocListResume<CR>:
  161. " For conceal markers.
  162. if has('conceal')
  163. set conceallevel=2 concealcursor=niv
  164. endif
  165. let g:neosnippet#snippets_directory = '~/.dotfiles/vim/neosnippets'