vim: Minor vimrc tweaking
[shutils.git] / dotfiles / vim / .vimrc
index 8c716d410c85344ece65201c3fee7c818bb2d6e4..df65e4a1e854e135ceaf320bac618b1585aef3e8 100644 (file)
@@ -1,19 +1,16 @@
 " Purpose:      My personal .vimrc
 " Author:       Stefan Huber
-"
-"Essential resources for vim users
-"  - vim.sf.net -- find tips and scripts for vim and gvim
-"
-"By calling ":help keyword" you get help for the specific
-"option and setting.
 
+"profile start /tmp/profile.log
+"profile func *
+"profile file *
 
-set nocompatible
 set encoding=utf8
-set modeline
 set number
 set backspace=indent,eol,start
 
+set mouse=a
+
 set tagstack
 set grepprg=grep\ -nH\ $*
 set foldcolumn=1
@@ -23,12 +20,15 @@ set hlsearch
 
 set cursorline
 set laststatus=2
+set scrolloff=4
 
 set listchars=tab:»­,trail:·,eol:$
+set virtualedit=block
 
 set autoindent
 set tabstop=4
 set shiftwidth=4
+set expandtab
 
 if version >= 703
     set spelllang=de_at,en
@@ -36,24 +36,72 @@ if version >= 703
     set colorcolumn=+1
 endif
 
-" Pathogen runtime path manipulation
-"call pathogen#infect() "Using the infect method breaks ft detection
-filetype off
-call pathogen#runtime_append_all_bundles()
-call pathogen#helptags()
+set wildmode=longest,list:longest
+
+set tags=./tags;/
 
 syntax on
 filetype plugin indent on
 
+runtime! autoload/plug.vim
+" Check if there is vim-plug installed
+if exists('g:loaded_plug')
+    call plug#begin('~/.config/nvim/plugged')
+        Plug 'Glench/Vim-Jinja2-Syntax'
+        Plug 'LaTeX-Box-Team/LaTeX-Box'
+        Plug 'benekastah/neomake'
+        Plug 'vim-airline/vim-airline'
+        Plug 'vim-airline/vim-airline-themes'
+        Plug 'chrisbra/csv.vim'
+        Plug 'craigemery/vim-autotag'
+        Plug 'godlygeek/tabular'
+        "Plug 'kien/ctrlp.vim'
+        Plug 'junegunn/fzf'
+        Plug 'majutsushi/tagbar'
+        Plug 'mhinz/vim-signify'
+        Plug 'msanders/snipmate.vim'
+        Plug 'scrooloose/nerdcommenter'
+        Plug 'scrooloose/nerdtree'
+        " Plug 'scrooloose/syntastic'
+        Plug 'sjl/splice.vim'
+        Plug 'Shougo/deoplete.nvim'
+        Plug 'suan/vim-instant-markdown'
+        Plug 't4ku/marktag'
+        Plug 'thinca/vim-fontzoom'
+        Plug 'tpope/vim-ragtag'
+        Plug 'vim-scripts/CSApprox'
+        Plug 'vim-scripts/DetectIndent'
+        Plug 'vim-scripts/git_patch_tags.vim'
+        Plug 'vim-scripts/loremipsum'
+    call plug#end()
+
+    autocmd! BufWritePost,BufEnter * Neomake
+
+" If there is no vim-plug, try pathogen
+else
+    runtime autoload/pathogen.vim
+    if exists("g:loaded_pathogen")
+        " Pathogen runtime path manipulation
+        call pathogen#runtime_append_all_bundles()
+        call pathogen#helptags()
+    endif
+endif
 
-"Power saving tip: powertop-homepage
-let &guicursor = &guicursor . ",a:blinkon0"
-"According to vim help -- enable mouse in xterm...
-set mouse=a
 
-" Use 256 colors
-set t_Co=256
-let g:CSApprox_attr_map = { 'bold' : 'bold', 'italic' : '', 'sp' : '' }
+if has('nvim')
+    set rtp^=/usr/share/vim/vimfiles
+else
+    set nocompatible
+endif
+
+" Color settings
+if !has('nvim')
+    set t_Co=256
+else
+    let $NVIM_TUI_ENABLE_TRUE_COLOR=1
+endif
+let g:CSApprox_attr_map = { 'bold' : 'bold', 'italic' : 'underline', 'sp' : 'bg' }
+
 colorscheme shuber-wombat
 
 
@@ -61,15 +109,27 @@ colorscheme shuber-wombat
 highlight BadWhitespace ctermbg=red guibg=red
 " Make trailing whitespace be flagged as bad.
 au Filetype python,tex,c,cpp,cs,objc,java,vim syn match BadWhitespace /\s\+$/ containedin=ALL
+au Filetype python,tex,c,cpp,cs,objc,java,vim let g:airline#extensions#whitespace#enabled = 0
 
 
+" Detect indentation, but otherwise set expandtab
 if exists(":DetectIndent")
     au BufReadPost * :DetectIndent
 endif
 
 
-let g:syntastic_mode_map = { 'mode' : 'active', 'active_filetypes' : [], 'passive_filetypes' : ['html'] }
+"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
+"  Airline
+"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
+
+let g:airline_powerline_fonts = 0
+let g:airline_theme = 'wombat'
 
+let g:airline#extensions#tabline#enabled = 1
+let g:airline#extensions#tagbar#enabled = 0
+let g:airline#extensions#whitespace#enabled = 0
+let g:airline#extensions#branch#enabled = 1
+let g:airline#extensions#branch#use_vcscommand = 1
 
 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
 "  Some macros
@@ -85,12 +145,17 @@ endfunction
 "  key bindings
 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
 
+nmap <s-PageDown> :bn<CR>
+nmap <s-PageUp>   :bp<CR>
+
 map <a-c> <plug>NERDCommenterToggle
+nmap <F9> :NERDTreeToggle<CR>
+nmap <F10> :TagbarToggle<CR>
 
-nmap <c-q> :q<CR>
-nmap <c-s> :w<CR>
-vmap <c-s> <Esc><c-s>gv
-imap <c-s> <c-o><c-s>
+"nmap <c-q> :q<CR>
+"nmap <c-s> :w<CR>
+"vmap <c-s> <Esc><c-s>gv
+"imap <c-s> <c-o><c-s>
 
 
 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
@@ -106,14 +171,14 @@ au Filetype fortran     set cindent cst csto=0
 "  C, C++, C#, objc, java
 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
 
-au Filetype c,cpp,cs,objc,java map <F4> :cnext <CR>
-au Filetype c,cpp,cs,objc,java map <S-F4> :cprevious <CR>
-au Filetype c,cpp,cs,objc,java map <F11> :AS <CR>
-au Filetype c,cpp,cs,objc,java map <S-F11> :A <CR>
+au Filetype c,cpp,cs,objc,java map <buffer> <F4> :cnext <CR>
+au Filetype c,cpp,cs,objc,java map <buffer> <S-F4> :cprevious <CR>
+au Filetype c,cpp,cs,objc,java map <buffer> <F11> :AS <CR>
+au Filetype c,cpp,cs,objc,java map <buffer> <S-F11> :A <CR>
 au Filetype c,cpp,cs,objc,java set cindent cst csto=0
-au Filetype c,cpp,cs,objc map <F7> :make <CR>
-au Filetype java map <F7> :!ant -f ../build.xml <CR>
-au Filetype c,cpp,cs,obj set makeprg=make
+au Filetype c,cpp,cs,objc map <buffer> <F7> :make <CR>
+au Filetype java map <buffer> <F7> :!ant -f ../build.xml <CR>
+au Filetype c,cpp,cs,objc set makeprg=make
 
 
 "Prepend the namespace to an identifier, e.g. 'std::' before 'map' excluding
@@ -136,9 +201,9 @@ function PrependCppNamespaceToIdent(ns, id)
     " in the middle begin with a star.
 
     " If #include and // and /* and ^* and :: is not prepend:
-    execute ':%s_\(\(#include\|\/\/\|\/\*\|^\s*\*[^/]\).*\|::\)\@<!\<' . a:id . '\>_' . a:ns . '::' . a:id . '_ge'
+    execute ':%s@\(\(#include\|\/\/\|\/\*\|^\s*\*[^/]\).*\|::\)\@<!\<' . a:id . '\>@' . a:ns . '::' . a:id . '@ge'
     " If #include and // and :: is not prepend, but */ is, and no further /* or // are found
-    execute ':%s_\(\(#include\|\/\/\).*\)\@<!\*\/\(\/[^\/\*]\|[^\/]\)*\zs\(::\)\@<!\<' . a:id . '\>_' . a:ns . '::' . a:id . '_ge'
+    execute ':%s@\(\(#include\|\/\/\).*\)\@<!\*\/\(\/[^\/\*]\|[^\/]\)*\zs\(::\)\@<!\<' . a:id . '\>@' . a:ns . '::' . a:id . '@ge'
 
 endfunction
 
@@ -155,7 +220,6 @@ function PrependSTLNamespace()
     let id = id +['queue', 'stack', 'priority_queue']
     let id = id +['ostream', 'istream', 'sstream']
     let id = id +['pair', 'string']
-    let id = ['map']
 
     for i in id
         call PrependCppNamespaceToIdent("std", i)
@@ -169,6 +233,19 @@ function EscapeHexToChar()
     execute '%s/^\(.*\)$/"\1"/'
 endfunction
 
+function InsertIncludeGuardsWithoutEndif()
+       let gatename = substitute(expand("%:t"), "\\.", "_", "g") . '_' . strpart(system('pwgen -c 16 1'), 0, 16)
+       execute "normal! i#ifndef " . gatename
+       execute "normal!   o#define " . gatename
+endfunction
+
+function AddIncludeGuards()
+       execute "normal! Go#endif"
+       execute "normal! gg"
+       call InsertIncludeGuardsWithoutEndif()
+endfunction
+
+autocmd BufNewFile *.{h,hpp,hxx} call AddIncludeGuards()
 
 
 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
@@ -176,6 +253,7 @@ endfunction
 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
 
 au Filetype text set textwidth=80
+au Filetype markddown set textwidth=80
 "According to thunderbirds settings
 au Filetype mail set textwidth=72
 au Filetype mail set expandtab
@@ -204,12 +282,41 @@ au Filetype php set textwidth=80
 "au Filetype php set cindent
 
 
+"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
+"  maxima
+"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
+
+au BufRead,BufNewFile *.wxm set filetype=maxima
+
+
 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
 "  LaTeX
 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
 
+let g:LatexBox_split_side = "rightbelow"
+"let g:LatexBox_split_resize = 1
+let g:LatexBox_ref_pattern = '\c\\\a*ref\*\?\_\s*{'
+
+let g:tex_flavor = "latex"
+let g:LatexBox_output_type = "pdf"
+let g:LatexBox_viewer = "okular"
+let g:LatexBox_latexmk_async = 1
+let g:LatexBox_latexmk_preview_continuously = 1
+"let g:LatexBox_show_warnings = 0
+let g:LatexBox_quickfix = 4
+
+if version >= 700
+    au Filetype tex set spell
+endif
+
 au BufRead,BufNewFile *.cls set filetype=tex
 au Filetype tex set textwidth=80
+au Filetype tex set shiftwidth=2
+au Filetype tex set smartindent
+" Override Tagbar Toggle with LatexBox TOC
+au Filetype tex nmap <buffer> <F10> :LatexTOCToggle<CR>
+au Filetype tex nmap <buffer> <F11> :LatexLabels<CR>
+
 
 "Remove Umlaute
 function TexTransUmlaute()
@@ -229,22 +336,12 @@ function FindWordRepeatings()
 "        call cursor(pos)
 endfunction
 
-let g:tex_flavor = "latex"
-let g:LatexBox_viewer="okular"
-let g:LatexBox_latexmk_options="-pvc"
-
-au Filetype tex set smartindent
-
-if version >= 700
-    au Filetype tex set spell
-endif
-
 
 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
 "  python
 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
 
-au Filetype python map <F5> :!python % <CR>
+au Filetype python map <buffer> <F5> :!python % <CR>
 
 " vimrc file for following the coding standards specified in PEP 7 & 8.
 
@@ -256,29 +353,126 @@ au Filetype python set expandtab
 " Wrap text after a certain number of characters
 au Filetype python set textwidth=79
 
+let g:syntastic_python_checkers = ["pyflakes"]
 
 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
 "  XML, Ipe
 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
 
 "Opens the current file in ipe
-au Filetype xml map <M-o> :call OpenIn("ipe") <CR>
+au BufRead,BufNewFile *.ipe set filetype=ipe
+au Filetype xml,ipe map <buffer> <M-o> :call OpenIn("ipe") <CR>
 
+au Filetype xml let g:tagbar_sort = 0
+let g:tagbar_type_xml = {
+  \ 'ctagstype' : 'xml',
+  \ 'kinds' : [
+    \ 't:Tag'
+  \ ]
+\ }
 
 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
 "  gnuplot
 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
 
 "Opens the current file in ipe
-au Filetype gnuplot map <M-o> :call OpenIn("gnuplot -persist") <CR>
+au Filetype gnuplot map <buffer> <M-o> :call OpenIn("gnuplot -persist") <CR>
+
+
+"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
+"  remind
+"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
+
+au BufRead,BufNewFile */.remind/* set filetype=remind
+
+
+"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
+"  vim-orgmode
+"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
+
+au BufRead,BufNewFile *.org set filetype=org
+let g:org_todo_keywords=['TODO', 'FEEDBACK', 'VERIFY', '|', 'DONE', 'DELEGATED']
+let g:org_todo_keyword_faces = [['FEEDBACK', 'magenta'], ['TODO', 'yellow']]
+
+
+"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
+"  markdown
+"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
+
+let g:instant_markdown_autostart = 0
+let g:instant_markdown_slow = 1
+au Filetype markdown map <buffer> <F5> :InstantMarkdownPreview<CR>
+au Filetype markdown let g:tagbar_sort = 0
+
+let g:tagbar_type_markdown = {
+  \ 'ctagstype' : 'markdown',
+  \ 'kinds' : [
+    \ 'h:Heading_L1',
+    \ 'i:Heading_L2',
+    \ 'k:Heading_L3'
+  \ ]
+\ }
+
+if executable('marktag')
+    let g:tagbar_type_markdown = {
+        \ 'ctagstype' : 'markdown',
+        \ 'ctagsbin' : 'marktag',
+        \ 'kinds' : [
+            \ 'h:header'
+        \ ],
+        \ 'sro' : '.',
+        \ 'kind2scope' : {
+            \ 'h' : 'header'
+        \  },
+        \ 'scope2kind' : {
+            \ 'header' : 'h'
+        \ }
+    \ }
+end
+
+
+"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
+"  deoplete
+"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
 
+let g:deoplete#enable_at_startup = 1
 
 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
 "  youcompleteme
 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
 
-let g:ycm_min_num_of_chars_for_completion = 999
+let g:ycm_global_ycm_extra_conf = '~/.ycm_extra_conf.py'
+let g:ycm_confirm_extra_conf = 0
+
+let g:ycm_min_num_of_chars_for_completion = 4
+let g:ycm_collect_identifiers_from_tags_files = 1
+let g:ycm_autoclose_preview_window_after_completion = 1
+
 let g:ycm_key_list_select_completion = ['<Down>']
+nnoremap <buffer> <leader>jd :YcmCompleter GoToDefinitionElseDeclaration<CR>
+
+let g:ycm_filetype_whitelist = { 'c' : 1, 'cpp' : 1, 'cs' : 1, 'objc' : 1, 'java' : 1, 'python' : 1 }
+
+"let g:ycm_server_use_vim_stdout = 1
+"let g:ycm_server_log_level = 'debug'
+
+
+"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
+"  syntastic
+"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
+
+let g:syntastic_mode_map = { 'mode' : 'active', 'active_filetypes' : [], 'passive_filetypes' : ['html'] }
+let g:ycm_show_diagnostics_ui = 0
+let g:syntastic_c_checkers = ["cppcheck"]
+let g:syntastic_cpp_checkers = g:syntastic_c_checkers
+
+
+"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
+"  signify
+"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
+
+let g:signify_vcs_list = ['git']
+
 
 
 
@@ -286,4 +480,8 @@ if filereadable($HOME . "/.vimrc-local")
     source ~/.vimrc-local
 endif
 
+" Being able to load project specific vimrc files
+set exrc
+set secure
+