From e4b83a5e11f622386764cffb4fb27094da093b30 Mon Sep 17 00:00:00 2001 From: DustVoice Date: Sun, 22 Sep 2019 23:18:19 +0200 Subject: [PATCH] Add more CPP automation --- init.vim | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/init.vim b/init.vim index 9c7a714..0cbf633 100644 --- a/init.vim +++ b/init.vim @@ -1265,6 +1265,47 @@ nnoremap p iunique_ptr<>i inoremap m make_unique<>i noremap m imake_unique<>i + +function! CPP_Include_Guard() + let guard_name = input("Please input the guard name:\n") + if guard_name != "" + execute("normal! mZ") + execute("normal! gg") + if getline(".") =~ "\." + execute("normal! O") + endif + execute("normal! O#ifndef " . guard_name) + execute("normal! o#define " . guard_name) + execute("normal! G") + if getline(".") =~ "\." + execute("normal! o") + endif + execute("normal! o#endif") + execute("normal! `Z") + endif +endfunction + +function! CPP_Comment_File() + let file_desc = input("Please input a short file description:\n") + if file_desc != "" + execute("normal! mZ") + execute("normal! O/**") + execute("normal! o") + execute("normal! S @file " . expand("%:t")) + execute("normal! o@author DustVoice") + execute("normal! o") + execute("normal! o@class DustVoice") + execute("normal! o") + execute("normal! o" . file_desc) + execute("normal! o*/") + execute("normal! <<") + execute("normal! `Z") + endif +endfunction + +command! CppIncludeGuard :call CPP_Include_Guard() +command! CppCommentFile :call CPP_Comment_File() + " ==================================== nmap bg :let &background = ( &background == "dark"? "light" : "dark" )