-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvimrc
214 lines (181 loc) · 5.15 KB
/
vimrc
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
" Vim 标准配置方案。
if has("win32") || has("win32unix")
let g:OS#name = "win"
let g:OS#win = 1
let g:OS#mac = 0
let g:OS#unix = 0
elseif has("mac")
let g:OS#name = "mac"
let g:OS#mac = 1
let g:OS#win = 0
let g:OS#unix = 0
elseif has("unix")
let g:OS#name = "unix"
let g:OS#unix = 1
let g:OS#win = 0
let g:OS#mac = 0
endif
if has("gui_running")
let g:OS#gui = 1
else
let g:OS#gui = 0
endif
set nocompatible
if g:OS#win
source $VIMRUNTIME/vimrc_example.vim
source $VIMRUNTIME/mswin.vim
behave mswin
endif
filetype plugin on
filetype indent on
syntax on
filetype on
" 编码设置
set encoding=utf-8
set termencoding=utf-8
set fileencoding=utf-8
set fileencodings=ucs-bom,utf-8,cp936,gb18030,big5,euc-jp,euc-kr,latin1
set langmenu=zh_CN.utf-8
source $VIMRUNTIME/delmenu.vim
source $VIMRUNTIME/menu.vim
language messages zh_CN.UTF-8
" 文件格式,默认 ffs=dos,unix
set fileformat=unix
set fileformats=unix,dos,mac
" 设置窗口默认大小。
set columns=90
set lines=30
" 字体设置
" @see http://support.microsoft.com/kb/306527/zh-cn
" @see http://www.gracecode.com/archives/1545/
" @see http://blog.xianyun.org/2009/09/14/vim-fonts.html
if g:OS#win
set guifont=Courier_New:h12:cANSI
elseif g:OS#mac
set guifont=Courier_New:h16
elseif g:OS#unix
endif
" 交换文件(swrap file),自动备份(auto backup)设置。
set nobackup
if g:OS#win
set directory=$VIM\tmp
else
set directory=~/.tmp
endif
" 持久化撤销设置。
if has("persistent_undo")
set undofile
set undolevels=1000
if g:OS#win
set undodir=$VIM\undodir
au BufWritePre undodir/* setlocal noundofile
else
set undodir=~/.undodir
au BufWritePre ~/.undodir/* setlocal noundofile
endif
endif
" Tabs
set softtabstop=4
set expandtab " replace tab to whitespace.
set tabstop=4 " show tab indent word space.
set shiftwidth=4 " tab length
set linebreak " break full word.
set autoindent " new line indent same this line.
set smartindent
set splitright
"set splitbelow
" 设置设置。
set foldmethod=syntax
set foldlevel=6
set foldcolumn=0
set ignorecase
set smartcase
set number " 显示行号。
" fixed.
set scrolloff=3
" 切换显示/隐藏菜单栏、工具栏。
" @see http://liyanrui.is-programmer.com/articles/1791/gvim-menu-and-toolbar-toggle.html
if g:OS#gui
set guioptions-=m
set guioptions-=T
map <silent> <F2> :if &guioptions =~# 'T' <Bar>
\set guioptions-=T <Bar>
\set guioptions-=m <bar>
\else <Bar>
\set guioptions+=T <Bar>
\set guioptions+=m <Bar>
\endif<CR>
endif
if g:OS#gui
set autochdir
set colorcolumn=81
hi colorcolumn guibg=#444444
" for Vim72-
"syn match out80 /\%80v./ containedin=ALL
"hi out80 guifg=#333333 guibg=#ffffff
endif
" 设置宽度不明的文字(如 “”①②→ )为双宽度文本。
" @see http://blog.sina.com.cn/s/blog_46dac66f010006db.html
set ambiwidth=double
" 高亮当前行
" highlight CurrentLine guibg=darkgrey guifg=white
" au! Cursorhold * exe 'match CurrentLine /\%' . line('.') . 'l.*/'
" set ut=100
"
" set cursorcolumn
set cursorline
if g:OS#win
hi cursorline gui=underline guibg=NONE cterm=underline
endif
set history=500
" Show tab number in your tab line
" @see http://vim.wikia.com/wiki/Show_tab_number_in_your_tab_line
" :h tabline
if g:OS#gui
" TODO: for MacVim.
set guitablabel=%N.%t
endif
" 自动换行。
" NOTE: this setting will change text source.
" set textwidth=80
" set fo+=m
" 共享系统剪贴板(yank的时候同时存储到剪贴板中)。
"set clipboard+=unnamed
" 状态栏。
set laststatus=2
set statusline=%t\ %1*%m%*\ %1*%r%*\ %2*%h%*%w%=%l%3*/%L(%p%%)%*,%c%V]\ [%b:0x%B]\ [%{&ft==''?'TEXT':toupper(&ft)},%{toupper(&ff)},%{toupper(&fenc!=''?&fenc:&enc)}%{&bomb?',BOM':''}%{&eol?'':',NOEOL'}]
"let &statusline=' %t %{&mod?(&ro?"*":"+"):(&ro?"=":" ")} %1*|%* %{&ft==""?"any":&ft} %1*|%* %{&ff} %1*|%* %{(&fenc=="")?&enc:&fenc}%{(&bomb?",BOM":"")} %1*|%* %=%1*|%* 0x%B %1*|%* (%l,%c%V) %1*|%* %L %1*|%* %P'
hi User1 guibg=red guifg=yellow
hi User2 guibg=#008000 guifg=white
hi User3 guibg=#C2BFA5 guifg=#999999
" ------------------------------- Mappings ------------------------------ {{{
" Normal Mode, Visual Mode, and Select Mode,
" use <Tab> and <Shift-Tab> to indent
" @see http://c9s.blogspot.com/2007/10/vim-tips.html
"nmap <tab> v> " :h ctrl-i :h <tab>
"nmap <s-tab> v<
vmap <tab> >gv
vmap <s-tab> <gv
" 选中一段文字并全文搜索这段文字
vnoremap * y/<C-R>=escape(@", '\\/.*$^~[]')<CR><CR>
vnoremap # y?<C-R>=escape(@", '\\/.*$^~[]')<CR><CR>
" 窗口间的移动设置。
map <C-j> <C-W>j
map <C-k> <C-W>k
map <C-l> <C-W>l
map <C-h> <C-W>h
map <C-kPlus> <C-w>+
map <C-kMinus> <C-w>-
map <C-S-kPlus> <C-w>_
map <C-S-kMinus> <C-w>_
" TODO: smart <Home>
function! RemoveTrailingWhitespace()
if &ft != "diff"
let b:curcol = col(".")
let b:curline = line(".")
silent! %s/\s\+$//
silent! %s/\(\s*\n\)\+\%$//
call cursor(b:curline, b:curcol)
endif
endfunction
autocmd BufWritePre * call RemoveTrailingWhitespace()