From dfbed3228749d82ab3a9feb67ebf4a9fa90cd031 Mon Sep 17 00:00:00 2001 From: Michael Carlberg Date: Sat, 29 Oct 2016 16:41:29 +0200 Subject: [PATCH] git: Vim files --- contrib/vim/autoload/ft/cpphpp.vim | 19 +++++++++++++++++++ contrib/vim/ftplugin/cpp.vim | 8 ++++++++ contrib/{ => vim/ftplugin}/dosini.vim | 0 3 files changed, 27 insertions(+) create mode 100644 contrib/vim/autoload/ft/cpphpp.vim create mode 100644 contrib/vim/ftplugin/cpp.vim rename contrib/{ => vim/ftplugin}/dosini.vim (100%) diff --git a/contrib/vim/autoload/ft/cpphpp.vim b/contrib/vim/autoload/ft/cpphpp.vim new file mode 100644 index 00000000..2176abb5 --- /dev/null +++ b/contrib/vim/autoload/ft/cpphpp.vim @@ -0,0 +1,19 @@ +" +" Get the filename of the swap file +" +func! ft#cpphpp#GetFilename() + let ext = expand('%:e') + let root = expand('%:p:r') + if (ext == 'cpp') + return fnameescape(substitute(root, '\(src/.*/\)\?src/', '\1include/', '') . '.hpp') + elseif (ext == 'hpp') + return fnameescape(substitute(root, '\(include/.*/\)\?include/', '\1src/', '') . '.cpp') + endif +endfunc + +" +" Swap between source/header using given cmd +" +func! ft#cpphpp#Swap(cmd) + execute a:cmd . ' ' . ft#cpphpp#GetFilename() +endfunc diff --git a/contrib/vim/ftplugin/cpp.vim b/contrib/vim/ftplugin/cpp.vim new file mode 100644 index 00000000..66eebfdb --- /dev/null +++ b/contrib/vim/ftplugin/cpp.vim @@ -0,0 +1,8 @@ +" Swap between source/header +nnoremap af :call ft#cpphpp#Swap('edit') +nnoremap as :call ft#cpphpp#Swap('new') +nnoremap av :call ft#cpphpp#Swap('vnew') + +" Code formatting using clang-format +set formatprg=/usr/bin/clang-format +nmap :ClangFormat diff --git a/contrib/dosini.vim b/contrib/vim/ftplugin/dosini.vim similarity index 100% rename from contrib/dosini.vim rename to contrib/vim/ftplugin/dosini.vim