forked from TonyCrane/Beautiful_Linux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvimrc.txt
148 lines (137 loc) · 3.88 KB
/
vimrc.txt
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
set nu
syntax on
set shiftwidth=4
set softtabstop=4
set tabstop=4
set laststatus=2
set cmdheight=2
set scrolloff=4
set smartindent
set autoindent
set showcmd
set mouse=a
inoremap ( ()<ESC>i
inoremap { {}<ESC>i
inoremap {<CR> {<CR>}<ESC>O
inoremap [ []<ESC>i
inoremap " ""<ESC>i
inoremap ' ''<ESC>i
colorschem molokai
set rtp+=/usr/local/lib/python2.7/dist-packages/powerline/bindings/vim/
set t_Co=256
set foldenable
set foldmethod=manual
if version >= 603
set helplang=cn
set encoding=utf-8
endif
set termencoding=utf-8
set encoding=utf-8
set fencs=utf-8,ucs-bom,shift-jis,gb18030,gbk,gb2312,cp936
au BufRead,BufNewFile *.cpp set filetype=cpp
au BufRead,BufNewFile *.sh set filetype=sh
au BufRead,BufNewFile *.java set filetype=java
au BufRead,BufNewFile *.sh set filetype=sh
"文件标题
autocmd BufNewFile *.cpp,*.[ch],*.sh,*.java,*.py exec ":call StTitle()"
func StTitle()
if &filetype == 'sh' || &filetype == 'python'
call setline(1,"\##############################################################")
call append(line("."), "\# > File Name : ".expand("%"))
call append(line(".")+1, "\# > Author : Tony")
call append(line(".")+2, "\# > Created Time : ".strftime("%c"))
call append(line(".")+3, "\##############################################################")
call append(line(".")+4, "")
else
call setline(1,"/*************************************************************")
call append(line("."), " * > File Name : ".expand("%"))
call append(line(".")+1, " * > Author : Tony")
call append(line(".")+2, " * > Created Time : ".strftime("%c"))
call append(line(".")+3, "**************************************************************/")
call append(line(".")+4, "")
endif
if &filetype == 'sh'
call append(line(".")+5, "\#!/bin/bash")
call append(line(".")+6, "")
endif
if &filetype == 'cpp'
call append(line(".")+5, "#include<bits/stdc++.h>")
call append(line(".")+6, "using namespace std;")
call append(line(".")+7, "")
call append(line(".")+8, "int main()")
call append(line(".")+9, "{")
call append(line(".")+10, " ")
call append(line(".")+11, " return 0;")
call append(line(".")+12, "}")
endif
endfunc
map <F5> :call Run()<CR>
func! Run()
exec "w"
if &filetype == 'cpp'
exec "!run"
elseif &filetype == 'java'
exec "!javac %"
exec "!java %<"
endif
endfunc
set completeopt=preview,menu
filetype on
" pathogen
execute pathogen#infect()
" NERDTree
map <silent> <F3> :NERDTreeToggle<CR>
" Taglist
map <silent> <F4> :TlistToggle<CR>
if &filetype == 'html'
inoremap ) <c-r>=ClosePair(')')<CR>
inoremap ] <c-r>=ClosePair(']')<CR>
inoremap } <c-r>=CloseBracket()<CR>
inoremap " <c-r>=QuoteDelim('"')<CR>
inoremap ' <c-r>=QuoteDelim("'")<CR>
function ClosePair(char)
if getline('.')[col('.') - 1] == a:char
return "\<Right>"
else
return a:char
endif
endf
function CloseBracket()
if match(getline(line('.') + 1), '\s*}') < 0
return "\<CR>}"
else
return "\<Esc>j0f}a"
endif
endf
function QuoteDelim(char)
let line = getline('.')
let col = col('.')
if line[col - 2] == "\\"
"Inserting a quoted quotation mark into the string
return a:char
elseif line[col - 1] == a:char
"Escaping out of the string
return "\<Right>"
else
"Starting a string
return a:char.a:char."\<Esc>i"
endif
endf
" html自动补全
autocmd BufNewFile * setlocal filetype=html
function! InsertHtmlTag()
let pat = '\c<\w\+\s*\(\s\+\w\+\s*=\s*[''#$;,()."a-z0-9]\+\)*\s*>'
normal! a>
let save_cursor = getpos('.')
let result = matchstr(getline(save_cursor[1]), pat)
"if (search(pat, 'b', save_cursor[1]) && searchpair('<','','>','bn',0, getline('.')) > 0)
if (search(pat, 'b', save_cursor[1]))
normal! lyiwf>
normal! a</
normal! p
normal! a>
endif
:call cursor(save_cursor[1], save_cursor[2], save_cursor[3])
endfunction
inoremap > <ESC>:call InsertHtmlTag()<CR>a<CR><Esc>O
endif