From 0b8d10cf3795f7ce103de2165e3aae15c0f52ec7 Mon Sep 17 00:00:00 2001 From: Stefan Huber Date: Mon, 2 Jul 2018 22:41:03 +0200 Subject: [PATCH] First commit --- .gitignore | 5 ++ README.md | 39 +++++++++++++ gvimrc | 6 ++ init-local.vim.example | 12 ++++ init.vim | 113 +++++++++++++++++++++++++++++++++++++ install.sh | 52 +++++++++++++++++ keymaps-local.vim.example | 1 + keymaps.vim | 35 ++++++++++++ macros-local.vim.example | 0 macros.vim | 91 +++++++++++++++++++++++++++++ neosnippets/gitcommit.snip | 19 +++++++ plugins-local.vim.example | 7 +++ plugins.vim | 64 +++++++++++++++++++++ plugsetup.vim | 18 ++++++ 14 files changed, 462 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 gvimrc create mode 100644 init-local.vim.example create mode 100644 init.vim create mode 100755 install.sh create mode 100644 keymaps-local.vim.example create mode 100644 keymaps.vim create mode 100644 macros-local.vim.example create mode 100644 macros.vim create mode 100644 neosnippets/gitcommit.snip create mode 100644 plugins-local.vim.example create mode 100644 plugins.vim create mode 100644 plugsetup.vim diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2bff0b3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +plugged +init-local.vim +keymaps-local.vim +macros-local.vim +plugins-local.vim diff --git a/README.md b/README.md new file mode 100644 index 0000000..36e411f --- /dev/null +++ b/README.md @@ -0,0 +1,39 @@ +# A modular vim configuration + +This is my personal vim configuration that is partly inspired by SpaceVim. It +is compatible to neovim and (g)vim (version 8 or higher). The configuration is +split up into multiple files such that personal customization is separated from +boilerplate code. + + +## Installation + +Simply clone this repository into ~/.vim and invoke install.sh therein. The +install script just creates symlinks to vim/gvim/neovim configuration files and +directories. + +```` +git clone https://git.sthu.org/repos/vimconf.git ~/.vim +~/.vim/install.sh +```` + +The install file also checks requirements for the configuration and the plugins +added: + + - python3 support for vim/gvim + - neovim python3 module + - aspell + + +## Specialization for local machines + +I personally would like to have the same vim configuration on all my accounts. +Still, on certain machines I would like to personalize and specialize the +configuration. The following files are read if existent: + + - plugins-local.vim + - macros-local.vim + - keymaps-local.vim + - init-local.vim + +For all four example files are shipped with the repository. diff --git a/gvimrc b/gvimrc new file mode 100644 index 0000000..3c95be5 --- /dev/null +++ b/gvimrc @@ -0,0 +1,6 @@ +set columns=100 +set lines=35 + +set guifont=Hack\ 9,Liberation\ Mono\ for\ Powerline\ 10,DejaVu\ Sans\ Mono\ 10,Monospace\ 10 + +set mousehide diff --git a/init-local.vim.example b/init-local.vim.example new file mode 100644 index 0000000..d75e4fd --- /dev/null +++ b/init-local.vim.example @@ -0,0 +1,12 @@ +" Configuration for youcompleteme, if not using vim-clang. +"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 = 2 +"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 = [''] +"nnoremap jd :YcmCompleter GoToDefinitionElseDeclaration +"let g:ycm_filetype_whitelist = { 'c' : 1, 'cpp' : 1, 'cs' : 1, 'objc' : 1, 'java' : 1, 'python' : 1 } + +" Do not show diagnostic window of vim-clang +let g:clang_diagsopt = '' diff --git a/init.vim b/init.vim new file mode 100644 index 0000000..f840aca --- /dev/null +++ b/init.vim @@ -0,0 +1,113 @@ +" My personal vim, nvim, gvim configuration +" Author: Stefan Huber + +set nocompatible +set termguicolors +set number +set cursorline +set scrolloff=5 + + +set encoding=utf-8 + +set listchars=tab:»­,trail:·,eol:$ +set virtualedit=block + +set tabstop=4 +set shiftwidth=4 +set expandtab +set smarttab + +set incsearch +set hlsearch + +set colorcolumn=+1 +set mouse=a +set wildmode=longest,list:full + +if has('nvim') + set guicursor= +end + +syntax on +filetype plugin indent on +runtime plugsetup.vim + +let g:airline_powerline_fonts=1 +let g:airline#extensions#tabline#enabled=1 +let g:airline#extensions#branch#enabled=1 + +let g:gruvbox_contrast_light='hard' +let g:gruvbox_contrast_dark='hard' +let g:gruvbox_italic = 1 +set bg=dark +colorscheme gruvbox + +" let NERDTreeWinPos="right" +let NERDTreeHijackNetrw=0 +let NERDTreeWinSize=22 +let NERDTreeQuitOnOpen=1 +"au VimEnter * if !argc() | Startify | NERDTree | wincmd w + +let g:neomake_c_enabled_makers = ['clangtidy', 'clangcheck'] +let g:neomake_cpp_enabled_makers = ['clangtidy', 'clangcheck'] + +call neomake#configure#automake('w') +"let g:neomake_logfile = '/tmp/neomake.log' + +let g:clang_compilation_database = '.' + +let g:deoplete#enable_at_startup=1 + +"augroup pencil + "au! + "au FileType markdown,mkd call pencil#init() + "au FileType text call pencil#init() + "au FileType mail call pencil#init() + "au FileType tex call pencil#init() +"augroup END + +let g:vim_markdown_folding_disabled=1 +let g:vim_markdown_frontmatter=1 +let g:vim_markdown_math=1 + +let g:guesslang_langs=[ 'en_US', 'de_AT'] +au FileType text,markdown,mail,tex setlocal spell +au BufReadPost * :DetectIndent + +au BufEnter *.c* let b:fswitchlocs='reg:/lib/include/,rel:.' +au BufEnter *.h* let b:fswitchlocs='reg:/include/lib/,rel:.' + +au BufEnter *.cpp,*.cc,*.cxx let b:fswitchdst='h,hxx,hpp,hh' +au BufEnter *.h,*.hh,*.hxx let b:fswitchdst='cc,c,cxx,cpp' + + +"git scissor line +au Filetype mail syn match Statement /^\s*-*\s*>8\s*-*\s*$/ +au Filetype mail syn match Statement /^\s*-*\s*8<\s*-*\s*$/ + +"mutt and neomutt +au BufRead,BufNewFile ~/.mutt/tmp/*mutt-* set filetype=mail +au BufRead,BufNewFile *.muttrc set filetype=muttrc + +" Some settings for tex files +au BufRead,BufNewFile *.cls set filetype=tex +au Filetype tex set shiftwidth=2 + +au BufRead,BufNewFile *.plt set filetype=gnuplot + +:let g:org_todo_keywords = [['TODO(t)', 'WAITING(w)', '|', 'DONE(d)'], + \ ['|', 'OBSOLETE(o)'], + \ ['CANCELED(c)']] + +" Trailing whitespace +highlight default link TrailingWhitespace SpellCap +" Make trailing whitespace be flagged as bad. +au BufRead,BufNewFile * syn match TrailingWhitespace /\s\+$/ containedin=ALL + +runtime macros.vim +runtime keymaps.vim + +if filereadable($HOME . '/.vim/init-local.vim') + source ~/.vim/init-local.vim +endif diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..d2d300a --- /dev/null +++ b/install.sh @@ -0,0 +1,52 @@ +#!/bin/sh + +set -e + +check_vim() +{ + if /usr/bin/vim --version | grep -q "$1"; then + echo "vim has support for $1." + else + echo "vim has no support for $1. Aborting." + exit + fi +} + +check_py3() +{ + if python3 -c "import $1" 2>/dev/null; then + echo "Python3 module '$1' exists." + else + echo "Python3 module '$1' missing. Aborting." + exit + fi +} + +check_prog() +{ + if which "$1" > /dev/null; then + echo "$1 found" + else + echo "$1 not found. Aborting." + exit + fi +} + +check_requirements() +{ + check_vim +python3 + check_prog aspell + check_py3 neovim +} + +install() { + echo "Installing files." + touch $HOME/.viminfo + ln -s $HOME/.vim/init.vim $HOME/.vimrc + ln -s $HOME/.vim/gvimrc $HOME/.gvimrc + ln -s $HOME/.vim $HOME/.config/nvim +} + + +check_requirements +install diff --git a/keymaps-local.vim.example b/keymaps-local.vim.example new file mode 100644 index 0000000..944dc4c --- /dev/null +++ b/keymaps-local.vim.example @@ -0,0 +1 @@ +"map :TMToggle diff --git a/keymaps.vim b/keymaps.vim new file mode 100644 index 0000000..20f3233 --- /dev/null +++ b/keymaps.vim @@ -0,0 +1,35 @@ +nnoremap :Denite file/rec +nnoremap / :Denite grep:. +nnoremap s :Denite buffer + +nnoremap pumvisible() ? "\" : "\" + +nnoremap :NERDTreeToggle +nnoremap :TagbarToggle +au Filetype tex nmap :VimtexTocToggle +au Filetype tex nmap :VimtexLabelsToggle +au Filetype gnuplot map :call OpenIn("gnuplot -persist") + +nmap :bn +nmap :bp + +map NERDCommenterToggle + +imap (neosnippet_expand_or_jump) +smap (neosnippet_expand_or_jump) +xmap (neosnippet_expand_target) + +au Filetype c,cpp,objc map :vsplit:FSRight +au Filetype c,cpp,objc map :FSHere +au BufNewFile *.{h,hpp,hxx} call AddIncludeGuards() + +au Filetype html,xml imap / + +" Start interactive EasyAlign in visual mode (e.g. vipga) +vmap (EasyAlign) +" Start interactive EasyAlign for a motion/text object (e.g. gaip) +nmap ga (EasyAlign) + +if filereadable($HOME . '/.vim/keymaps-local.vim') + source ~/.vim/keymaps-local.vim +endif diff --git a/macros-local.vim.example b/macros-local.vim.example new file mode 100644 index 0000000..e69de29 diff --git a/macros.vim b/macros.vim new file mode 100644 index 0000000..08f3d22 --- /dev/null +++ b/macros.vim @@ -0,0 +1,91 @@ +" Tranlate umlauts to tex-syntax umlauts +function TexTransUmlaute() + execute ':%s/ü/\\\"u/ge' + execute ':%s/Ü/\\\"U/&' + execute ':%s/ö/\\\"o/&' + execute ':%s/Ö/\\\"O/&' + execute ':%s/ä/\\\"a/&' + execute ':%s/Ä/\\\"A/&' + execute ':%s/ß/\\\"s/&' + execute ':%s/²/\^2/&' +endfunction + + +"Open current file with a specific program +function OpenIn(prog) + silent execute ":!" . a:prog . " % &" +endfunction + + +"Prepend the namespace to an identifier, e.g. 'std::' before 'map' excluding +"those in C/C++ comments. +function PrependCppNamespaceToIdent(ns, id) + + " To match Not to match + " + "|id |// id + "| id |// /* */ id + "|/* */ /* */ id |/* */ // id + "|id /* */ |/* id + "|*/ id | * id + " |/* id */ + " |::id + " |/**/ ::id + " |#include + " + " In order to not match '* id' it is assumed that multi-line comment lines + " in the middle begin with a star. + + " If #include and // and /* and ^* and :: is not prepend: + execute ':%s@\(\(#include\|\/\/\|\/\*\|^\s*\*[^/]\).*\|::\)\@@' . a:ns . '::' . a:id . '@ge' + " If #include and // and :: is not prepend, but */ is, and no further /* or // are found + execute ':%s@\(\(#include\|\/\/\).*\)\@@' . a:ns . '::' . a:id . '@ge' + +endfunction + + +"Prepend STL namespace 'std::' to several identifiers +function PrependSTLNamespace() + " This list of identifier is not complete, but adding all of them is too + " much. We rather like to add identifieres that are 'typical' for C++. + " Others, like 'move' are likely to not be C++ specific. In this cases the + " user is asked to call PrependCppNamespaceToIdent by hand. + let id = [] + let id = id +['cin', 'cout', 'cerr', 'endl'] + let id = id +['swap', 'sort', 'max', 'min'] + let id = id +['vector', 'deque', 'list', 'map', 'multimap', 'set'] + let id = id +['queue', 'stack', 'priority_queue'] + let id = id +['ostream', 'istream', 'sstream'] + let id = id +['pair', 'string'] + + for i in id + call PrependCppNamespaceToIdent("std", i) + endfor +endfunction + + +function EscapeHexToChar() + echo 'Call "x/Nxb addr" in GDB to print N bytes at addr' + execute '%s/^.*://' + execute '%s/\s*0x\(\x\x\)/\\x\1/g' + 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 + + +if filereadable($HOME . '/.vim/macros-local.vim') + source ~/.vim/macros-local.vim +endif diff --git a/neosnippets/gitcommit.snip b/neosnippets/gitcommit.snip new file mode 100644 index 0000000..ed9ffe3 --- /dev/null +++ b/neosnippets/gitcommit.snip @@ -0,0 +1,19 @@ +# Signed-off-by tag line +snippet signed-off-by +options head + Signed-off-by: ${1:authorname } + +# Reported-by tag line +snippet reported-by +options head + Reported-by: ${1:authorname } + +# Tested-by tag line +snippet tested-by +options head + Tested-by: ${1:authorname } + +# Tested-by tag line +snippet acked-by +options head + Acked-by: ${1:authorname } diff --git a/plugins-local.vim.example b/plugins-local.vim.example new file mode 100644 index 0000000..05a6bc0 --- /dev/null +++ b/plugins-local.vim.example @@ -0,0 +1,7 @@ +Plug 'jamessan/vim-gnupg' + +" An alternative to youcompleteme (ycm) +"Plug 'justmao945/vim-clang' +Plug 'shuber2/vim-clang', { 'branch': 'multipy' } + +"Plug 'kien/tabman.vim' diff --git a/plugins.vim b/plugins.vim new file mode 100644 index 0000000..e90edc3 --- /dev/null +++ b/plugins.vim @@ -0,0 +1,64 @@ +Plug 'mhinz/vim-startify' + +Plug 'vim-airline/vim-airline' +Plug 'morhetz/gruvbox' + +Plug 'mhinz/vim-signify' +Plug 'tpope/vim-fugitive' +Plug 'airblade/vim-rooter' + +Plug 'Shougo/vimproc.vim', {'do': 'make'} +Plug 'Shougo/denite.nvim' + +Plug 'scrooloose/nerdcommenter' + +Plug 'scrooloose/nerdtree', {'on': 'NERDTreeToggle'} +Plug 'Xuyuanp/nerdtree-git-plugin', {'on': 'NERDTreeToggle'} + +Plug 'neomake/neomake' +Plug 'majutsushi/tagbar', {'on': 'TagbarToggle'} + +Plug 'plasticboy/vim-markdown', {'for': 'markdown'} +Plug 'lvht/tagbar-markdown', {'for': 'markdown'} + +Plug 'PProvost/vim-markdown-jekyll' +Plug 'tpope/vim-liquid' + +Plug 'cakebaker/scss-syntax.vim', {'for': 'scss'} +Plug 'hail2u/vim-css3-syntax', {'for': ['scss', 'css']} +Plug 'ap/vim-css-color', {'for': ['scss', 'css']} + +Plug 'tpope/vim-ragtag', {'for': ['html', 'xml']} + +Plug 'lervag/vimtex' + +if has('nvim') + Plug 'Shougo/deoplete.nvim', {'do': ':UpdateRemotePlugins' } +else + Plug 'Shougo/deoplete.nvim' + Plug 'roxma/nvim-yarp' + Plug 'roxma/vim-hug-neovim-rpc' +endif + +Plug 'Shougo/neosnippet.vim' +Plug 'Shougo/neosnippet-snippets' + +Plug 'tpope/vim-speeddating' +Plug 'jceb/vim-orgmode', {'for': ['org']} + +Plug 'Konfekt/vim-DetectSpellLang', {'do': 'spell'} +Plug 'ciaranm/detectindent' + +Plug 'derekwyatt/vim-fswitch', {'for': ['c', 'cpp', 'objc']} +Plug 'ludovicchabant/vim-gutentags', {'for': ['c', 'cpp', 'objc']} + +Plug 'godlygeek/tabular' +Plug 'junegunn/vim-easy-align' + +Plug 'thinca/vim-fontzoom' + +Plug 'vim-scripts/loremipsum', {'on': 'Loremipsum'} + +if filereadable($HOME . '/.vim/plugins-local.vim') + source ~/.vim/plugins-local.vim +endif diff --git a/plugsetup.vim b/plugsetup.vim new file mode 100644 index 0000000..ab7fa21 --- /dev/null +++ b/plugsetup.vim @@ -0,0 +1,18 @@ +"Automatic installation of vim-plug. +"https://github.com/junegunn/vim-plug/wiki/tips +if empty(glob('~/.vim/autoload/plug.vim')) + silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs + \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim + autocmd VimEnter * PlugInstall --sync | source ~/.vim/init.vim +endif + +call plug#begin('~/.vim/plugged') +source ~/.vim/plugins.vim +call plug#end() + +"Automatically install missing plugins +"https://github.com/junegunn/vim-plug/wiki/extra +autocmd VimEnter * + \ if len(filter(values(g:plugs), '!isdirectory(v:val.dir)')) + \| PlugInstall --sync | q + \| endif -- 2.30.2