1
0

nvimrc 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  1. " set the runtime path to include Vundle and initialize
  2. call plug#begin('~/.config/nvim/plugged')
  3. Plug 'neoclide/coc.nvim', { 'branch': 'release' }
  4. Plug 'ludovicchabant/vim-gutentags'
  5. Plug 'scrooloose/nerdtree'
  6. Plug 'Xuyuanp/nerdtree-git-plugin'
  7. Plug 'tpope/vim-fugitive'
  8. Plug 'airblade/vim-gitgutter'
  9. Plug 'whiteinge/diffconflicts'
  10. Plug 'mhinz/vim-startify'
  11. Plug 'altercation/vim-colors-solarized'
  12. Plug 'vim-airline/vim-airline'
  13. Plug 'vim-airline/vim-airline-themes'
  14. Plug 'suan/vim-instant-markdown'
  15. Plug 'tpope/vim-markdown'
  16. Plug 'nvie/vim-flake8'
  17. Plug 'SirVer/ultisnips'
  18. Plug 'octol/vim-cpp-enhanced-highlight'
  19. Plug 'junegunn/goyo.vim'
  20. Plug 'junegunn/limelight.vim'
  21. Plug 'lervag/vimtex'
  22. Plug 'ap/vim-css-color'
  23. Plug 'mattn/emmet-vim'
  24. Plug 'tpope/vim-commentary'
  25. Plug 'pangloss/vim-javascript', { 'for': 'javacript' }
  26. Plug 'tpope/vim-unimpaired'
  27. Plug 'tpope/vim-surround'
  28. Plug 'christoomey/vim-tmux-navigator'
  29. Plug 'roxma/vim-tmux-clipboard'
  30. Plug 'Chiel92/vim-autoformat'
  31. Plug 'keith/swift.vim'
  32. Plug 'snakemake/snakemake', {'rtp': 'misc/vim/'}
  33. Plug 'junegunn/vim-easy-align'
  34. Plug 'glench/vim-jinja2-syntax'
  35. Plug 'fatih/vim-go'
  36. Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
  37. Plug 'junegunn/fzf.vim'
  38. " All of your Plugins must be added before the following line
  39. call plug#end() " required
  40. "
  41. " U S E R S E T U P
  42. "
  43. " Recursive file search
  44. set path+=**
  45. " Ignore some stuff esp. for ctrlP
  46. set wildignore+=*/node_modules/*,*/build*/*,*/InstallArea/*
  47. " Make watchdogs possible
  48. set backupcopy=yes
  49. " jump between split lines
  50. map j gj
  51. map k gk
  52. nnoremap <silent> <BS> :TmuxNavigateLeft<cr>
  53. "map mapleader / to (german layout)
  54. let mapleader = ","
  55. " execute current file
  56. nnoremap <leader>e :!'%:p'<CR>
  57. " Run `make` in current directory
  58. nnoremap <leader>m :!make<CR>
  59. " open build/*.pdf
  60. nnoremap <leader>o :!open build/*.pdf<CR>
  61. " open Nerdtree with CTRL+n
  62. map <C-n> :NERDTreeToggle<CR>
  63. " toggle background with ,i
  64. nnoremap <leader>i :let &background = (&background == "dark" ? "light" : "dark")<CR>
  65. " Open fzf file list
  66. nnoremap <silent> <expr> <Leader><Leader> (expand('%') =~ 'NERD_tree' ? "\<c-w>\<c-w>" : '').":Files\<cr>"
  67. nnoremap <silent> <Leader>b :Buffers<CR>
  68. nnoremap <silent> <Leader>t :Tags<CR>
  69. " :w for :W
  70. command W w
  71. command Wq wq
  72. command Q q
  73. command Qa qa
  74. command WQ wq
  75. " color scheme
  76. colo solarized
  77. set ai " Set auto inline on
  78. set number " Show line numbers
  79. syntax on " Set syntax highlighting on
  80. set tabstop=4 " width of tab
  81. " should be redundant after tabstop and expandtab,
  82. " but vim-snipmate is messing up (?)
  83. set softtabstop=4
  84. set shiftwidth=4
  85. set expandtab " use 'tabstop' spaces instead of tab
  86. set colorcolumn=80 " Bar hinting for 80 chars
  87. set breakindent "baby, yeah!
  88. set mouse=a " activate mouse support
  89. set relativenumber " aka :set rnu
  90. " searching
  91. set ignorecase " ignore case while searching
  92. nnoremap <C-s> :set hlsearch!<CR>
  93. " autoformatting
  94. let g:formatter_python = ['yapf']
  95. let g:formatter_yapf_style = 'pep8'
  96. " handling backupfiles
  97. set backupdir=~/.config/nvim/backup//
  98. set directory=~/.config/nvim/swap//
  99. set undodir=~/.config/nvim/undo//
  100. " NERDTree Configuration
  101. " hide some fileextenxions
  102. let NERDTreeIgnore = ['\.pyc$']
  103. " vim-fugitive
  104. " gdiff vertical instead of horizontal
  105. set diffopt+=vertical
  106. " Airline stuff
  107. let g:airline_powerline_fonts = 1
  108. let g:airline#extensions#tabline#enabled = 1
  109. let g:airline#extensions#tabline#buffer_nr_show = 1
  110. " multiple-cursors mapping
  111. let g:multi_cursor_use_default_mapping=0
  112. let g:multi_cursor_next_key='<C-d>'
  113. let g:multi_cursor_quit_key='<Esc>'
  114. " configure UltiSnips
  115. let g:UltiSnipsExpandTrigger='<C-j>'
  116. let g:UltiSnipsJumpForwardTrigger='<C-j>'
  117. let g:UltiSnipsJumpBackwardTrigger='<C-k>'
  118. " vCoolor config
  119. let g:vcoolor_map = '<C-c>'
  120. let g:vcool_ins_rgb_map = '' " Insert rgb color.
  121. let g:vcool_ins_hsl_map = '' " Insert hsl color.
  122. let g:vcool_ins_rgba_map = '' " Insert rgba color.
  123. " vim-javascript config
  124. let g:javascript_enable_domhtmlcss = 1
  125. " limelight+goyo settings, automatically fire up limelight with goyo
  126. let g:limelight_conceal_ctermfg = 'gray'
  127. let g:goyo_width = 85
  128. autocmd! User GoyoEnter Limelight
  129. autocmd! User GoyoLeave Limelight!
  130. " map `,g` to start goyo
  131. nnoremap <leader>g :Goyo<CR>
  132. " Enable emmet-vim just for html/css
  133. let g:user_emmet_isntall_global = 0
  134. autocmd FileType html,css,md EmmetInstall
  135. " configure flake8
  136. " bind `,f` to Flake8
  137. nnoremap <leader>f :call Flake8()<CR>
  138. let g:flake8_show_quickfix=1
  139. let g:flake8_show_in_gutter=1
  140. " instant markdown
  141. let g:instant_markdown_autostart = 0
  142. " activate mouse support
  143. set mouse=a
  144. set scrolloff=5
  145. " add some cpp-keywords
  146. syn keyword cppExceptions noexcept using
  147. " allow mouse clicks to change cursor position
  148. set noequalalways
  149. " list whitespaces and some other characters
  150. set listchars=tab:>-,trail:~
  151. set list
  152. " use latex flavour for plaintex files
  153. let g:tex_flavor = "latex"
  154. " set some default options for my personal latexmk
  155. let g:vimtex_compiler_progname="nvr"
  156. let g:vimtex_view_method = 'skim'
  157. " let g:vimtex_view_general_viewer = 'open'
  158. " let g:vimtex_view_general_options = '-a Skim'
  159. let g:vimtex_compiler_latexmk={
  160. \ 'options' : [
  161. \ '-lualatex',
  162. \ '-silent',
  163. \ '-synctex=1',
  164. \ '-interaction=nonstopmode',
  165. \ '-shell-escape',
  166. \ ],
  167. \ 'build_dir' : 'livepreview',
  168. \}
  169. let g:vimtex_quickfix_ignore_filters = [
  170. \ 'Marginpar on page',
  171. \]
  172. let g:vimtex_quickfix_autoclose_after_keystrokes = 5
  173. "
  174. " coc.nvim
  175. "
  176. " TextEdit might fail if hidden is not set.
  177. set hidden
  178. " Some servers have issues with backup files, see #649.
  179. " use them anyway
  180. " set nobackup
  181. " set nowritebackup
  182. " Give more space for displaying messages.
  183. " set cmdheight=2
  184. " Having longer updatetime (default is 4000 ms = 4 s) leads to noticeable
  185. " delays and poor user experience.
  186. set updatetime=300
  187. " Don't pass messages to |ins-completion-menu|.
  188. set shortmess+=c
  189. " Always show the signcolumn, otherwise it would shift the text each time
  190. " diagnostics appear/become resolved.
  191. if has("patch-8.1.1564")
  192. " Recently vim can merge signcolumn and number column into one
  193. set signcolumn=number
  194. else
  195. set signcolumn=yes
  196. endif
  197. " Use tab for trigger completion with characters ahead and navigate.
  198. " NOTE: Use command ':verbose imap <tab>' to make sure tab is not mapped by
  199. " other plugin before putting this into your config.
  200. inoremap <silent><expr> <TAB>
  201. \ pumvisible() ? "\<C-n>" :
  202. \ <SID>check_back_space() ? "\<TAB>" :
  203. \ coc#refresh()
  204. inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"
  205. function! s:check_back_space() abort
  206. let col = col('.') - 1
  207. return !col || getline('.')[col - 1] =~# '\s'
  208. endfunction
  209. " Use <c-space> to trigger completion.
  210. if has('nvim')
  211. inoremap <silent><expr> <c-space> coc#refresh()
  212. else
  213. inoremap <silent><expr> <c-@> coc#refresh()
  214. endif
  215. " Use <cr> to confirm completion, `<C-g>u` means break undo chain at current
  216. " position. Coc only does snippet and additional edit on confirm.
  217. " <cr> could be remapped by other vim plugin, try `:verbose imap <CR>`.
  218. if exists('*complete_info')
  219. inoremap <expr> <cr> complete_info()["selected"] != "-1" ? "\<C-y>" : "\<C-g>u\<CR>"
  220. else
  221. inoremap <expr> <cr> pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>"
  222. endif
  223. " Use `[g` and `]g` to navigate diagnostics
  224. " Use `:CocDiagnostics` to get all diagnostics of current buffer in location list.
  225. nmap <silent> [g <Plug>(coc-diagnostic-prev)
  226. nmap <silent> ]g <Plug>(coc-diagnostic-next)
  227. " GoTo code navigation.
  228. nmap <silent> gd <Plug>(coc-definition)
  229. nmap <silent> gy <Plug>(coc-type-definition)
  230. nmap <silent> gi <Plug>(coc-implementation)
  231. nmap <silent> gr <Plug>(coc-references)
  232. " Use K to show documentation in preview window.
  233. nnoremap <silent> K :call <SID>show_documentation()<CR>
  234. function! s:show_documentation()
  235. if (index(['vim','help'], &filetype) >= 0)
  236. execute 'h '.expand('<cword>')
  237. else
  238. call CocAction('doHover')
  239. endif
  240. endfunction
  241. " Highlight the symbol and its references when holding the cursor.
  242. autocmd CursorHold * silent call CocActionAsync('highlight')
  243. " Symbol renaming.
  244. nmap <leader>rn <Plug>(coc-rename)
  245. " Formatting selected code.
  246. xmap <leader>f <Plug>(coc-format-selected)
  247. nmap <leader>f <Plug>(coc-format-selected)
  248. augroup mygroup
  249. autocmd!
  250. " Setup formatexpr specified filetype(s).
  251. autocmd FileType typescript,json setl formatexpr=CocAction('formatSelected')
  252. " Update signature help on jump placeholder.
  253. autocmd User CocJumpPlaceholder call CocActionAsync('showSignatureHelp')
  254. augroup end
  255. " Applying codeAction to the selected region.
  256. " Example: `<leader>aap` for current paragraph
  257. xmap <leader>a <Plug>(coc-codeaction-selected)
  258. nmap <leader>a <Plug>(coc-codeaction-selected)
  259. " Remap keys for applying codeAction to the current buffer.
  260. nmap <leader>ac <Plug>(coc-codeaction)
  261. " Apply AutoFix to problem on the current line.
  262. nmap <leader>qf <Plug>(coc-fix-current)
  263. " Map function and class text objects
  264. " NOTE: Requires 'textDocument.documentSymbol' support from the language server.
  265. xmap if <Plug>(coc-funcobj-i)
  266. omap if <Plug>(coc-funcobj-i)
  267. xmap af <Plug>(coc-funcobj-a)
  268. omap af <Plug>(coc-funcobj-a)
  269. xmap ic <Plug>(coc-classobj-i)
  270. omap ic <Plug>(coc-classobj-i)
  271. xmap ac <Plug>(coc-classobj-a)
  272. omap ac <Plug>(coc-classobj-a)
  273. " Use CTRL-S for selections ranges.
  274. " Requires 'textDocument/selectionRange' support of LS, ex: coc-tsserver
  275. nmap <silent> <C-s> <Plug>(coc-range-select)
  276. xmap <silent> <C-s> <Plug>(coc-range-select)
  277. " Add `:Format` command to format current buffer.
  278. command! -nargs=0 Format :call CocAction('format')
  279. " Add `:Fold` command to fold current buffer.
  280. command! -nargs=? Fold :call CocAction('fold', <f-args>)
  281. " Add `:OR` command for organize imports of the current buffer.
  282. command! -nargs=0 OR :call CocAction('runCommand', 'editor.action.organizeImport')
  283. " Add (Neo)Vim's native statusline support.
  284. " NOTE: Please see `:h coc-status` for integrations with external plugins that
  285. " provide custom statusline: lightline.vim, vim-airline.
  286. set statusline^=%{coc#status()}%{get(b:,'coc_current_function','')}
  287. " Mappings for CoCList
  288. " Show all diagnostics.
  289. nnoremap <silent><nowait> <space>a :<C-u>CocList diagnostics<cr>
  290. " Manage extensions.
  291. nnoremap <silent><nowait> <space>e :<C-u>CocList extensions<cr>
  292. " Show commands.
  293. nnoremap <silent><nowait> <space>c :<C-u>CocList commands<cr>
  294. " Find symbol of current document.
  295. nnoremap <silent><nowait> <space>o :<C-u>CocList outline<cr>
  296. " Search workspace symbols.
  297. nnoremap <silent><nowait> <space>s :<C-u>CocList -I symbols<cr>
  298. " Do default action for next item.
  299. nnoremap <silent><nowait> <space>j :<C-u>CocNext<CR>
  300. " Do default action for previous item.
  301. nnoremap <silent><nowait> <space>k :<C-u>CocPrev<CR>
  302. " Resume latest coc list.
  303. nnoremap <silent><nowait> <space>p :<C-u>CocListResume<CR>
  304. "
  305. " End COC
  306. "
  307. " vimtex settings
  308. let g:vimtex_matchparen_enabled=0 " turn off folding to speed up things
  309. " Snakemake syntax
  310. au BufNewFile,BufRead Snakefile set syntax=snakemake
  311. au BufNewFile,BufRead *.rules set syntax=snakemake
  312. au BufNewFile,BufRead *.snakefile set syntax=snakemake
  313. au BufNewFile,BufRead *.snake set syntax=snakemake
  314. " golang
  315. let g:go_fmt_command = "goimports"
  316. " only for the e5 interactive machines
  317. let g:go_version_warning = 0
  318. " easy align
  319. vmap <Enter> <Plug>(EasyAlign)
  320. source $HOME/.config/nvim/local.vimrc