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

 

 

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

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

 

 

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


map <C-A> ggVG"+y


"格式化代码
map <F4> gg=G


function AddTitle()
    call append(0,"//Author       :	NIYOUDUOGAO")
    call append(1,"//Last modified:	".strftime("%Y-%m-%d %H:%M"))
    call append(2,"//Email        :	pjm000@163.com")
    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 <F5> :call HeadFile()<CR>
function HeadFile()
    call append(0,"#include <bits/stdc++.h>")
    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 <F6> :call Run()<CR> 
func! Run()
	call Title()
	exec "w"
	exec "!g++ % -o %<"
	exec "!./%<"
endfunc


syntax enable
set background=dark
colorscheme molokai

 

  • 3
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值