-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvimrc.vim
More file actions
194 lines (163 loc) · 4.57 KB
/
vimrc.vim
File metadata and controls
194 lines (163 loc) · 4.57 KB
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
if v:progname =~? "evim"
finish
endif
set nocompatible
" encoding
set fileencodings=utf-8,ucs-bom,gb2312,cp936,big5
set termencoding=utf-8
set encoding=utf-8
set history=400
filetype plugin on
colorscheme desert "blue
syntax on
set autoread
set writebackup
set nobackup
set backspace=indent,eol,start
set whichwrap=b,s,<,>,[,],h,l
set ruler
set showmatch
set showcmd
set number
set incsearch
set hlsearch
"for program
set path+=.
set fileformat=unix "equal to dos2unix
set expandtab
set tabstop=4
set softtabstop=4
"shiftwidth effect while smarttab is on,else tabstop
set shiftwidth=4
:highlight OverLength ctermbg=red ctermfg=white guibg=red guifg=white
:match OverLength '\%120v.*'
"space shows
set listchars=tab:>-,trail:-
set list
set autoindent shiftwidth=4
set cindent shiftwidth=4
set tags=./tags,./TAGS,~/.tags,~/TAGS
imap <C-B> <Esc>i
imap <C-F> <Esc>la
imap <C-Z> <Esc>:w<CR><Esc>:sh<CR>
imap `( ()<Esc>i
imap `[ []<Esc>i
imap `{ {}<Esc>i
imap `I #include <><Esc>i
imap <F1> <CR>Date: <Esc>:read !date<CR>kJ
map <F2> :buffers<CR>:buffer
map <F3> :bprevious<CR>
map <F4> :bnext<CR>
map <F5> :Tlist<CR>
map <F6> :TlistUpdate<CR>
map <F7> :cprevious<CR>
map <F8> :cnext<CR>
map <F9> :w<CR> :make<CR> :copen<CR> <C-W>10_
map <F10> :call Search_Word()<CR>
map <F11> :nohlsearch<CR>
map <F12> :w<CR>
let mapleader = ","
map <silent> <leader>s :source $MYVIMRC<cr>
map <silent> <leader>e :e $MYVIMRC<cr>
"map <silent> <C-X> :q!<cr>
autocmd! bufwritepost $MYVIMRC source $MYVIMRC
"taglist
nmap <silent> <leader>tl :TlistToggle<cr> "for taglist
let Tlist_Show_One_File = 0 "不同时显示多个文件的tag,只显示当前文件的
let Tlist_File_Fold_Auto_Close = 1 "其他文件自动折叠
let Tlist_Exit_OnlyWindow = 1 "如果taglist窗口是最后一个窗口,则退出vim
let Tlist_Use_Right_Window = 1 "在右侧窗口中显示taglist窗口
let Tlist_Ctags_Cmd = '/usr/bin/ctags'
"let Tlist_Auto_Open = 1
"winmanager
nmap <C-W><C-F> :FirstExplorerWindow<cr>
nmap <C-W><C-B> :BottomExplorerWindow<cr>
nmap <silent> <leader>wm :WMToggle<cr>
let g:winManagerWindowLayout = "BufExplorer,FileExplorer"
"let g:winManagerWindowLayout = "BufExplorer,FileExplorer|TagList"
let g:winManagerWidth = 30
let g:defaultExplorer = 0
set exrc
function! ChangeCurDir(...)
let cur_dir = expand('%:h')
execute "cd " . cur_dir
endfunction
function! EditCppFile(...)
let file_prefix = expand('%:r')
if filereadable(file_prefix . ".cpp")
execute "e " . file_prefix . ".cpp"
elseif filereadable(file_prefix . ".cc")
execute "e " . file_prefix . ".cc"
elseif filereadable(file_prefix . ".c")
execute "e " . file_prefix . ".c"
endif
endfunction
function! EditHeaderFile(...)
let file_prefix = expand('%:r')
execute "e " . file_prefix . ".h"
endfunction
function! GrepCurWord(...)
let args=a:000
if empty(args)
let args=["*"]
endif
let cur_word= expand('<cword>')
execute "grep " . cur_word . " " . join(args)
endfunction
command! Se call SetPath()
command! Cd call ChangeCurDir()
command! Ecpp call EditCppFile()
command! Ehead call EditHeaderFile()
command! -nargs=* Gr call GrepCurWord(<f-args>)
set noic
"format cpp
function! CppFormat()
let file_path = expand('%:p')
execute "silent !cppfmt -i " . file_path
execute ":e"
execute ":se filetype=cpp"
endfunction
autocmd! BufWritePost *.cpp call CppFormat()
autocmd! BufWritePost *.h call CppFormat()
"format proto
function! ProtoFormat()
let file_path = expand('%:p')
execute "silent !protofmt -i " . file_path
execute ":e"
execute ":se filetype=proto"
endfunction
autocmd! BufWritePost *.proto call ProtoFormat()
"format go
function! GoFormat()
let file_path = expand('%:p')
execute "silent !gofmt -w " . file_path
execute ":e"
execute ":se filetype=go"
endfunction
autocmd! BufWritePost *.go call GoFormat()
"format BUILD
function! BuildFormat()
let file_path = expand('%:p')
execute "silent !buildifier -mode=fix " . file_path
execute ":e"
execute ":se filetype=go"
endfunction
autocmd! BufWritePost BUILD call BuildFormat()
autocmd! BufWritePost WORKSPACE call BuildFormat()
"configure bazel env
set path+=$HOME/workspace
set makeprg=$HOME/.run_bazel.sh
inoremap jk <esc>
au BufRead,BufNewFile BUILD set filetype=python
" vim-plug
" see more: https://github.com/junegunn/vim-plug
call plug#begin()
" for bazel
Plug 'google/vim-maktaba'
Plug 'bazelbuild/vim-bazel'
call plug#end()
function! Make()
execute ":Bazel build :all"
endfunction
command! Ma call Make()
nnoremap ma :Bazel build :all<cr>