vim配置文件

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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
set nocompatible              " required
filetype off " required

" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
"call vundle#begin()

" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')

" let Vundle manage Vundle, required
"Plugin 'gmarik/Vundle.vim'

" Add all your plugins here (note older versions of Vundle used Bundle instead of Plugin)
"Plugin 'Valloric/YouCompleteMe'


" All of your Plugins must be added before the following line
"call vundle#end() " required
filetype plugin indent on " required

syntax on "自动语法高亮
set number " 显示行号
set cursorline " 突出显示当前行
set ruler " 打开状态栏标尺
set shiftwidth=4 " 设定 << 和 >> 命令移动时的宽度为 4
set tabstop=4 " 设定 tab 长度为 4
filetype plugin indent on " 开启插件
set backupcopy=yes " 设置备份时的行为为覆盖
set nowrapscan " 禁止在搜索到文件两端时重新搜索
set incsearch " 输入搜索内容时就显示搜索结果
set hlsearch " 搜索时高亮显示被找到的文本
set cmdheight=1 " 设定命令行的行数为 1
set laststatus=2 " 显示状态栏(默认值为 1, 无法显示状态栏)
set statusline=\ %<%F[%1*%M%*%n%R%H]%=\ %y\ %0(%{&fileformat}\ %{&encoding}\ %c:%l/%L%)\
" 设置在状态行显示的信息
set foldenable " 开始折叠
set foldmethod=syntax " 设置语法折叠
set foldcolumn=0 " 设置折叠区域的宽度
setlocal foldlevel=1 " 设置折叠层数为
" set foldclose=all " 设置为自动关闭折叠
nnoremap <space> @=((foldclosed(line('.')) < 0) ? 'zc' : 'zo')<CR>
" 用空格键来开关折叠
" return OS type, eg: windows, or linux, mac, et.st..
function! MySys()
if has("win16") || has("win32") || has("win64") || has("win95")
return "windows"
elseif has("unix")
return "linux"
endif
endfunction

"highlight Functions
syn match cFunctions "\<[a-zA-Z_][a-zA-Z_0-9]*\>[^()]*)("me=e-2
syn match cFunctions "\<[a-zA-Z_][a-zA-Z_0-9]*\>\s*("me=e-1
hi cFunctions gui=NONE cterm=bold ctermfg=blue

nmap <C-down> :resize +3<CR>
nmap <C-up> :resize -3<CR>
nmap <C-left> :vertical resize -3<CR>
nmap <C-right> :vertical resize +3<CR>
nmap <F5> :call RunTest()<CR>
nmap <F2> :call Save()<CR>
nmap <F3> :call Esc()<CR>
nnoremap <C-s> :call Save()<CR>
map <F9> :call Run()<CR>
func! RunTest()
exec "w"
exec "!./test.sh"
endfunc

func! Save()
exec"w"
endfunc

func! Esc()
exec "w"
exec "!clear"
exec "q"
endfunc

func! Run()
exec "w"
exec "!g++ -Wall -g % -o %<"
exec "! ./%<"
endfunc

" 当新建 .h .c .hpp .cpp .mk .sh等文件时自动调用SetTitle 函数
autocmd BufNewFile *.[ch],*.hpp,*.cpp,Makefile,*.mk,*.sh exec ":call SetTitle()"

" 加入注释
func SetComment()
call setline(1,"/*================================================================")
call append(line("."), "* Copyright (C) ".strftime("%Y")." brooke. All rights reserved.")
call append(line(".")+1, "* ")
call append(line(".")+2, "* 文件名称:".expand("%:t"))
call append(line(".")+3, "* 创 建 者:Brooke")
call append(line(".")+4, "* 创建日期:".strftime("%Y年%m月%d日"))
call append(line(".")+5, "* 描 述:")
call append(line(".")+6, "*")
call append(line(".")+7, "================================================================*/")
call append(line(".")+8, "")
call append(line(".")+9, "")
endfunc

" 加入shell,Makefile注释
func SetComment_sh()
call setline(3, "#================================================================")
call setline(4, "# Copyright (C) ".strftime("%Y")." brooke. All rights reserved.")
call setline(5, "# ")
call setline(6, "# 文件名称:".expand("%:t"))
call setline(7, "# 创 建 者:Brooke")
call setline(8, "# 创建日期:".strftime("%Y年%m月%d日"))
call setline(9, "# 描 述:")
call setline(10, "#")
call setline(11, "#================================================================")
call setline(12, "")
call setline(13, "")
endfunc


" 定义函数SetTitle,自动插入文件头
func SetTitle()

if &filetype == 'make'
call setline(1,"")
call setline(2,"")
call SetComment_sh()

elseif &filetype == 'sh'
call setline(1,"#!/system/bin/sh")
call setline(2,"")
call SetComment_sh()

else
call SetComment()
if expand("%:e") == 'hpp'
call append(line(".")+10, "#ifndef _".toupper(expand("%:t:r"))."_H")
call append(line(".")+11, "#define _".toupper(expand("%:t:r"))."_H")
call append(line(".")+12, "#ifdef __cplusplus")
call append(line(".")+13, "extern \"C\"")
call append(line(".")+14, "{")
call append(line(".")+15, "#endif")
call append(line(".")+16, "")
call append(line(".")+17, "#ifdef __cplusplus")
call append(line(".")+18, "}")
call append(line(".")+19, "#endif")
call append(line(".")+20, "#endif //".toupper(expand("%:t:r"))."_H")

elseif expand("%:e") == 'h'
call append(line(".")+10, "#pragma once")

elseif &filetype == 'c'
call append(line(".")+10,"#include \"".expand("%:t:r").".h\"")

elseif &filetype == 'cpp'
call append(line(".")+10, "using namespace std;")
call append(line(".")+10, "#include \""."iostream\"")

endif

endif
endfunc
作者

bd160jbgm

发布于

2017-12-22

更新于

2021-05-08

许可协议