-
Notifications
You must be signed in to change notification settings - Fork 0
/
_vimrc
282 lines (227 loc) · 7.77 KB
/
_vimrc
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
set nocompatible
source $VIMRUNTIME/vimrc_example.vim
source $VIMRUNTIME/mswin.vim
behave mswin
set diffexpr=MyDiff()
function MyDiff()
let opt = '-a --binary '
if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif
if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif
let arg1 = v:fname_in
if arg1 =~ ' ' | let arg1 = '"' . arg1 . '"' | endif
let arg2 = v:fname_new
if arg2 =~ ' ' | let arg2 = '"' . arg2 . '"' | endif
let arg3 = v:fname_out
if arg3 =~ ' ' | let arg3 = '"' . arg3 . '"' | endif
let eq = ''
if $VIMRUNTIME =~ ' '
if &sh =~ '\<cmd'
let cmd = '""' . $VIMRUNTIME . '\diff"'
let eq = '"'
else
let cmd = substitute($VIMRUNTIME, ' ', '" ', '') . '\diff"'
endif
else
let cmd = $VIMRUNTIME . '\diff'
endif
silent execute '!' . cmd . ' ' . opt . arg1 . ' ' . arg2 . ' > ' . arg3 . eq
endfunction
" Share the clipboard with windows
set clipboard=unnamed
" Plugin manager -- pathogen
call pathogen#infect()
" Open the explorer tree
nmap <Leader>n :NERDTreeToggle<CR>
" Ignore pyc files
let NERDTreeIgnore = ['\.pyc$\|\.meta$']
" Set background as back
colo ayumi
" colo bandit
" colo diablo3
" Set no back up swap file
set nobackup
" Set tab as 4 space
set tabstop=4
set shiftwidth=4
set expandtab
" No Auto change line in txt file
set wrap
set linebreak
set nolist " list disables linebreak
set formatoptions+=l
"autocmd Filetype cs setlocal ts=4 sw=4 sts=0 noexpandtab
" CtrlP settings
map <F3> :CtrlPMRUFiles<CR>
let g:ctrlp_cmd = 'CtrlP .'
let g:ctrlp_by_filename = 1
let g:ctrlp_match_window_bottom = 0
let g:ctrlp_match_window_reversed = 0
let g:ctrlp_custom_ignore = '\.git$\|\.hg$\|\.svn$\|\.obj$\|\.pyc$\|\.meta$'
let g:ctrlp_root_markers = ['.ycm_extra_conf.py']
let g:ctrlp_clear_cache_on_exit = 0
let g:ctrlp_prompt_mappings = { 'PrtSelectMove("j")': ['<c-n>', '<down>'], 'PrtSelectMove("k")': ['<c-p>', '<up>'], 'PrtHistory(-1)': ['<c-j>'], 'PrtHistory(1)': ['<c-k>'], 'PrtClearCache()': ['<F4>'], }
" Taglist
" Open tag list selector
"map <S-o> :TlistToggle<CR>
map <S-o> :TagbarToggle<CR>
let g:Tlist_Ctags_Cmd='ctags.exe'
"For mac
"let g:Tlist_Ctags_Cmd='/usr/local/bin/ctags'
" Just display the current buffer's functions
let Tlist_Show_One_File = 1
" Show tag list on the right side
let Tlist_Use_Right_Window = 1
" Remap scroll up and scroll down
noremap <C-j> <C-e>
noremap <C-k> <C-y>
" Grep for search under specific folder or files
let Grep_Path = 'D:\Program Files\grep-2.5.4-bin\bin\grep.exe'
let Fgrep_Path = 'D:\Program Files\grep-2.5.4-bin\bin\fgrep.exe'
let Egrep_Path = 'D:\Program Files\grep-2.5.4-bin\bin\efgrep.exe'
let Grep_Find_Path = 'D:\Program Files\findutils-4.2.20-2-bin\bin\find.exe'
let Grep_Xargs_Path = 'D:\Program Files\findutils-4.2.20-2-bin\bin\xargs.exe'
" Remap to toggle qfix
map <C-F8> :QFix<CR>
map <F8> :cn<CR>
map <S-F8> :cp<CR>
nmap <Tab> <C-W><C-W>
nmap <A-k> :wincmd k<CR>
nmap <A-j> :wincmd j<CR>
nmap <A-h> :wincmd h<CR>
nmap <A-l> :wincmd l<CR>
" set encoding=utf-8
" Display line number
set number
" Set font to couriernew
set guifont=Bitstream_Vera_Sans_Mono:h10:cANSI
"set guifont=Lucida_Console:h11
"set guifont=monofur:h12
"Toggle Menu and Toolbar
set guioptions-=m
set guioptions-=T
" Don't need to hit enter
set cmdheight=3 lines=43
map <silent> <F9> :if &guioptions =~# 'T' <Bar>
\set guioptions-=T <Bar>
\set guioptions-=m <bar>
\else <Bar>
\set guioptions+=T <Bar>
\set guioptions+=m <Bar>
\endif<CR>
" Find current buffer in the NERD_Tree
map <Leader>g :NERDTreeFind<CR>
" Switch between cpp and h files
map <A-o> :A<CR>
" let ctags_path+="C:\Python26\Lib\site-packages\django\tags"
set completeopt=longest,menu " Don't display the preview window
" YouCompleteMe
nmap <C-]> :YcmCompleter GoTo<CR>
let g:ycm_confirm_extra_conf = 0
" Easy motion short cut key
let g:EasyMotion_leader_key = ";"
" Set alternate search path
let g:alternateSearchPath = 'sfr:./'
" Auto save buff and keep the change history
set autowriteall
" Turn backup off, since most stuff is in SVN, git anyway...
set nobackup
set nowb
set noswapfile
"Persistent undo
set undofile " Save undo's after file closes
set undodir=$HOME/vim/undo " where to save undo histories, make sure it's existed, or else create it manually
set undolevels=1000 " How many undos
set undoreload=10000 " number of lines to save for undo
" Hightlight current line
autocmd BufEnter * setlocal cursorline
set list listchars=tab:>-,trail:.,precedes:<,extends:>
autocmd BufWinLeave * call clearmatches()
"au BufWinEnter * let w:m1=matchadd('Search', '\%<81v.\%>77v', -1)
"au BufWinEnter * let w:m2=matchadd('Underlined', '\%>78v.\+', -1)
autocmd BufWritePre *.{as,lua,cpp,h,c,py,js,etc} call StripTrailingWhite()
autocmd BufWritePre *.{as,lua,cpp,h,c,py,js,etc} call StripTabs()
function! StripTrailingWhite()
let l:winview = winsaveview()
silent! %s/\s\+$//
call winrestview(l:winview)
endfunction
function! StripTabs()
let l:winview = winsaveview()
silent! %s/\t/ /g
call winrestview(l:winview)
endfunction
function ExplorerCurrentBuffer()
exec ":silent !explorer /select, %:p"
endfunction
" Open the selected buffer in windows explorer
nmap <F10> :!start explorer /select, %:p<CR>
" For Mac
nmap <F10> :silent !open -R %:p<CR>
" Show dec or hex of current number-word under cursor
nnoremap gn :call DecAndHex(expand("<cWORD>"))<CR>
function! DecAndHex(number)
let ns = '[.,;:''"<>()^_lL]' " number separators
if a:number =~? '^' . ns. '*[-+]\?\d\+' . ns . '*$'
let dec = substitute(a:number, '[^0-9+-]*\([+-]\?\d\+\).*','\1','')
echo dec . printf(' -> 0x%X, -(0x%X)', dec, -dec)
elseif a:number =~? '^' . ns. '*\%\(h''\|0x\|#\)\?\(\x\+\)' . ns . '*$'
let hex = substitute(a:number, '.\{-}\%\(h''\|0x\|#\)\?\(\x\+\).*','\1','')
echon '0x' . hex . printf(' -> %d', eval('0x'.hex))
if strpart(hex, 0,1) =~? '[89a-f]' && strlen(hex) =~? '2\|4\|6'
" for 8/16/24 bits numbers print the equivalent negative number
echon ' ('. float2nr(eval('0x'. hex) - pow(2,4*strlen(hex))) . ')'
endif
echo
else
echo "NaN"
endif
endfunction
" Highlight c operator
autocmd! BufRead,BufNewFile,BufEnter *.{c,cpp,h,javascript} call CSyntaxAfter()
" Fold marker
set fdm=marker
" Surround selection with character
"vnoremap ( <ESC>`>i)<ESC>`<i(<ESC>
"vnoremap " <ESC>`>i"<ESC>`<i"<ESC>
"vnoremap ' <ESC>`>i'<ESC>`<i'<ESC>
"vnoremap { <ESC>`>i}<ESC>`<i{<ESC>
"vnoremap [ <ESC>`>i]<ESC>`<i[<ESC>
" au BufRead,BufNewFile *.jar,*.war,*.ear,*.sar,*.rar set filetype=zip
" Grep under windows
set grepprg=findstr\ /n\ /s
command -nargs=+ FullMatchSearch :call g:FullMatchSearch(<f-args>)
command -nargs=+ PartialMatchSearch :call g:PartialMatchSearch(<f-args>)
function! g:FullMatchSearch(pattern, searchDir)
exec "grep \"\\<" . a:pattern . "\\>\" " . a:searchDir
cw
endfunction
function! g:PartialMatchSearch(pattern, searchDir)
exec "grep \"" . a:pattern . "\" " . a:searchDir
cw
endfunction
nmap <leader>f :FullMatchSearch <c-r>=expand("<cword>")<cr>
nmap <leader>F :PartialMatchSearch <c-r>=expand("<cword>")<cr>
" Set tail height
let g:tail#Height = 30
" actionscript language
let tlist_actionscript_settings = 'actionscript;c:class;f:method;p:property;v:variable'
" Treat long line as break lines
map j gj
map k gk
" Make cmdline tab completion similar to bash
set wildmode=list:longest
" Auto complete for command in status bar
set wildmenu
set wildmode=longest:full,full
" For comment useless param
nmap mc i/*<Esc>wea*/<Esc>k
" Use pylint
set makeprg=pylint\ --reports=n\ --rcfile=pylint.conf\ --output-format=parseable\ %:p
set errorformat=%f:%l:\ %m
nmap <leader>m :make<cr>
" Format json
nmap <leader>j :%!python -m json.tool<cr>
" Open as maximum window
au GUIEnter * simalt ~x
" For Mac
" set lines=999 columns=999