-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvimrc-mini
281 lines (236 loc) · 9.55 KB
/
vimrc-mini
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
271
272
273
274
275
276
277
278
279
280
281
"============================================================================
" FileName: .vimrc
" Author: Huoty
" Email: [email protected]
" HomePage: http://www.konghy.cn/
" Version: 1.0.0
" CreateDate: 2016-10-10 10:08:06
" History: huoty 2016-10-10 1.0.0 第一个版本
" huoty 2017-04-12 1.1.0 功能增强
" huoty 2019-05-21 1.2.0 优化配置;新建 lua 文件时添加插入默认头注释
" Description: Linux 下 vim 用户自定义配置文件。
"============================================================================
" 基本设置
syntax on "开启语法高亮
set nocompatible "去掉 vi 的一致性
set number "显示行号
set scrolloff=3 "光标移动到 Buffer 的顶部和底部时保持 3 行距离
set viminfo+=! "保存全局变量
set confirm "处理未保存或者只读文件时, 给出提示
set autoread "当文件在外部被修改,自动更新该文件
set showcmd "标尺的右边显示未完成的命令
set history=500 "保留历史记录
set nobackup "禁止自动备份
set showmode "显示文本处理模式
set autochdir "将当前编辑文件的路径设置为当前路径
set fileformat=unix "设置以 unix 的格式保存文件
"set whichwrap+=<,>,h,l "允许 backspace 和光标键跨越行边界
" 更快速的编辑
set lazyredraw
set ttyfast
" 高亮行和列
set cursorline "突出显示当前行
"set cursorcolumn "突出显示当前列
" 设置字体
set guifont=Monaco:h12:cANSI
set guifontwide=幼圆:h12:cGB2312
" 设置主题
colorscheme ron
set background=dark
" 隐藏滚动条
set guioptions-=r
set guioptions-=L
set guioptions-=b
" 启用鼠标
"set mouse=a
"set selection=exclusive
"set selectmode=mouse,key
" 记录上一次打开文件的位置
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal g`\"" |
\ endif
" 侦测文件类型插件
filetype on "侦测文件类型插件
filetype plugin on "载入文件类型插件
filetype plugin indent on "为特定文件类型载入相关缩进文件
" 缩进与括号匹配
set autoindent "自动缩进
set smartindent "智能缩进
set showmatch "显示匹配的括号
set matchtime=5 "匹配括号高亮的时间
set backspace=2 "使回格键(backspace)正常处理 indent, eol, start 等
" Tab 设置
set tabstop=4 "设置 Tab 长度
set shiftwidth=4 "缩进尺寸为 4 个空格
set softtabstop=4
set smarttab "只按一下 Backspace 就删除 4 个空格
set expandtab "编辑时将所有 Tab 替换为空格
" 编码设置
set fileencodings=utf-8,gb2312,gbk,gb18030,ucs-bom,cp936,big5,euc-jp,euc-kr,latin1
set fileencoding=utf-8
set termencoding=utf-8
" 搜索设置
set incsearch "实时匹配
set hlsearch "高亮搜索项
set ignorecase "忽略大小写
" 文本换行设置
"set nowrap "设置不自动折行
set linebreak "英文单词在换行时不被截断
set iskeyword+=_,$,@,%,#,- "带有如下符号的单词不要被换行分割
autocmd FileType text setlocal textwidth=80 "纯文本时自动换行
" 语言设置
set langmenu=zh_CN.UTF-8
set helplang=cn
" 状态栏设置
set t_Co=8
let g:Powerline_symbols='unicode'
set encoding=utf8
set laststatus=2
set statusline=%F\ %y\ %r%m%*%=[%{&fenc!=''?&fenc:&enc}][Line:%l/%L,Column:%c][%p%%]
" 自动补全
set wildmode=list:full "可用来改动补全时采用的方式
set wildmenu "使用 Tab 自动补全的时用菜单列出内容
" 输入括号和引号自动跳到中间
imap () ()<ESC>i
imap [] []<ESC>i
imap {} {}<ESC>i
imap "" ""<ESC>i
imap '' ''<ESC>i
imap <> <><ESC>
" 高亮多余的空白符
highlight ExtraWhitespace ctermbg=red guibg=red
autocmd BufWinEnter * match ExtraWhitespace /\s\+$\| \+\ze\t\+\|\t\+\zs \+/
" 识别 Python 文件类型
autocmd BufRead,BufNewFile *.py,*.pyx set filetype=python
"==========================================================================
" 快捷键映射
"==========================================================================
" 切换到粘贴模式, 避免粘贴文本错位
set pastetoggle=<F9>
" 删除文件中所有行尾多余的空格,快捷键 \w
nnoremap <leader>w :%s/\s\+$//<cr>:let @/=''<CR>
"------------------------------------------------ end ---------------------
"==========================================================================
" 新建 Shell 脚本文件时,自动添加文件头
"==========================================================================
function HeaderShell()
call setline(1, "#! /bin/bash")
call append(1, "")
call append(2, "# Author: Huoty <[email protected]>")
call append(3, "# CreateTime: " . strftime('%Y-%m-%d %T', localtime()))
call append(4, "# Script starts from here:")
normal G
normal o
normal o
endf
autocmd bufnewfile *.sh call HeaderShell()
"------------------------------------------------ end ---------------------
"==========================================================================
" 新建 Python 文件时,自动添加文件头
"==========================================================================
function HeaderPython()
call setline(1, "#! /usr/bin/env python")
call append(1, "# -*- coding: utf-8 -*-")
call append(2, "")
call append(3, "# Copyright (c) Huoty, All rights reserved")
call append(4, "# Author: Huoty <[email protected]>")
call append(5, "# CreateTime: " . strftime('%Y-%m-%d %T', localtime()))
normal G
normal o
normal o
endf
autocmd bufnewfile *.py,*.pyx call HeaderPython()
"------------------------------------------------ end ---------------------
"==========================================================================
" 新建 PHP 文件时,自动添加文件头
"==========================================================================
function HeaderPHP()
call setline(1, "<?php # Script -- " . expand("%:t"))
call append(1, "")
call append(2, "/* Author @ Huoty")
call append(3, " * Date @ " . strftime('%Y-%m-%d %T', localtime()))
call append(4, " * Brief @ ")
call append(5, " */")
call append(6, "")
call append(7, "?>")
normal G
normal O
normal O
endf
autocmd bufnewfile *.php call HeaderPHP()
"------------------------------------------------ end ---------------------
"==========================================================================
"新建 Lua 文件时,自动添加文件头
"==========================================================================
function HeaderLua()
call setline(1, "-- Copyright (c) Huoty, All rights reserved")
call append(1, "-- Author: Huoty <[email protected]>")
call append(2, "-- CreateTime: " . strftime('%Y-%m-%d %T', localtime()))
normal G
normal o
normal o
endf
autocmd bufnewfile *.lua call HeaderLua()
"------------------------------------------------ end ---------------------
"========================= 插件管理 =======================================
" Vundle 是 Vim bundle 的简称, 是一个 Vim 插件管理器.
"
" :PluginList - 列出所有已配置的插件
" :PluginInstall - 安装插件,追加 `!` 用以更新或使用 :PluginUpdate
" :PluginSearch foo - 搜索 foo ; 追加 `!` 清除本地缓存
" :PluginClean - 清除未使用插件,需要确认; 追加 `!` 自动批准移除未使用插件
"==========================================================================
filetype off "必须
"设置包括 vundle 和初始化相关的 runtime path
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'VundleVim/Vundle.vim' "让vundle管理插件版本, 必须
"插件列表:
Plugin 'vim-scripts/LargeFile' "用于打开大文件
Plugin 'scrooloose/nerdcommenter' "快速注释
Plugin 'vim-scripts/AutoComplPop' "自动提示补全
Plugin 'kien/rainbow_parentheses.vim' "括号着色
Plugin 'airblade/vim-gitgutter' "Git Diff 状态
Plugin 'terryma/vim-multiple-cursors' "多重选取
Plugin 'ctrlpvim/ctrlp.vim' "在工程中快速定位某个文件
Plugin 'dyng/ctrlsf.vim' "在工程中全局搜索某个特定的字符
call vundle#end()
filetype plugin indent on
"========================= 插件配置 =======================================
" 对相应的插件进行配置
"==========================================================================
"LargeFile 插件:
let g:LargeFile=5 "设置打开最大文件的标准为5M
"NERD_commenter 插件:
map <F3> <leader>cc "注释
map <F4> <leader>cu "取消注释
"Multiple Cursors 插件:
let g:multi_cursor_next_key='<C-n>' "选中一个
let g:multi_cursor_prev_key='<C-p>' "放弃一个, 回到上一个
let g:multi_cursor_skip_key='<C-x>' "跳过当前选中, 选中下一个
let g:multi_cursor_quit_key='<Esc>' "退出选择
"Rainbow Parentheses 插件:
let g:rbpt_colorpairs = [
\ ['brown', 'RoyalBlue3'],
\ ['Darkblue', 'SeaGreen3'],
\ ['darkgray', 'DarkOrchid3'],
\ ['darkgreen', 'firebrick3'],
\ ['darkcyan', 'RoyalBlue3'],
\ ['darkred', 'SeaGreen3'],
\ ['darkmagenta', 'DarkOrchid3'],
\ ['brown', 'firebrick3'],
\ ['gray', 'RoyalBlue3'],
\ ['darkmagenta', 'DarkOrchid3'],
\ ['Darkblue', 'firebrick3'],
\ ['darkgreen', 'RoyalBlue3'],
\ ['darkcyan', 'SeaGreen3'],
\ ['darkred', 'DarkOrchid3'],
\ ['red', 'firebrick3'],
\ ]
let g:rbpt_max = 16
let g:rbpt_loadcmd_toggle = 0
au VimEnter * RainbowParenthesesToggle
au Syntax * RainbowParenthesesLoadRound
au Syntax * RainbowParenthesesLoadSquare
au Syntax * RainbowParenthesesLoadBraces