aboutsummaryrefslogtreecommitdiffstats
path: root/vim/vimrcs/autocmd.vim
diff options
context:
space:
mode:
Diffstat (limited to 'vim/vimrcs/autocmd.vim')
-rw-r--r--vim/vimrcs/autocmd.vim81
1 files changed, 81 insertions, 0 deletions
diff --git a/vim/vimrcs/autocmd.vim b/vim/vimrcs/autocmd.vim
new file mode 100644
index 0000000..c974344
--- /dev/null
+++ b/vim/vimrcs/autocmd.vim
@@ -0,0 +1,81 @@
1autocmd BufReadPost,BufWritePre *.html,*.c,*.cpp,*.vim normal gg=G
2"autocmd FileType * :normal gg=G<c-o><c-o>
3autocmd Filetype c,cpp map <buffer><C-d> 0xx<esc>ta
4autocmd Filetype python map <buffer><C-d> 0xx<esc>ta
5
6"新建.c,.h,.sh,.java文件,自动插入文件头
7autocmd BufNewFile *.cpp,*.[ch],*.sh exec ":call SetTitle()"
8func SetTitle()
9 if &filetype == 'sh'
10 call setline(1,"#!/bin/bash")
11 call append(line("."), "" )
12 call append(line(".")+1, "\##########################################################################" )
13 call append(line(".")+2, "\# File Name : ".expand("%"))
14 call append(line(".")+3, "\# Encoding : utf-8")
15 call append(line(".")+4, "\# Author : We-unite")
16 call append(line(".")+5, "\# Email : weunite1848@gmail.com")
17 call append(line(".")+6, "\# Created Time : ".strftime("%Y-%m-%d",localtime()))
18 call append(line(".")+7, "\##########################################################################" )
19 call append(line(".")+8, "")
20 elseif &filetype =='py'
21 call setline(1,"#!/usr/bin/env python")
22 call append(line("."), "" )
23 call append(line(".")+1, "\##########################################################################" )
24 call append(line(".")+2, "\# File Name : ".expand("%"))
25 call append(line(".")+3, "\# Encoding : utf-8")
26 call append(line(".")+4, "\# Author : We-unite")
27 call append(line(".")+5, "\# Email : weunite1848@gmail.com")
28 call append(line(".")+6, "\# Created Time : ".strftime("%Y-%m-%d",localtime()))
29 call append(line(".")+7, "\##########################################################################" )
30 call append(line(".")+8, "")
31 else
32 call setline(1, "/*************************************************************************")
33 call append(line("."), " > File Name : ".expand("%"))
34 call append(line(".")+1, " > Encoding : utf-8")
35 call append(line(".")+2, " > Author : We-unite")
36 call append(line(".")+3, " > Email : weunite1848@gmail.com ")
37 call append(line(".")+4, " > Created Time : ".strftime("%Y-%m-%d-%H:%M:%S",localtime()))
38 call append(line(".")+5, " ************************************************************************/")
39 call append(line(".")+6, "")
40 if &filetype == 'cpp'
41 call append(line(".")+7, "#include <iostream>")
42 call append(line(".")+8, "using namespace std;")
43 call append(line(".")+9, "")
44 elseif &filetype == 'c'
45 call append(line(".")+7, "#include <stdio.h>")
46 call append(line(".")+8, "#include <stdlib.h>")
47 call append(line(".")+9, "")
48 endif
49 endif
50 " 光标移动到文件末尾
51 normal G
52endfunc
53
54"C,C++ 按F5编译运行
55map <F5> :call CompileRunGcc()<CR>
56
57func CompileRunGcc()
58 exec "w"
59 if &filetype == 'c'
60 exec "!gcc -g -o %< %"
61 exec "! ./%<"
62 elseif &filetype == 'cpp'
63 exec "!g++ -g -o %< %"
64 exec "! ./%<"
65 "elseif &filetype == 'java'
66 " exec "!javac %"
67 " exec "!java %<"
68 elseif &filetype == 'sh'
69 :!./%
70 elseif &filetype == 'python'
71 exec "!python %"
72 endif
73endfunc
74
75"C,C++的调试
76map <F8> :call RunGdb()<CR>
77
78func RunGdb()
79 exec "w"
80 exec "!gdb ./%<"
81endfunc