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.vim174
1 files changed, 99 insertions, 75 deletions
diff --git a/vim/init/config.vim b/vim/init/config.vim
index 489521f..20beab2 100644
--- a/vim/init/config.vim
+++ b/vim/init/config.vim
@@ -10,25 +10,49 @@
10" Open help page in a new tab 10" Open help page in a new tab
11autocmd BufEnter *.txt if &filetype == 'help' | wincmd T | endif 11autocmd BufEnter *.txt if &filetype == 'help' | wincmd T | endif
12 12
13" Quickly edit html tag class 13" Automatically apply filetype by shebang
14function! s:ChangeAttr(pattern) 14function! s:ApplyShebang()
15 15 let l:filetype = matchstr(getline(1), '^#!.*[ /]\zs[[:alnum:]]\+$')
16 let l:attr = matchstr(getline('.'), a:pattern.'="') 16 let l:shebangMatch = #{node: "javascript"}
17 if l:attr == '' 17 if l:filetype != ""
18 let l:all_attrs = matchstr(getline('.'), '<[[:alnum:]]\+\zs\s\?[^>]*>\ze') 18 if has_key(shebangMatch, l:filetype)
19 execute 's/'.l:all_attrs.'/ '.a:pattern.'=""'.l:all_attrs.'/' 19 let l:filetype = shebangMatch[l:filetype]
20 noh
21 normal! 0f"l
22 startinsert
23 else
24 normal! 0
25 call search(l:attr)
26 normal! f"l
27 noh
28 startinsert
29 endif 20 endif
21 echo "filetype from shebang: ".l:filetype
22 execute "set filetype=".l:filetype
23 endif
30endfunction 24endfunction
25autocmd BufReadPost * call <SID>ApplyShebang()
26
27" For vimscript
28if executable('vim-language-server')
29 echo "set vim language server"
30 au User lsp_setup call lsp#register_server({
31 \ 'name': 'vimscript-language-server',
32 \ 'cmd': {server_info->['vimscript-language-server']},
33 \ 'whitelist': ['vim'],
34 \ })
35endif
31 36
37" html
38" Quickly edit html tag class
39function! s:ChangeAttr(pattern)
40 let l:attr = matchstr(getline('.'), a:pattern.'="')
41 if l:attr == ''
42 let l:all_attrs = matchstr(getline('.'), '<[[:alnum:]]\+\zs\s\?[^>]*>\ze')
43 execute 's/'.l:all_attrs.'/ '.a:pattern.'=""'.l:all_attrs.'/'
44 noh
45 normal! 0f"l
46 startinsert
47 else
48 normal! 0
49 call search(l:attr)
50 normal! f"l
51 noh
52 startinsert
53 endif
54endfunction
55" Edit class and id for javascript files
32autocmd FileType html nnoremap <leader>cl :call <SID>ChangeAttr("class")<CR> 56autocmd FileType html nnoremap <leader>cl :call <SID>ChangeAttr("class")<CR>
33autocmd BufLeave nunmap <leader>cl 57autocmd BufLeave nunmap <leader>cl
34autocmd FileType html nnoremap <leader>id :call <SID>ChangeAttr("id")<CR> 58autocmd FileType html nnoremap <leader>id :call <SID>ChangeAttr("id")<CR>
@@ -38,9 +62,9 @@ autocmd BufLeave nunmap <leader>id
38" 有 tmux 何没有的功能键超时(毫秒) 62" 有 tmux 何没有的功能键超时(毫秒)
39"---------------------------------------------------------------------- 63"----------------------------------------------------------------------
40if $TMUX != '' 64if $TMUX != ''
41 set ttimeoutlen=30 65 set ttimeoutlen=30
42elseif &ttimeoutlen > 80 || &ttimeoutlen <= 0 66elseif &ttimeoutlen > 80 || &ttimeoutlen <= 0
43 set ttimeoutlen=80 67 set ttimeoutlen=80
44endif 68endif
45 69
46 70
@@ -49,22 +73,22 @@ endif
49" 记得设置 ttimeout (见 init-basic.vim) 和 ttimeoutlen (上面) 73" 记得设置 ttimeout (见 init-basic.vim) 和 ttimeoutlen (上面)
50"---------------------------------------------------------------------- 74"----------------------------------------------------------------------
51if has('nvim') == 0 && has('gui_running') == 0 75if has('nvim') == 0 && has('gui_running') == 0
52 function! s:metacode(key) 76 function! s:metacode(key)
53 exec "set <M-".a:key.">=\e".a:key 77 exec "set <M-".a:key.">=\e".a:key
54 endfunc 78 endfunc
55 for i in range(10) 79 for i in range(10)
56 call s:metacode(nr2char(char2nr('0') + i)) 80 call s:metacode(nr2char(char2nr('0') + i))
57 endfor 81 endfor
58 for i in range(26) 82 for i in range(26)
59 call s:metacode(nr2char(char2nr('a') + i)) 83 call s:metacode(nr2char(char2nr('a') + i))
60 call s:metacode(nr2char(char2nr('A') + i)) 84 call s:metacode(nr2char(char2nr('A') + i))
61 endfor 85 endfor
62 for c in [',', '.', '/', ';', '{', '}'] 86 for c in [',', '.', '/', ';', '{', '}']
63 call s:metacode(c) 87 call s:metacode(c)
64 endfor 88 endfor
65 for c in ['?', ':', '-', '_', '+', '=', "'"] 89 for c in ['?', ':', '-', '_', '+', '=', "'"]
66 call s:metacode(c) 90 call s:metacode(c)
67 endfor 91 endfor
68endif 92endif
69 93
70 94
@@ -72,9 +96,9 @@ endif
72" 终端下功能键设置 96" 终端下功能键设置
73"---------------------------------------------------------------------- 97"----------------------------------------------------------------------
74function! s:key_escape(name, code) 98function! s:key_escape(name, code)
75 if has('nvim') == 0 && has('gui_running') == 0 99 if has('nvim') == 0 && has('gui_running') == 0
76 exec "set ".a:name."=\e".a:code 100 exec "set ".a:name."=\e".a:code
77 endif 101 endif
78endfunc 102endfunc
79 103
80 104
@@ -104,10 +128,10 @@ call s:key_escape('<S-F12>', '[24;2~')
104" Refer: http://sunaku.github.io/vim-256color-bce.html 128" Refer: http://sunaku.github.io/vim-256color-bce.html
105"---------------------------------------------------------------------- 129"----------------------------------------------------------------------
106if &term =~ '256color' && $TMUX != '' 130if &term =~ '256color' && $TMUX != ''
107 " disable Background Color Erase (BCE) so that color schemes 131 " disable Background Color Erase (BCE) so that color schemes
108 " render properly when inside 256-color tmux and GNU screen. 132 " render properly when inside 256-color tmux and GNU screen.
109 " see also http://snk.tuxfamily.org/log/vim-256color-bce.html 133 " see also http://snk.tuxfamily.org/log/vim-256color-bce.html
110 set t_ut= 134 set t_ut=
111endif 135endif
112 136
113 137
@@ -143,26 +167,26 @@ silent! call mkdir(expand('~/.vim/tmp'), "p", 0755)
143" 会令一些支持 xterm 不完全的终端解析错误,显示为错误的字符,比如 q 字符 167" 会令一些支持 xterm 不完全的终端解析错误,显示为错误的字符,比如 q 字符
144" 如果你确认你的终端支持,不会在一些不兼容的终端上运行该配置,可以注释 168" 如果你确认你的终端支持,不会在一些不兼容的终端上运行该配置,可以注释
145if has('nvim') 169if has('nvim')
146 set guicursor= 170 set guicursor=
147elseif (!has('gui_running')) && has('terminal') && has('patch-8.0.1200') 171elseif (!has('gui_running')) && has('terminal') && has('patch-8.0.1200')
148 let g:termcap_guicursor = &guicursor 172 let g:termcap_guicursor = &guicursor
149 let g:termcap_t_RS = &t_RS 173 let g:termcap_t_RS = &t_RS
150 let g:termcap_t_SH = &t_SH 174 let g:termcap_t_SH = &t_SH
151 set guicursor= 175 set guicursor=
152 set t_RS= 176 set t_RS=
153 set t_SH= 177 set t_SH=
154endif 178endif
155 179
156" 打开文件时恢复上一次光标所在位置 180" 打开文件时恢复上一次光标所在位置
157autocmd BufReadPost * 181autocmd BufReadPost *
158 \ if line("'\"") > 1 && line("'\"") <= line("$") | 182 \ if line("'\"") > 1 && line("'\"") <= line("$") |
159 \ exe "normal! g`\"" | 183 \ exe "normal! g`\"" |
160 \ endif 184 \ endif
161 185
162" 定义一个 DiffOrig 命令用于查看文件改动 186" 定义一个 DiffOrig 命令用于查看文件改动
163if !exists(":DiffOrig") 187if !exists(":DiffOrig")
164 command DiffOrig vert new | set bt=nofile | r ++edit # | 0d_ | diffthis 188 command DiffOrig vert new | set bt=nofile | r ++edit # | 0d_ | diffthis
165 \ | wincmd p | diffthis 189 \ | wincmd p | diffthis
166endif 190endif
167 191
168 192
@@ -172,16 +196,16 @@ endif
172"---------------------------------------------------------------------- 196"----------------------------------------------------------------------
173augroup InitFileTypesGroup 197augroup InitFileTypesGroup
174 198
175 " 清除同组的历史 autocommand 199 " 清除同组的历史 autocommand
176 au! 200 au!
177 201
178 " C/C++ 文件使用 // 作为注释 202 " C/C++ 文件使用 // 作为注释
179 au FileType c,cpp setlocal commentstring=//\ %s 203 au FileType c,cpp setlocal commentstring=//\ %s
180 204
181 " markdown 允许自动换行 205 " markdown 允许自动换行
182 au FileType markdown setlocal wrap 206 au FileType markdown setlocal wrap
183 au FileType markdown set sw=2 207 au FileType markdown set sw=2
184 au FileType markdown set ts=2 208 au FileType markdown set ts=2
185 209
186 " Fold markdown by heading level 210 " Fold markdown by heading level
187 function MarkdownLevel() 211 function MarkdownLevel()
@@ -195,24 +219,24 @@ augroup InitFileTypesGroup
195 au FileType markdown setlocal foldexpr=MarkdownLevel() 219 au FileType markdown setlocal foldexpr=MarkdownLevel()
196 au FileType markdown setlocal foldmethod=expr 220 au FileType markdown setlocal foldmethod=expr
197 221
198 " lisp 进行微调 222 " lisp 进行微调
199 au FileType lisp setlocal ts=8 sts=2 sw=2 et 223 au FileType lisp setlocal ts=8 sts=2 sw=2 et
200 224
201 " scala 微调 225 " scala 微调
202 au FileType scala setlocal sts=4 sw=4 noet 226 au FileType scala setlocal sts=4 sw=4 noet
203 227
204 " haskell 进行微调 228 " haskell 进行微调
205 au FileType haskell setlocal et 229 au FileType haskell setlocal et
206 230
207 " quickfix 隐藏行号 231 " quickfix 隐藏行号
208 au FileType qf setlocal nonumber 232 au FileType qf setlocal nonumber
209 233
210 " 强制对某些扩展名的 filetype 进行纠正 234 " 强制对某些扩展名的 filetype 进行纠正
211 au BufNewFile,BufRead *.as setlocal filetype=actionscript 235 au BufNewFile,BufRead *.as setlocal filetype=actionscript
212 au BufNewFile,BufRead *.pro setlocal filetype=prolog 236 au BufNewFile,BufRead *.pro setlocal filetype=prolog
213 au BufNewFile,BufRead *.es setlocal filetype=erlang 237 au BufNewFile,BufRead *.es setlocal filetype=erlang
214 au BufNewFile,BufRead *.asc setlocal filetype=asciidoc 238 au BufNewFile,BufRead *.asc setlocal filetype=asciidoc
215 au BufNewFile,BufRead *.vl setlocal filetype=verilog 239 au BufNewFile,BufRead *.vl setlocal filetype=verilog
216 au BufRead /tmp/mutt-* set tw=72 240 au BufRead /tmp/mutt-* set tw=72
217 241
218augroup END 242augroup END