X-Git-Url: https://git.sthu.org/?a=blobdiff_plain;f=dotfiles%2Fvim%2F.vimrc;h=5da54996af79d7730b9e6dfb1fec05781fb8b839;hb=68e246948776c9bca12913cd3cf648fc783191f9;hp=7a05e1d5250798c9e3d6c6457632be1c28112158;hpb=0fb103495587561054a6a6eba55f7f078631499d;p=shutils.git diff --git a/dotfiles/vim/.vimrc b/dotfiles/vim/.vimrc index 7a05e1d..5da5499 100644 --- a/dotfiles/vim/.vimrc +++ b/dotfiles/vim/.vimrc @@ -130,27 +130,31 @@ function PrependCppNamespaceToIdent(ns, 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 // and /* and ^* and :: is not prepend: - execute ':%s_\(\(\/\/\|\/\*\|^\s*\*[^/]\).*\|::\)\@_' . a:ns . '::' . a:id . '_ge' - " If // and :: is not prepend, but */ is, and no further /* or // are found - execute ':%s_\(\/\/.*\)\@_' . a:ns . '::' . a:id . '_ge' + " 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'] + let id = id +['ostream', 'istream', 'sstream'] let id = id +['pair', 'string'] - let id = ['map'] for i in id call PrependCppNamespaceToIdent("std", i) @@ -164,6 +168,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} call AddIncludeGuards() """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""