-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvimrc
More file actions
270 lines (238 loc) · 6.93 KB
/
vimrc
File metadata and controls
270 lines (238 loc) · 6.93 KB
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
"====================
" Author: ZhangTianyi
" Version: 1.2
" Email: tyz1024@gmail.com
" Sections:
" -> Initial Plugins
" -> General Settings
" -> Display Settings
" -> FileEncode Settings
" -> Filetype Settings
" -> HotKey Settings
" -> Others
"====================
" Initial Plugins
"====================
" 判断当前操作系统
let g:isdos = 0
let g:isunix = 0
if(has("win64") || has("win32") || has("win95") || has("win16"))
let g:isdos = 1
else
let g:isunix = 1
endif
" 设置Leader键
let mapleader = ','
" 加载Vundle插件
if g:isunix
if filereadable(expand("~/.vimrc.bundles"))
source ~/.vimrc.bundles
endif
else
if filereadable(expand("~/_vimrc.bundles"))
source ~/_vimrc.bundles
endif
endif
" 文件类型检测
filetype plugin indent on
"====================
" General Settings
"====================
" 允许退格键删除任意内容
set backspace=indent,eol,start
" 允许光标跨越边界
set whichwrap+=<,>,h,l
" 自动读取文件内容
set autoread
" 历史记录
set nobackup " 取消备份文件
set noswapfile " 取消交换文件
set history=2000 " 最大历史记录
" 打开文件回到之前位置(依据.viminfo)
if has('autocmd')
autocmd BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$")
\ | exe "normal! g'\""
\ | exe "normal! g`\""
\ | exe "normal! zz" | endif
endif
" 创建持久性撤销记录
if has('persistent_undo')
set undofile
if g:isunix
set undodir=/tmp/vimundo/
" :help set
"space between '=' and {value} is not allowed.
else
let &undodir = expand('$HOME/vimfiles/vimundo/')
" :help let
"'let &{option}' equals to 'set {option}', but more flexible.
endif
silent call mkdir(&undodir, 'p')
endif
" remain the content after quit
set t_ti= t_te=
" remember info about open buffers on close
set viminfo^=%
" enabled to paste more than 50 lines
set viminfo='1000,<1000
" turn magic on for regular expressions
set magic
" 支持在Visual模式下,通过C-y复制到系统剪切板
vnoremap <C-y> "+y
" 支持在normal模式下,通过C-p粘贴系统剪切板
nnoremap <C-p> "*p
"====================
" Display Settings
"====================
" 基础设置
syntax enable " 语法高亮
set number " 显示行号
set ruler " 显示标尺
set autoindent " 自动缩进
set smartindent " 智能缩进
set linebreak " 智能折行
set showcmd " 显示正在输入指令
set hlsearch " 高亮显示搜索结果
set ignorecase " 搜索时忽略大小写
set smartcase " 智能区分大小写
" 文本格式
set expandtab " 自动将Tab转换为空格
set tabstop=4 " 制表符空格数
set shiftwidth=4 " normal模式下缩进空格数
set softtabstop=4 " Tab转换的空格数目
set scrolloff=7 " 自动翻页最小距离
set textwidth=1000 " 设置最大行宽
" Relative Line Number
set relativenumber number
au FocusLost * :set norelativenumber number
au FocusGained * :set relativenumber
" Use Absolute Line Number while typing
autocmd InsertEnter * :set norelativenumber number
autocmd InsertLeave * :set relativenumber
function! NumberToggle()
if(&relativenumber == 1)
set norelativenumber number
else
set relativenumber
endif
endfunc
nnoremap <C-n> :call NumberToggle()<CR>
" 高亮配色
set t_Co=256 " 开启256色
set cursorline " 显示光标标线
set cursorcolumn
highlight CursorLine cterm=NONE ctermfg=NONE ctermbg=darkgray
highlight CursorColumn cterm=NONE ctermfg=NONE ctermbg=darkgray
highlight CursorLineNr cterm=NONE ctermfg=lightgreen ctermbg=NONE
" 设置Visual模式下选中区域颜色
highlight Visual cterm=NONE ctermfg=NONE ctermbg=gray
" 设置标记一列的背景颜色和数字一行颜色一致
hi! link SignColumn LineNr
hi! link ShowMarksHLl DiffAdd
hi! link ShowMarksHLu DiffChange
" 防止错误整行标红导致看不清
highlight clear SpellBad
highlight SpellBad term=standout ctermfg=1 term=underline cterm=underline
highlight clear SpellCap
highlight SpellCap term=underline cterm=underline
highlight clear SpellRare
highlight SpellRare term=underline cterm=underline
highlight clear SpellLocal
highlight SpellLocal term=underline cterm=underline
" 图形界面模式下补充参数
if has("gui_running")
set guifont=Monaco:h14
if has("gui_gtk2") "GTK2
set guifont=Monaco\ 12, Monospace\ 12
endif
set guioptions-=T
set guioptions+=e
set guioptions-=r
set guioptions-=L
set guitablabel=%M\ %t
set showtabline=1
set linespace=2
set noimd
endif
"====================
" FileEncode Settings
"====================
" 文件编码
set encoding=utf-8
set fileencoding=utf-8
" 自动判断编码时,依次尝试以下编码:
set fileencodings=ucs-bom,utf-8,cp936,gb18030,big5,euc-jp,euc-kr,latin1
set helplang=cn
" 下面这句只影响非图形界面下的Vim
set termencoding=utf-8
" Use Unix as the standard file type
set ffs=unix,dos,mac
if g:isunix
set ff=unix
else
set ff=dos
endif
" 如遇Unicode值大于255的文本,不必等到空格再折行。
set formatoptions+=m
" 合并两行中文时,不在中间加空格:
set formatoptions+=B
"====================
" Filetype Settings
"====================
" 突出显示超出第80列的所有内容及行末空格
highlight OverLength cterm=NONE ctermfg=white ctermbg=darkred
au BufRead,BufNewFile *.py match OverLength /\%>80v.\+\|\s\+$/
" 文件保存时删除句尾空格
function! DeleteTrailingWS() abort
normal mz
%s/\s\+$//ge
normal `z
endfunc
autocmd BufWrite * :call DeleteTrailingWS()
nnoremap <Leader><Space> :call DeleteTrailingWS()
"====================
" HotKey Settings
"====================
" 快速进入命令行
nnoremap ; :
" 命令行模式加强
cnoremap <C-j> <t_kd>
cnoremap <C-k> <t_ku>
cnoremap <C-a> <Home>
cnoremap <C-e> <End>
" Use sane regexes
nnoremap / /\v
vnoremap / /\v
" Keep search pattern at the center of the screen
nnoremap <silent> n nzz
nnoremap <silent> N Nzz
nnoremap <silent> * *zz
nnoremap <silent> # #zz
nnoremap <silent> g* g*zz
" 选择全部
nnoremap <Leader>sa ggVG"
" 选择块
nnoremap <Leader>v V'}
" 去掉搜索高亮
noremap <silent> <Leader>/ :noh<CR>
"====================
" Others
"====================
if g:isunix
autocmd! bufwritepost .vimrc source % "vimrc文件修改之后自动加载(linux)
else
autocmd! bufwritepost _vimrc source % "vimrc文件修改之后自动加载(windows)
endif
" auto-complete configuration
set completeopt=longest,menu
" 增强模式中的命令行自动完成操作
set wildmenu
set wildignore+=*.o,*~,*.pyc,*.class
" 离开插入模式后自动关闭预览窗口
autocmd InsertLeave * if pumvisible() == 0 | pclose | endif
" 若下拉菜单显示,则映射为前值。<C-y>确认并退出;<C-e>取消并退出。
inoremap <expr> <CR> pumvisible() ? "\<C-y>" : "\<CR>"
inoremap <expr> <ESC> pumvisible() ? "\<C-e>" : "\<ESC>"
inoremap <expr> <Down> pumvisible() ? "\<C-n>" : "\<Down>"
inoremap <expr> <Up> pumvisible() ? "\<C-p>" : "\<Up>"
"End-of-Config