aboutsummaryrefslogtreecommitdiffhomepage
path: root/vim/init/config.vim
diff options
context:
space:
mode:
Diffstat (limited to 'vim/init/config.vim')
-rw-r--r--vim/init/config.vim182
1 files changed, 182 insertions, 0 deletions
diff --git a/vim/init/config.vim b/vim/init/config.vim
new file mode 100644
index 0000000..7e08ebf
--- /dev/null
+++ b/vim/init/config.vim
@@ -0,0 +1,182 @@
1"======================================================================
2"
3" init-config.vim - 正常模式下的配置,在 init-basic.vim 后调用
4"
5" Created by skywind on 2018/05/30
6" Last Modified: 2018/05/30 19:20:46
7"
8"======================================================================
9" vim: set ts=4 sw=4 tw=78 noet :
10
11" Open help page in a new tab
12autocmd BufEnter *.txt if &filetype == 'help' | wincmd T | endif
13
14
15"----------------------------------------------------------------------
16" 有 tmux 何没有的功能键超时(毫秒)
17"----------------------------------------------------------------------
18if $TMUX != ''
19 set ttimeoutlen=30
20elseif &ttimeoutlen > 80 || &ttimeoutlen <= 0
21 set ttimeoutlen=80
22endif
23
24
25"----------------------------------------------------------------------
26" 终端下允许 ALT,详见:http://www.skywind.me/blog/archives/2021
27" 记得设置 ttimeout (见 init-basic.vim) 和 ttimeoutlen (上面)
28"----------------------------------------------------------------------
29if has('nvim') == 0 && has('gui_running') == 0
30 function! s:metacode(key)
31 exec "set <M-".a:key.">=\e".a:key
32 endfunc
33 for i in range(10)
34 call s:metacode(nr2char(char2nr('0') + i))
35 endfor
36 for i in range(26)
37 call s:metacode(nr2char(char2nr('a') + i))
38 call s:metacode(nr2char(char2nr('A') + i))
39 endfor
40 for c in [',', '.', '/', ';', '{', '}']
41 call s:metacode(c)
42 endfor
43 for c in ['?', ':', '-', '_', '+', '=', "'"]
44 call s:metacode(c)
45 endfor
46endif
47
48
49"----------------------------------------------------------------------
50" 终端下功能键设置
51"----------------------------------------------------------------------
52function! s:key_escape(name, code)
53 if has('nvim') == 0 && has('gui_running') == 0
54 exec "set ".a:name."=\e".a:code
55 endif
56endfunc
57
58
59"----------------------------------------------------------------------
60" 功能键终端码矫正
61"----------------------------------------------------------------------
62call s:key_escape('<F1>', 'OP')
63call s:key_escape('<F2>', 'OQ')
64call s:key_escape('<F3>', 'OR')
65call s:key_escape('<F4>', 'OS')
66call s:key_escape('<S-F1>', '[1;2P')
67call s:key_escape('<S-F2>', '[1;2Q')
68call s:key_escape('<S-F3>', '[1;2R')
69call s:key_escape('<S-F4>', '[1;2S')
70call s:key_escape('<S-F5>', '[15;2~')
71call s:key_escape('<S-F6>', '[17;2~')
72call s:key_escape('<S-F7>', '[18;2~')
73call s:key_escape('<S-F8>', '[19;2~')
74call s:key_escape('<S-F9>', '[20;2~')
75call s:key_escape('<S-F10>', '[21;2~')
76call s:key_escape('<S-F11>', '[23;2~')
77call s:key_escape('<S-F12>', '[24;2~')
78
79
80"----------------------------------------------------------------------
81" 防止tmux下vim的背景色显示异常
82" Refer: http://sunaku.github.io/vim-256color-bce.html
83"----------------------------------------------------------------------
84if &term =~ '256color' && $TMUX != ''
85 " disable Background Color Erase (BCE) so that color schemes
86 " render properly when inside 256-color tmux and GNU screen.
87 " see also http://snk.tuxfamily.org/log/vim-256color-bce.html
88 set t_ut=
89endif
90
91
92"----------------------------------------------------------------------
93" 备份设置
94"----------------------------------------------------------------------
95
96" 允许备份
97set backup
98
99" 保存时备份
100set writebackup
101
102" 备份文件地址,统一管理
103set backupdir=~/.vim/tmp
104
105" 备份文件扩展名
106set backupext=.bak
107
108" 禁用交换文件
109set noswapfile
110
111" 创建目录,并且忽略可能出现的警告
112silent! call mkdir(expand('~/.vim/tmp'), "p", 0755)
113
114
115"----------------------------------------------------------------------
116" 配置微调
117"----------------------------------------------------------------------
118
119" 修正 ScureCRT/XShell 以及某些终端乱码问题,主要原因是不支持一些
120" 终端控制命令,比如 cursor shaping 这类更改光标形状的 xterm 终端命令
121" 会令一些支持 xterm 不完全的终端解析错误,显示为错误的字符,比如 q 字符
122" 如果你确认你的终端支持,不会在一些不兼容的终端上运行该配置,可以注释
123if has('nvim')
124 set guicursor=
125elseif (!has('gui_running')) && has('terminal') && has('patch-8.0.1200')
126 let g:termcap_guicursor = &guicursor
127 let g:termcap_t_RS = &t_RS
128 let g:termcap_t_SH = &t_SH
129 set guicursor=
130 set t_RS=
131 set t_SH=
132endif
133
134" 打开文件时恢复上一次光标所在位置
135autocmd BufReadPost *
136 \ if line("'\"") > 1 && line("'\"") <= line("$") |
137 \ exe "normal! g`\"" |
138 \ endif
139
140" 定义一个 DiffOrig 命令用于查看文件改动
141if !exists(":DiffOrig")
142 command DiffOrig vert new | set bt=nofile | r ++edit # | 0d_ | diffthis
143 \ | wincmd p | diffthis
144endif
145
146
147
148"----------------------------------------------------------------------
149" 文件类型微调
150"----------------------------------------------------------------------
151augroup InitFileTypesGroup
152
153 " 清除同组的历史 autocommand
154 au!
155
156 " C/C++ 文件使用 // 作为注释
157 au FileType c,cpp setlocal commentstring=//\ %s
158
159 " markdown 允许自动换行
160 au FileType markdown setlocal wrap
161
162 " lisp 进行微调
163 au FileType lisp setlocal ts=8 sts=2 sw=2 et
164
165 " scala 微调
166 au FileType scala setlocal sts=4 sw=4 noet
167
168 " haskell 进行微调
169 au FileType haskell setlocal et
170
171 " quickfix 隐藏行号
172 au FileType qf setlocal nonumber
173
174 " 强制对某些扩展名的 filetype 进行纠正
175 au BufNewFile,BufRead *.as setlocal filetype=actionscript
176 au BufNewFile,BufRead *.pro setlocal filetype=prolog
177 au BufNewFile,BufRead *.es setlocal filetype=erlang
178 au BufNewFile,BufRead *.asc setlocal filetype=asciidoc
179 au BufNewFile,BufRead *.vl setlocal filetype=verilog
180 au BufRead /tmp/mutt-* set tw=72
181
182augroup END