-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.myvimrc
353 lines (295 loc) · 11.5 KB
/
.myvimrc
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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
filetype off
call pathogen#runtime_append_all_bundles()
filetype plugin indent on
set nocompatible
set modelines=0
set expandtab
syntax on
set t_Co=256
if &diff
set wrap
colors mayansmoke
let g:Tb_MoreThanOne=100
else
colorscheme summerfruit256
set colorcolumn=81
end
" config vim-airline
set laststatus=2
let g:airline_theme='light'
set textwidth=80
set formatoptions=qrn1
set smartindent autoindent
set hlsearch ruler incsearch showmatch
set isfname-==
" backspace move across line
set backspace=indent,eol,start
set vb t_vb=
set ignorecase smartcase
set mouse=a
set incsearch
" <F1> to toggle paste mode
set pastetoggle=<F1>
nnoremap <Leader>FF :let @*=expand("%:p")<cr>:echo "Copied file path to clipboard"<cr>
nnoremap <Leader>F :let @*=expand("%:t")<cr>:echo "Copied file name to clipboard"<cr>
"nnoremap t :Unite file_rec/async<cr>
"let g:unite_source_file_rec_max_cache_files=100000
"call unite#custom#source('file_mru,file_rec,file_rec/async,grepocate',
" \ 'max_candidates', 0)
" yank to system clipboard
" For Linux, a hack, not sure why a single copy won't work...
"set clipboard=unnamedplus,autoselect
set clipboard=unnamed
" Or if it doesn't work, remap y
" :map y :w !/home/xianxu/.iterm2/it2copy<CR><CR>
" map y y:echom system('/home/xianxu/bin/it2copy', @0)<CR>
" map y y:call writefile([@0], '/tmp/vim_copy_paste')<CR>:!sed 's/[\d0]/\n/g' /tmp/vim_copy_paste > /tmp/vim_copy_paste1<CR><CR>:!/home/xianxu/.iterm2/it2copy < /tmp/vim_copy_paste1<CR><CR>
" vmap y y:call system('/home/xianxu/.iterm2/it2copy', @0)<CR>
" For Mac
" set clipboard+=autoselect
" setting spell
set spell spelllang=en_us
" turn spell off by default
set spell!
" toggle display of line number
nnoremap <leader>l :set number! number?<cr>
" toggle display of whitespaces (tabs etc.)
nnoremap <leader>w :set list!<cr>
" sort
vnoremap <leader>s :sort<cr>
" correct color for spell check.
hi SpellLocal ctermbg=lightcyan
" When editing a file, always jump to the last known cursor position.
" Don't do it when the position is invalid or when inside an event handler
" (happens when dropping a file on gvim).
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal! g`\"" |
\ endif
set wildignore+=*.pex,*.o,*.obj,.git,.svm,*.class,*.jar,lib_managed,src_managed,target,dist,
\*.ico,*.png,*.jpg,*.jpeg,novim*,*.bz2,*.gz,*.tar,*.zip,3rdparty,*.lock,*.pyc
" dealing with tabs
nnoremap <leader>] :tabn<CR>
nnoremap <leader>[ :tabp<CR>
" custom file type and syntax color
augroup filetypedetect
au BufNewFile,BufRead *.d set filetype=rust syntax=d
au BufNewFile,BufRead *.rs set filetype=rust syntax=rust
au BufNewFile,BufRead *.pig set filetype=pig syntax=pig
au BufNewFile,BufRead Capfile set filetype=ruby syntax=ruby
au BufNewFile,BufRead *.thrift set filetype=thrift syntax=thrift
au BufNewFile,BufRead TARGETS set filetype=python syntax=python
au BufNewFile,BufRead *.py set filetype=python syntax=python
au BufNewFile,BufRead *.mesos set filetype=python syntax=python
au BufNewFile,BufRead BUILD set filetype=python syntax=python
au BufNewFile,BufRead *.go set filetype=go syntax=go
au BufNewFile,BufRead *.sbt set filetype=scala syntax=scala
au BufNewFile,BufRead *.js set filetype=javascript syntax=javascript
au BufRead,BufNewFile README set filetype=mediawiki
au BufRead,BufNewFile *.ml set filetype=ocaml
au BufRead,BufNewFile *.proto set filetype=proto
augroup END
set shiftround "Round spaces to nearest shiftwidth multiple
set nojoinspaces "Don't convert spaces to tabs
autocmd FileType d setlocal tabstop=4 shiftwidth=4 softtabstop=4
autocmd FileType cpp setlocal tabstop=4 shiftwidth=4 softtabstop=4
autocmd FileType haskell setlocal tabstop=4 shiftwidth=4 softtabstop=4
autocmd FileType thrift setlocal tabstop=2 shiftwidth=2 softtabstop=2
autocmd FileType scala setlocal tabstop=2 shiftwidth=2 softtabstop=2
autocmd FileType java setlocal tabstop=2 shiftwidth=2 softtabstop=2
autocmd FileType ruby setlocal tabstop=2 shiftwidth=2 softtabstop=2
autocmd FileType php setlocal tabstop=2 shiftwidth=2 softtabstop=2
autocmd FileType js setlocal tabstop=2 shiftwidth=2 softtabstop=2
autocmd FileType go setlocal tabstop=4 shiftwidth=4 softtabstop=4
" Remove trailing whitespace from code files on save
function! StripTrailingWhitespace()
" store current cursor location
silent exe "normal ma<CR>"
" store the current search value
let saved_search = @/
" delete the whitespace (e means don't warn if pattern not found)
%s/\s\+$//e
%s/^\t/ /e
%s/^ \t/ /e
%s/^ \t/ /e
%s/^ \t/ /e
%s/^ \t/ /e
%s/^ \t/ /e
%s/^ \t/ /e
%s/^ \t/ /e
%s/^ \t/ /e
%s/^ \t/ /e
%s/^ \t/ /e
%s/^ \t/ /e
%s/^ \t/ /e
%s/^ \t/ /e
" restore old cursor location
silent exe "normal `a<CR>"
" restore the search value
let @/ = saved_search
endfunction
"*.scala,*.c,*.h,*.hpp,*.cc,*.cpp,*.py,*.sh,*.tex
"autocmd BufWritePre * call StripTrailingWhitespace()
" start neocomplete, this allows you to complete with tokens in this file.
let g:neocomplcache_enable_at_startup = 1
"inoremap <expr><CR> neocomplcache#smart_close_popup() . "\<CR>"
" <TAB>: completion.
inoremap <expr><TAB> pumvisible() ? "\<C-n>" : "\<TAB>"
" reload all buffers
noremap <leader><CR> :checktime<CR>
" deal with space
noremap <leader><SPACE> :call StripTrailingWhitespace()<CR>
" automatically save views
"au BufWinLeave *.* mkview
"au BufWinEnter *.* silent loadview
" create fold of matching bracket
noremap <leader>f v%zf
" toggle fold
noremap <leader>a za
" setting for mac vim
if has("gui_running")
set guioptions=-t " remove toolbox from window
set gfn=Inconsolata-dz:h15 " default font
set guioptions+=a " for macvim to copy on select
set guioptions+=r
" in gui mode, remap quit to buffer kills
cnoreabbrev wq w<bar>bd
cnoreabbrev q bd
"syntax off
endif
" last opened buffer, only works with one history, better than nothing
nnoremap <c-s-t> :b#<CR>
" quit TagmaBufMgr if it's the last
"let g:TagmaBufMgrLastLine = 1
"let g:TagmaBufMgrLastWindow = 1
" easier search of tags
set runtimepath^=~/.vim/bundle/ctrlp.vim
let g:ctrlp_cmd = 'CtrlPMRU'
let g:ctrlp_match_window = 'bottom,order:btt,min:1,max:20,results:100'
let g:ctrlp_max_files=100000
let g:ctrlp_working_path_mode = 'ra'
let g:ctrlp_root_markers = ['.cp']
let g:ctrlp_follow_symlinks = 1
let g:ctrlp_mruf_max = 2000
let g:ctrlp_mruf_exclude = '/tmp/.*\|/temp/.*'
" shortcuts to load .vimrc and source it
nnoremap <leader>ev :vsplit $MYVIMRC<cr>
nnoremap <leader>sv :source $MYVIMRC<cr>
" some ascii art stuff
vnoremap <leader>vd ma"aygvoOl:s/\%V.\%V/ /g<cr>:nohlsearch<cr>`a
vnoremap <leader>vc ma"aygvoOly<cr>:nohlsearch<cr>`a
vnoremap <leader>vb maoOl:s/\%V.\%V/\|/g<cr>:nohlsearch<cr>`a
vnoremap <leader>v<space> maoOl:s/\%V.\%V/\-/g<cr>:nohlsearch<cr>`a
noremap <leader>vp ma1vh"apgvly<esc>`a
" comment and copy
vnoremap <leader>C yPgv:call NERDComment(1, 'sexy')<cr>
function! RightAlignVisual() range
let [l, r] = [virtcol("'<"), virtcol("'>")]
let [l, r] = [min([l, r]), max([l, r])]
exe "'<,'>" 's/\%'.l.'v.*\%<'.(r+1).'v./\=StrPadLeft(submatch(0),r-l+1)'
endfunction
function! StrPadLeft(s, w)
let s = substitute(a:s, '^\s\+\|\s\+$', '', 'g')
return repeat(' ', a:w - strwidth(s)) . s
endfunction
vnoremap <leader>vr :call RightAlignVisual()<cr>
" xiki
"let $XIKI_DIR = '/usr/local/rvm/gems/ree-1.8.7-2011.03@twitter/gems/xiki-0.6.3/'
"source /usr/local/rvm/gems/ree-1.8.7-2011.03@twitter/gems/xiki-0.6.3/etc/vim/xiki.vim
" Tabularize
"let mapleader=','
"if exists(":Tabularize")
" nmap <Leader>a= :Tabularize /=<CR>
" vmap <Leader>a= :Tabularize /=<CR>
" nmap <Leader>a: :Tabularize /:\zs<CR>
" vmap <Leader>a: :Tabularize /:\zs<CR>
"endif
let g:syntastic_mode_map = { 'mode': 'passive',
\ 'active_filetypes': ['ruby', 'haskell'],
\ 'passive_filetypes': ['scala', 'java'] }
" Browse file in cgit (Cgit! for copy to clipboard)
function! s:Cgit(bang)
let repo = substitute(system('basename `git rev-parse --show-toplevel`'), '\n$', '', '')
let repo_root = substitute(system('git rev-parse --show-toplevel'), '\n$', '', '')
let abs_path = expand("%:p")
let rel_path = substitute(abs_path, '^'.repo_root.'/', '', '')
let url = 'https://cgit.twitter.biz/'.repo.'/tree/'.rel_path.'#n'.line(".")
if a:bang
let @* = url
echom url
else
call system('git web--browse '.'"'.url.'"')
endif
endfunction
command! -bang Cgit call <SID>Cgit(<bang>0)
"let g:Tb_VSplit=28
"let Tb_MaxSize=0
hi VertSplit guifg=bg guibg=#cccccc ctermfg=bg ctermbg=grey
hi ColorColumn guibg=#f6f6f6 ctermbg=lightgrey
" auto complete with :e command
set wildmenu
set wildmode=list:longest
" buffer saving
set autowrite
set hidden
set sessionoptions=buffers
nnoremap <C-Up> :bprevious<cr>
nnoremap <C-Down> :bnext<cr>
inoremap <C-Up> <esc>:bprevious<cr>
inoremap <C-Down> <esc>:bnext<cr>
vnoremap <C-Up> <esc>:bprevious<cr>
vnoremap <C-Down> <esc>:bnext<cr>
hi Tb_VisibleNormal guifg=#006600 guibg=#bbeebb ctermbg=green ctermbg=lightgreen
" for the following to work on macvim, I seems need to do:
" :e $VIMRUNTIME/menu.vim
" search d-w and comment out that line
if has('gui_macvim')
map <D-w> :bd<cr>
endif
nnoremap <LEADER>c viwy
autocmd FileType cpp setlocal tabstop=2 shiftwidth=2 softtabstop=2
autocmd FileType go setlocal tabstop=4 shiftwidth=4 softtabstop=4
autocmd FileType haskell setlocal tabstop=4 shiftwidth=4 softtabstop=4
autocmd FileType java setlocal tabstop=2 shiftwidth=2 softtabstop=2
autocmd FileType js setlocal tabstop=2 shiftwidth=2 softtabstop=2
autocmd FileType python setlocal tabstop=4 shiftwidth=4 softtabstop=4
autocmd FileType php setlocal tabstop=2 shiftwidth=2 softtabstop=2
autocmd FileType ruby setlocal tabstop=2 shiftwidth=2 softtabstop=2
autocmd FileType scala setlocal tabstop=2 shiftwidth=2 softtabstop=2
nnoremap <Leader>a :A<cr>
nnoremap <Leader>A <c-w><c-w>:bd<cr>:vsp<cr>:A<cr>
nnoremap <Leader>s <c-w>r
nnoremap <Leader>j :%!python -m json.tool<cr>
" incsearch
" map / <Plug>(incsearch-forward)
" map ? <Plug>(incsearch-backward)
" map g/ <Plug>(incsearch-stay)
" Taglist-related
set tags=tags;/
nnoremap <c-]> g<c-]>
vnoremap <c-]> g<c-]>
nnoremap <c-u> :TlistToggle<cr>
" let Tlist_Auto_Open = 1
let Tlist_Exit_OnlyWindow = 1 "if taglist window is the only window left, exit vim
let Tlist_Show_Menu = 1 "show Tags menu in gvim
let Tlist_Show_One_File = 1 "show tags of only one file
let Tlist_Sort_Type = "name"
let Tlist_WinWidth = 50
"let tlist_php_settings = 'php;c:class;f:function'
let Tlist_Use_Right_Window = 1
"let tlist_cpp_settings = 'c++;n:namespace;;d:macro;t:typedef;c:class;g:enum;s:struct;u:union;f:function;m:member;p:prototype'
" fb specific stuff
map <C-K> :pyf /mnt/vol/engshare/admin/scripts/vim/clang-format.py<CR>
" Save and restore sessions
nnoremap <Leader>q :mksession! ~/vim_session<bar>xa!<CR>
nnoremap <Leader>L :source ~/vim_session<CR>
let g:session_autoload = 'no'
map <C-K> :pyf /mnt/vol/engshare/admin/scripts/vim/clang-format.py<CR>
set noswapfile
map z bvey
nmap <silent> ˚ :wincmd l<CR>
nmap <silent> ∆ :wincmd h<CR>
let g:solarized_diffmode="high"
highlight CursorLine ctermbg=153
highlight CursorColumn ctermbg=153
nnoremap <leader>h :set cursorcolumn!<cr>:set cursorline!<cr>