1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
已复制! set expandtab
set tabstop=4
set shiftwidth=4
set softtabstop=4
autocmd FileType asm,nasm,vim,sh,makefile set tabstop=4 softtabstop=4 shiftwidth=4 noexpandtab
set showmatch
set nowrap
set textwidth=500
set lbr
set foldmethod=syntax
set nofoldenable
autocmd FileType python set omnifunc=pythoncomplete#Complete
autocmd FileType javascript set omnifunc=javascriptcomplete#CompleteJS
autocmd FileType html set omnifunc=htmlcomplete#CompleteTags
autocmd FileType css set omnifunc=csscomplete#CompleteCSS
autocmd FileType xml set omnifunc=xmlcomplete#CompleteTags
autocmd FileType php set omnifunc=phpcomplete#CompletePHP
autocmd FileType c set omnifunc=ccomplete#Complete
nnoremap gg=G :call PreserveCursorAndFormat()<CR>
function! PreserveCursorAndFormat()
let l:save_pos = getpos(".")
let l:save_view = winsaveview()
normal! gg=G
call setpos('.', l:save_pos)
call winrestview(l:save_view)
endfunction
command! -nargs=0 ClangFormat :call ClangFormat()
autocmd FileType c,h,cpp,hpp,cc nnoremap <buffer> gg=G :ClangFormat<CR>
function! ClangFormat()
let clang_format = "clang-format"
let clang_format_file = findfile(".clang-format", ".;")
if clang_format_file != ""
let clang_format = clang_format . " -style=file"
else
let clang_format = clang_format . " -style='{IndentWidth: 4}'"
endif
let save_cursor = getpos(".")
let save_view = winsaveview()
let save_cursor = getpos(".")
let save_view = winsaveview()
execute ":silent %! ".clang_format
call setpos('.', save_cursor)
call winrestview(save_view)
endfunction
autocmd BufNewFile *.cpp,*.[ch],*.sh exec ":call SetTitle()"
func SetTitle()
if &filetype == 'sh'
call setline(1,"#!/bin/bash")
call append(line("."), "" )
call append(line(".")+1, "\##########################################################################" )
call append(line(".")+2, "\# File Name : ".expand("%"))
call append(line(".")+3, "\# Encoding : utf-8")
call append(line(".")+4, "\# Author : We-unite")
call append(line(".")+5, "\# Email : weunite1848@gmail.com")
call append(line(".")+6, "\# Created Time : ".strftime("%Y-%m-%d %H:%M:%S",localtime()))
call append(line(".")+7, "\##########################################################################" )
call append(line(".")+8, "")
elseif &filetype =='py'
call setline(1,"#!/usr/bin/env python")
call append(line("."), "" )
call append(line(".")+1, "\##########################################################################" )
call append(line(".")+2, "\# File Name : ".expand("%"))
call append(line(".")+3, "\# Encoding : utf-8")
call append(line(".")+4, "\# Author : We-unite")
call append(line(".")+5, "\# Email : weunite1848@gmail.com")
call append(line(".")+6, "\# Created Time : ".strftime("%Y-%m-%d %H:%M:%S",localtime()))
call append(line(".")+7, "\##########################################################################" )
call append(line(".")+8, "")
else
call setline(1, "/*************************************************************************")
call append(line("."), " > File Name : ".expand("%"))
call append(line(".")+1, " > Encoding : utf-8")
call append(line(".")+2, " > Author : We-unite")
call append(line(".")+3, " > Email : weunite1848@gmail.com ")
call append(line(".")+4, " > Created Time : ".strftime("%Y-%m-%d %H:%M:%S",localtime()))
call append(line(".")+5, " ************************************************************************/")
call append(line(".")+6, "")
if &filetype == 'cpp'
call append(line(".")+7, "#include <iostream>")
call append(line(".")+8, "using namespace std;")
call append(line(".")+9, "")
elseif &filetype == 'c'
call append(line(".")+7, "#include <stdio.h>")
call append(line(".")+9, "")
endif
endif
normal G
endfunc
|