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
|
"======================================================================
"
" init-config.vim - 正常模式下的配置,在 init-basic.vim 后调用
"
" Created by skywind on 2018/05/30
" Last Modified: 2018/05/30 19:20:46
"
"======================================================================
" vim: set ts=4 sw=4 tw=78 noet :
" Open help page in a new tab
autocmd BufEnter *.txt if &filetype == 'help' | wincmd T | endif
"----------------------------------------------------------------------
" 有 tmux 何没有的功能键超时(毫秒)
"----------------------------------------------------------------------
if $TMUX != ''
set ttimeoutlen=30
elseif &ttimeoutlen > 80 || &ttimeoutlen <= 0
set ttimeoutlen=80
endif
"----------------------------------------------------------------------
" 终端下允许 ALT,详见:http://www.skywind.me/blog/archives/2021
" 记得设置 ttimeout (见 init-basic.vim) 和 ttimeoutlen (上面)
"----------------------------------------------------------------------
if has('nvim') == 0 && has('gui_running') == 0
function! s:metacode(key)
exec "set <M-".a:key.">=\e".a:key
endfunc
for i in range(10)
call s:metacode(nr2char(char2nr('0') + i))
endfor
for i in range(26)
call s:metacode(nr2char(char2nr('a') + i))
call s:metacode(nr2char(char2nr('A') + i))
endfor
for c in [',', '.', '/', ';', '{', '}']
call s:metacode(c)
endfor
for c in ['?', ':', '-', '_', '+', '=', "'"]
call s:metacode(c)
endfor
endif
"----------------------------------------------------------------------
" 终端下功能键设置
"----------------------------------------------------------------------
function! s:key_escape(name, code)
if has('nvim') == 0 && has('gui_running') == 0
exec "set ".a:name."=\e".a:code
endif
endfunc
"----------------------------------------------------------------------
" 功能键终端码矫正
"----------------------------------------------------------------------
call s:key_escape('<F1>', 'OP')
call s:key_escape('<F2>', 'OQ')
call s:key_escape('<F3>', 'OR')
call s:key_escape('<F4>', 'OS')
call s:key_escape('<S-F1>', '[1;2P')
call s:key_escape('<S-F2>', '[1;2Q')
call s:key_escape('<S-F3>', '[1;2R')
call s:key_escape('<S-F4>', '[1;2S')
call s:key_escape('<S-F5>', '[15;2~')
call s:key_escape('<S-F6>', '[17;2~')
call s:key_escape('<S-F7>', '[18;2~')
call s:key_escape('<S-F8>', '[19;2~')
call s:key_escape('<S-F9>', '[20;2~')
call s:key_escape('<S-F10>', '[21;2~')
call s:key_escape('<S-F11>', '[23;2~')
call s:key_escape('<S-F12>', '[24;2~')
"----------------------------------------------------------------------
" 防止tmux下vim的背景色显示异常
" Refer: http://sunaku.github.io/vim-256color-bce.html
"----------------------------------------------------------------------
if &term =~ '256color' && $TMUX != ''
" disable Background Color Erase (BCE) so that color schemes
" render properly when inside 256-color tmux and GNU screen.
" see also http://snk.tuxfamily.org/log/vim-256color-bce.html
set t_ut=
endif
"----------------------------------------------------------------------
" 备份设置
"----------------------------------------------------------------------
" 允许备份
set backup
" 保存时备份
set writebackup
" 备份文件地址,统一管理
set backupdir=~/.vim/tmp
" 备份文件扩展名
set backupext=.bak
" 禁用交换文件
set noswapfile
" 创建目录,并且忽略可能出现的警告
silent! call mkdir(expand('~/.vim/tmp'), "p", 0755)
"----------------------------------------------------------------------
" 配置微调
"----------------------------------------------------------------------
" 修正 ScureCRT/XShell 以及某些终端乱码问题,主要原因是不支持一些
" 终端控制命令,比如 cursor shaping 这类更改光标形状的 xterm 终端命令
" 会令一些支持 xterm 不完全的终端解析错误,显示为错误的字符,比如 q 字符
" 如果你确认你的终端支持,不会在一些不兼容的终端上运行该配置,可以注释
if has('nvim')
set guicursor=
elseif (!has('gui_running')) && has('terminal') && has('patch-8.0.1200')
let g:termcap_guicursor = &guicursor
let g:termcap_t_RS = &t_RS
let g:termcap_t_SH = &t_SH
set guicursor=
set t_RS=
set t_SH=
endif
" 打开文件时恢复上一次光标所在位置
autocmd BufReadPost *
\ if line("'\"") > 1 && line("'\"") <= line("$") |
\ exe "normal! g`\"" |
\ endif
" 定义一个 DiffOrig 命令用于查看文件改动
if !exists(":DiffOrig")
command DiffOrig vert new | set bt=nofile | r ++edit # | 0d_ | diffthis
\ | wincmd p | diffthis
endif
"----------------------------------------------------------------------
" 文件类型微调
"----------------------------------------------------------------------
augroup InitFileTypesGroup
" 清除同组的历史 autocommand
au!
" C/C++ 文件使用 // 作为注释
au FileType c,cpp setlocal commentstring=//\ %s
" markdown 允许自动换行
au FileType markdown setlocal wrap
" lisp 进行微调
au FileType lisp setlocal ts=8 sts=2 sw=2 et
" scala 微调
au FileType scala setlocal sts=4 sw=4 noet
" haskell 进行微调
au FileType haskell setlocal et
" quickfix 隐藏行号
au FileType qf setlocal nonumber
" 强制对某些扩展名的 filetype 进行纠正
au BufNewFile,BufRead *.as setlocal filetype=actionscript
au BufNewFile,BufRead *.pro setlocal filetype=prolog
au BufNewFile,BufRead *.es setlocal filetype=erlang
au BufNewFile,BufRead *.asc setlocal filetype=asciidoc
au BufNewFile,BufRead *.vl setlocal filetype=verilog
au BufRead /tmp/mutt-* set tw=72
augroup END
|