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
164
165
166
167
168
169
170
171
|
" 通用配置
"打开语法高亮。自动识别代码,使用多种颜色显示
if has("syntax")
syntax on
endif
set nu "显示行号
"set nonu "取消显示行号
set shiftwidth=4 "设置缩进的空格数为4
set tabstop=4 "设定tab长度为4
set autoindent "设定自动缩进,下一行的缩进自动跟上一行的缩进保持一致
set cindent "设置使用C/C++语言的自动缩进方式
set cursorline "突出显示当前行
set autoread "打开文件监视.如果在编辑过程中文件发生外部改变(比如被别的编辑器编辑了),就会发出提示
set hlsearch "启用高亮搜索
"set nohlsearch "关闭高亮搜索
set incsearch "查询增量模式,自动追随要查找的内容,并就自动跳到第一个匹配的结果
"set nohl "只取消当前的搜索高亮
set ignorecase "搜索忽略大小写
set smartcase " Do smart case matching
set noeb "去掉输入错误的提示声音
set laststatus=2 "总是显示状态行
set showmode "显示当前是处于命令模式还是插入模式
set showcmd "显示当前输入的命令
set ruler "在编辑过程中,在右下角显示光标位置的状态行
" 命令模式下,底部操作指令按下 Tab 键自动补全。
" 第一次按下 Tab,会显示所有匹配的操作指令的清单;
" 第二次按下 Tab,会依次选择各个指令。
set wildmenu
set wildmode=longest:list,full
" 设置在状态行显示的信息: 文件格式, 编码格式, 当前行的第几个字符, 当前行数, 文件总行数
set statusline=\ %<%F[%1*%M%*%n%R%H]%=\ %y\ %0(%{&fileformat}\ %{&encoding}\ %c:%l/%L%)\
"显示文件名:总行数,总的字符数
"set statusline=[%F]%y%r%m%*%=[Line:%l/%L,Column:%c][%p%%]
"切换文件时,如果当前文件被修改,则自动保存,不再提示
set autowriteall
"语言设置
set enc=utf-8
set fencs=utf-8,ucs-bom,shift-jis,gb18030,gbk,gb2312,cp936
set langmenu=zh_CN.UTF-8
set helplang=cn
"映射光标在窗口间移动的快捷键
nmap <C-h> <C-W>h
nmap <C-j> <C-W>j
nmap <C-k> <C-W>k
nmap <C-l> <C-W>l
"去掉当前高亮
nmap <C-n> :nohl<CR>
"刷新当前文件,重新载入当前文件
nmap <F5> :edit<CR>
"设置或取消paste模式
nmap <F6> :set paste<CR>
nmap <F7> :set nopaste<CR>
"======快捷键调用函数,当前文件头部添加注释(/* */格式)======
function UpdateTitle()
normal m'
execute '/* Last modified\s*:/s@:.*$@\=strftime(": %Y-%m-%d %H:%M:%S")@'
normal "
normal mk
execute '/* Filename\s*:/s@:.*$@\=": ".expand("%:t")@'
execute "noh"
normal 'k
echohl WarningMsg | echo "Successful in updating the copy right." | echohl None
endfunction
function AddTitle()
call append(0,"/**********************************************************")
call append(1," * Filename: ".expand("%:t"))
call append(2," * Author: sunxidong")
call append(3," * Email: sunxidong9999@gmail.com")
call append(4," * Created: ".strftime("%Y-%m-%d %H:%M:%S"))
call append(5," * Last modified: ".strftime("%Y-%m-%d %H:%M:%S"))
call append(6," * Description: ")
call append(7," * *******************************************************/")
echohl WarningMsg | echo "Successful in adding the copyright." | echohl None
endfunction
function AddAuthor()
let n=1
while n < 7
let line = getline(n)
if line =~'^\s*\*\s*\S*Last\s*modified\s*:\s*\S*.*$'
call UpdateTitle()
return
endif
let n = n + 1
endwhile
call AddTitle()
endfunction
" 设置快捷键,按F9后向当前文件头部添加注释(/* */格式)
map <F9> ms:call AddAuthor()<cr>'s
function UpdateTitle_M()
normal m'
execute '/# Last modified\s*:/s@:.*$@\=strftime(": %Y-%m-%d %H:%M:%S")@'
normal "
normal mk
execute '/# Filename\s*:/s@:.*$@\=": ".expand("%:t")@'
execute "noh"
normal 'k
echohl WarningMsg | echo "Successful in updating the copy right." | echohl None
endfunction
function AddTitle_M()
call append(0,"###########################################################")
call append(1,"# Filename: ".expand("%:t"))
call append(2,"# Author: sunxidong")
call append(3,"# Email: sunxidong9999@gmail.com")
call append(4,"# Created: ".strftime("%Y-%m-%d %H:%M:%S"))
call append(5,"# Last modified: ".strftime("%Y-%m-%d %H:%M:%S"))
call append(6,"# Description: ")
call append(7,"##########################################################")
echohl WarningMsg | echo "Successful in adding the copyright." | echohl None
endfunction
function AddAuthor_M()
let n=1
while n < 7
let line = getline(n)
if line =~'^#\s*\S*Last\s*modified\s*:\s*\S*.*$'
call UpdateTitle_M()
return
endif
let n = n + 1
endwhile
call AddTitle_M()
endfunction
" 设置快捷键,按F10后向当前文件头部添加注释(#格式)
map <F10> ms:call AddAuthor_M()<cr>'s
"==============================================================
" 配置cscope,打开文件时自动加载cscope.out
if has("cscope") && filereadable("/usr/bin/cscope")
set csprg=/usr/bin/cscope
set csto=0
set cst
set nocsverb
" add any database in current directory
if filereadable("cscope.out")
cs add cscope.out
" else add database pointed to by environment
elseif $CSCOPE_DB != ""
cs add $CSCOPE_DB
endif
set csverb
endif
" 配置cscope快捷键
nmap <C-\>g :cs find g <C-R>=expand("<cword>")<CR><CR>
nmap <C-\>s :cs find s <C-R>=expand("<cword>")<CR><CR>
nmap <C-\>c :cs find c <C-R>=expand("<cword>")<CR><CR>
nmap <C-\>t :cs find t <C-R>=expand("<cword>")<CR><CR>
nmap <C-\>e :cs find e <C-R>=expand("<cword>")<CR><CR>
nmap <C-\>f :cs find f <C-R>=expand("<cfile>")<CR><CR>
nmap <C-\>i :cs find i ^<C-R>=expand("<cfile>")<CR>$<CR>
nmap <C-\>d :cs find d <C-R>=expand("<cword>")<CR><CR>
|