vim 自动插入作者信息与头文件配置

 

 

觉得挺挺好玩的,就学习配置了一下

自动添加作者信息和头文件适用与c++环境, 作者名字、邮箱自行替换就ok了。 有不明白的地方可以留言哦。。。

 

 

set nu
set shiftwidth=4
set syntax=on
set tabstop=4
set cindent
set autoindent
set mouse=a


map  ggVG"+y


"格式化代码
map  gg=G


function AddTitle()
    call append(0,"//Author       :	NIYOUDUOGAO")
    call append(1,"//Last modified:	".strftime("%Y-%m-%d %H:%M"))
    call append(2,"//Email        :	[email protected]")
    call append(3,"//Filename     :	".expand("%:t"))
    echohl WarningMsg | echo "Successful in adding copyright." | echohl None
endf
 
function UpdateTitle()
     normal m'
     execute '/Last modified/s@:.*$@\=strftime(":\t%Y-%m-%d %H:%M")@'
     normal ''
     normal mk
     execute '/Filename/s@:.*$@\=":\t".expand("%:t")@'
     execute "noh"
     normal 'k
     echohl WarningMsg | echo "Successful in updating the copyright." | echohl None
endfunction
function Title()
    let n = 1
    while n < 6
        let line = getline(n)
        if line =~ '^\s*\S*Last\smodified\S*.*$'
            call UpdateTitle()
            return
        endif
        let n = n + 1
    endwhile
    call AddTitle()
endfunction
 
 
 
 
"添加头文件
map  :call HeadFile()
function HeadFile()
    call append(0,"#include ")
    call append(1,"#define mset(a, x) memset(a, x, sizeof(a))")
    call append(2,"using namespace std;")
    call append(3,"typedef long long ll;")
    call append(4,"const int INF = 0x3f3f3f3f;")
    call append(5,"const int mod = 1e9 + 7;")
    call append(6,"const int N = 1e5 + 5;")
	call append(7,"")
	call append(8,"int main() {")
	call append(9,"    std::ios::sync_with_stdio(false);")
	call append(10,"    cin.tie(0), cout.tie(0);")
	call append(11,"")
	call append(12,"    return 0;")
	call append(13,"}")
    echohl WarningMsg | echo "Successful in adding copyright." | echohl None
endf
 
 
map  :call Run() 
func! Run()
	call Title()
	exec "w"
	exec "!g++ % -o %<"
	exec "!./%<"
endfunc


syntax enable
set background=dark
colorscheme molokai

 

你可能感兴趣的:(Linux)