nvim/init.vim
2019-07-15 09:43:51 +02:00

305 lines
11 KiB
VimL

let HOSTNAME = substitute(system('hostname'), '\n', '', '')
" =============Plugins==================
call plug#begin()
Plug 'morhetz/gruvbox'
Plug 'Shougo/denite.nvim', { 'do': ':UpdateRemotePlugins' }
Plug 'chemzqm/denite-git'
Plug 'tomtom/tcomment_vim'
Plug 'bling/vim-airline'
Plug 'vim-airline/vim-airline-themes'
" Plug 'Shougo/deoplete.nvim', { 'do': ':UpdateRemotePlugins' }
Plug 'tpope/vim-fugitive'
Plug 'airblade/vim-gitgutter'
Plug 'SirVer/ultisnips'
Plug 'honza/vim-snippets'
Plug 'vim-scripts/a.vim'
Plug 'luochen1990/rainbow'
if has("win32")
Plug 'autozimu/LanguageClient-neovim', {
\ 'branch': 'next',
\ 'do': 'powershell -executionpolicy bypass -File install.ps1',
\ }
else
Plug 'autozimu/LanguageClient-neovim', {
\ 'branch': 'next',
\ 'do': 'bash install.sh',
\ }
end
Plug 'Shougo/echodoc.vim'
Plug 'arakashic/chromatica.nvim', { 'do': ':UpdateRemotePlugins' }
Plug 'neoclide/coc.nvim', {'do': { -> coc#util#install()}}
Plug 'neoclide/coc-json', {'do': 'yarn install --frozen-lockfile'}
Plug 'neoclide/coc-python', {'do': 'yarn install --frozen-lockfile'}
Plug 'neoclide/coc-yaml', {'do': 'yarn install --frozen-lockfile'}
Plug 'neoclide/coc-highlight', {'do': 'yarn install --frozen-lockfile'}
Plug 'neoclide/coc-snippets', {'do': 'yarn install --frozen-lockfile'}
Plug 'neoclide/coc-lists', {'do': 'yarn install --frozen-lockfile'}
Plug 'kkoomen/vim-doge'
call plug#end()
" =============Paths=====================
exec "source " . stdpath('config') . "/" . hostname() . ".vim"
" =============Settings==================
filetype plugin on
filetype indent on
set nocompatible
set ignorecase " Case sensitive off
set incsearch
set encoding=utf-8
set nobackup
set noswapfile
set mouse=a
set spelllang=en,de
set spellsuggest=double,10
set list
set icon
set listchars=tab:>.,trail:.,extends:#,nbsp:.
set showmatch " Show pair braces
set hlsearch "Highlight search
syntax on
set number
set scrolloff=2
set autochdir " Always switch to directory of current buffer
let mapleader = ","
set title
if has("win32")
" set rop=type:directx
let g:loaded_matchparen = 1
end
set listchars=eol,tab:>·,trail:~,extends:>,precedes:<,space:␣
set listchars=eol:⏎,tab:␉·,trail:␠,nbsp:⎵
set listchars=tab:>.,trail:.,extends:#,nbsp:.
" set clipboard+=unnamedplus " use system clipboard
" " Copy to clipboard
vnoremap <leader>y "+y
nnoremap <leader>Y "+yg_
nnoremap <leader>y "+y
nnoremap <leader>yy "+yy
" " Paste from clipboard
nnoremap <leader>p "+p
nnoremap <leader>P "+P
vnoremap <leader>p "+p
vnoremap <leader>P "+P
autocmd BufEnter,FocusGained * checktime " Check for file modifications
" =================Look and feel=======================
set termguicolors
set background=dark
colorscheme gruvbox
" =================Filetypes===========================
au BufRead,BufNewFile *.simvis set filetype=xml
au BufRead,BufNewFile *.simcfg set filetype=cfg
au BufRead,BufNewFile *.simcon set filetype=cfg
au BufRead,BufNewFile *.simudex set filetype=cfg
au BufRead,BufNewFile Jenkinsfile* set filetype=groovy
autocmd BufNewFile,BufRead *.manifest set filetype=xml
autocmd BufNewFile,BufReadPre SConstruct set filetype=python
autocmd BufNewFile,BufReadPre SConscript set filetype=python
autocmd FileType json syntax match Comment +\/\/.\+$+
" =================Windows and Tabs====================
" Open a new tab with F2
map <silent> <F2> <Esc>:tabnew <CR><ESC>:Explore<CR>
imap <silent> <F2> <Esc>:tabnew <CR><ESC>:Explore<CR>
map <silent> <S-Right> :tabnext<CR>
map <silent> <S-Left> :tabprevious<CR>
nmap <silent> <A-Up> :wincmd k<CR>
nmap <silent> <A-Down> :wincmd j<CR>
nmap <silent> <A-Left> :wincmd h<CR>
nmap <silent> <A-Right> :wincmd l<CR>
" Open a new vertical split window with Ctrl - F2
map <silent> <C-F2> <Esc>:vsplit .<CR>
imap <silent> <C-F2> <Esc>:vsplit .<CR>
" Open a new horizontal split window with Shift - F2
map <silent> <S-F2> <Esc>:split .<CR>
imap <silent> <S-F2> <Esc>:split .<CR>
" ========================Codestyle========================
set tabstop=2 " Size of a tab
set shiftwidth=2 " Die Einrückung
set expandtab "Tabs get spaces when inserting
set softtabstop=0
"set autoindent
"alignment ansi style (astyle)
set cindent " C-Code Style / Automatische Einrückung
set cinoptions=(0,u0,U0,:0,=0 "Einrückung wie bei astyle: :0 (switch), =0 (case), (0 (unclosed parentheses),
set modeline "Read indent comments (at end of file)
" ======================shortcut=======================
map <C-S> <ESC>:wa<CR>
imap <C-S> <ESC>:wa<CR>
"Jump to last modification line
map ö `.
nnoremap ü :let @/='\<<C-R>=expand("<cword>")<CR>\>'<CR>:set hls<CR>
vnoremap <silent> ü :<C-U>
\let old_reg=getreg('"')<Bar>let old_regtype=getregtype('"')<CR>
\gvy:let @/=substitute(
\escape(@", '/\.*$^~['), '\_s\+', '\\_s\\+', 'g')<CR>
\gV:call setreg('"', old_reg, old_regtype)<CR>:set hls<CR>
"map jump back to ctrl+-
nnoremap <C--> <C-O>
"===================Reselect visual block after indent/outdent============
vnoremap < <gv
vnoremap > >gv
" ===========Linewrap and jumping=============================
setlocal wrap linebreak nolist
set virtualedit=
setlocal display+=lastline
nnoremap <silent> k gk
nnoremap <silent> j gj
nnoremap <silent> 0 g0
nnoremap <silent> $ g$
nnoremap <silent> <Up> gk
nnoremap <silent> <Down> gj
nnoremap <silent> <Home> g<Home>
nnoremap <silent> <End> g<End>
vnoremap <silent> <Up> gk
vnoremap <silent> <Down> gj
vnoremap <silent> <Home> g<Home>
vnoremap <silent> <End> g<End>
" =================Comments============================
map <C-C> :TComment<CR>
" =========================Deoplete====================
let g:deoplete#enable_at_startup = 1
let g:deoplete#auto_complete_start_length = 1
let g:deoplete#enable_smart_case = 1
" =====================A======================
" Function for switching between header and c* files
map <F5> :wa <CR> :A<CR>
imap <F5> <Esc>:wa<CR>:A<CR>i
map <C-F5> :AV<CR>
imap <C-F5> <Esc>:AV<CR>i
map <S-F5> :AT<CR>
imap <S-F5> <Esc>:AT<CR>i
let g:alternateSearchPath = 'sfr:../source,sfr:../src,sfr:../include,../../include,sfr:../inc,sfr:../h'
" Dont create the file if the .cpp or .h is not found
let g:alternateNoDefaultAlternate = 1
" ===================UltiSnips================
let g:UltiSnipsExpandTrigger = "<Plug>(ultisnips_expand)"
let g:UltiSnipsJumpForwardTrigger = "<Tab>"
let g:UltiSnipsJumpBackwardTrigger = "<S-Tab>"
" ===========RAINBOW====================
let g:rainbow_active = 1
let g:rainbow_conf = {
\ 'guifgs': ['lightblue', 'darkorange3', 'seagreen3', 'firebrick'],
\ 'ctermfgs': ['lightblue', 'lightyellow', 'lightcyan', 'lightmagenta'],
\ 'operators': '_,_',
\ 'parentheses': ['start=/(/ end=/)/ fold', 'start=/\[/ end=/\]/ fold', 'start=/{/ end=/}/ fold'],
\ 'separately': {
\ '*': {},
\ 'tex': {
\ 'parentheses': ['start=/(/ end=/)/', 'start=/\[/ end=/\]/'],
\ },
\ 'cpp': {
\ 'parentheses': [
\ 'start=/(/ end=/)/ fold',
\ 'start=/\[/ end=/\]/ fold',
\ 'start=/{/ end=/}/ fold',
\ 'start=/\(\(\<operator\>\)\@<!<\)\&[a-zA-Z0-9_]\@<=<\ze[^<]/ end=/>/']
\ },
\ 'cmake': {
\ 'parentheses': [],
\ },
\ 'lisp': {
\ 'guifgs': ['royalblue3', 'darkorange3', 'seagreen3', 'firebrick', 'darkorchid3'],
\ },
\ 'vim': {
\ 'parentheses': ['start=/(/ end=/)/', 'start=/\[/ end=/\]/', 'start=/{/ end=/}/ fold', 'start=/(/ end=/)/ containedin=vimFuncBody', 'start=/\[/ end=/\]/ containedin=vimFuncBody', 'start=/{/ end=/}/ fold containedin=vimFuncBody'],
\ },
\ 'html': {
\ 'parentheses': ['start=/\v\<((area|base|br|col|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr)[ >])@!\z([-_:a-zA-Z0-9]+)(\s+[-_:a-zA-Z0-9]+(\=("[^"]*"|'."'".'[^'."'".']*'."'".'|[^ '."'".'"><=`]*))?)*\>/ end=#</\z1># fold'],
\ },
\ 'css': 0,
\ }
\}
" ===================LanguageServer==================
if has("win32")
let g:LanguageClient_serverCommands = {
\ 'cpp': ['clangd'],
\ }
else
let g:LanguageClient_serverCommands = {
\ 'cpp': ['cquery',
\ '--log-file=/tmp/cq.log',
\ '--init={"cacheDirectory":"/tmp/cquery/"}']
\ }
end
nnoremap <silent> K :call LanguageClient#textDocument_hover()<CR>
nnoremap <silent> gd :call LanguageClient#textDocument_definition({'gotoCmd': 'tabedit'})<CR>
nnoremap <silent> <F3> :call LanguageClient_contextMenu()<CR>
vnoremap <silent> <F3> :call LanguageClient_contextMenu()<CR>
nnoremap <silent> <F6> :call LanguageClient_textDocument_documentSymbol()<CR>
let g:LanguageClient_hasClientSupport = 0
" ===================EchoDoc=========================
set cmdheight=2
let g:echodoc#enable_at_startup = 1
let g:echodoc#type = 'signature'
" ===================FZF=============================
nnoremap <C-P> :FZF<CR>
let g:fzf_action = {
\ 'enter': 'tab split',
\ 'ctrl-x': 'split',
\ 'ctrl-v': 'vsplit' }
" ===================Chromatica======================
let g:chromatica#enable_at_startup=1
" ===================COC=============================
inoremap <silent><expr> <c-space> coc#refresh()
autocmd CursorHold * silent call CocActionAsync('highlight')
set updatetime=500 " After ms should CursorHold trigger
" Remap for format selected region
vmap <leader>f <Plug>(coc-format-selected)
nmap <leader>f <Plug>(coc-format-selected)
nmap <leader>r <Plug>(coc-rename)
" Use `:Format` for format current buffer
command! -nargs=0 Format :call CocAction('format')
" Shortcuts for denite interface
" Show extension list
nnoremap <silent> <space>e :CocList extensions<cr>
" Show symbols of current buffer
nnoremap <silent> <space>o :CocList outline<cr>
" Search symbols of current workspace
nnoremap <silent> <space>t :CocList symbols<cr>
" Show diagnostics of current workspace
nnoremap <silent> <space>a :CocList diagnostics<cr>
" Show available commands
nnoremap <silent> <space>c :CocList commands<cr>
" Show available services
nnoremap <silent> <space>s :CocList services<cr>
" Show links of current buffer
nnoremap <silent> <space>l :CocList link<cr>
nmap <silent> gd <Plug>(coc-definition)
nmap <silent> gy <Plug>(coc-type-definition)
nmap <silent> gi <Plug>(coc-implementation)
nmap <silent> gr <Plug>(coc-references)
" Use K for show documentation in preview window
nnoremap <silent> K :call <SID>show_documentation()<CR>
function! s:show_documentation()
if &filetype == 'vim'
execute 'h '.expand('<cword>')
else
call CocAction('doHover')
endif
endfunction
nnoremap <silent> <space>y :<C-u>CocList -A --normal yank<cr>
" ===================Denite==========================
call denite#custom#map('insert', '<Down>', '<denite:move_to_next_line>', 'noremap')
call denite#custom#map('insert', '<Up>', '<denite:move_to_previous_line>', 'noremap')
nnoremap <C-P> :Denite -default-action=tabopen file/rec<CR>
nnoremap <C-B> :Denite buffer<CR>