-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.vimrc
276 lines (222 loc) · 6.47 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
"===================
" General behaviour
"===================
set nocompatible
set encoding=utf-8
set autoread
set modelines=0
set wildignore+=*.jpg,*.bmp,*.gif,*.png,*.jpeg
set wildignore+=*.o,*.obj,*.exe,*.dll,*.so
set wildignore+=*.sw?
set wildignore+=*.DS_Store
set wildignore+=*.pyc
set wildignore+=*.apk,*.class,*.jar,*.zip,*.tar,*.gz
set wildmenu
" Disable useless manual lookup
nnoremap K <nop>
" Navigate by visual line (is there a proper way to do this?)
noremap j gj
noremap k gk
" put backup files in ~/.vim/baks
"set backup
"set backupdir=~/.vim/baks
let mapleader = ","
let maplocalleader = "\\"
nnoremap ; :
" Lexical autocomplete tabwrapper
function InsertTabWrapper()
let col = col('.') - 1
if !col || getline('.')[col - 1] !~ '\k'
return "\<tab>"
else
return "\<c-p>"
endif
endfunction
inoremap <tab> <c-r>=InsertTabWrapper()<cr>
" Map key to toggle option
function MapToggle(key, opt)
let cmd = ':set '.a:opt.'! \| set '.a:opt."?\<CR>"
exec 'nnoremap '.a:key.' '.cmd
exec 'inoremap '.a:key." \<C-O>".cmd
endfunction
command -nargs=+ MapToggle call MapToggle(<f-args>)
" Install plugins!
call pathogen#infect()
"===================
" Visuals
"===================
syntax enable
if !has('gui_running')
let g:solarized_termcolors=256
endif
set background=dark
colorscheme solarized
set nu
set visualbell
set showcmd
set showmode
set ruler
let g:syntastic_javascript_checkers=['eslint']
let g:syntastic_python_checkers=['pyflakes', 'pycodestyle']
" show trailing spaces in yellow.
set list
set listchars=tab:\ \ ,trail:\ ,extends:»,precedes:«
hi ExtraWhitespace ctermbg=yellow guibg=yellow
match ExtraWhitespace /\s\+$/
autocmd BufWinEnter * match ExtraWhitespace /\s\+$/
autocmd InsertEnter * match ExtraWhitespace /\s\+\%#\@<!$/
autocmd InsertLeave * match ExtraWhitespace /\s\+$/
autocmd BufWinLeave * call clearmatches()
if has("gui")
set cursorline
hi CursorLine ctermbg=DarkBlue ctermfg=NONE cterm=NONE guibg=DarkBlue guifg=NONE gui=none
autocmd WinEnter * setlocal cursorline
autocmd WinLeave * setlocal nocursorline
endif
" Matching characters (conditionally set angle brackets only in certain types)
set showmatch
set matchtime=1
au BufNewFile,BufRead *.html,*.xml set mps+=<:>
"===================
" Search
"===================
set smartcase incsearch ignorecase hlsearch
set incsearch
" Display-altering option toggles
MapToggle <C-n> hlsearch
MapToggle <C-p> ignorecase
" Clean whitespace
map <leader>w :s/\s\+$//<cr>:let @/=''<CR>
" file regex search
map <leader>s :%s/
" Easier bracket match
nnoremap <tab> %
vnoremap <tab> %
"===================
" Window management
"===================
map <C-J> <C-W>j<C-W>_<C-W>k4<C-W>+<C-W>j
map <C-K> <C-W>k<C-W>_<C-W>j4<C-W>+<C-W>k
map <C-h> <C-W>h<C-W>\|<C-W>l<C-W>h
map <C-l> <C-W>l<C-W>\|<C-W>h<C-W>l
let NERDTreeIgnore = ['\.pyc$']
nnoremap <leader>t :NERDTreeToggle<CR>
" Requires `brew install ctags-exuberant`
let g:tagbar_ctags_bin="/usr/local/Cellar/ctags/5.8/bin/ctags"
" Requires https://github.com/mozilla/doctorjs (make install)
"let g:tagbar_type_javascript = {'ctagsbin' : '/usr/local/bin/jsctags'}
nnoremap <leader>g :TagbarToggle<CR>
"===================
" Coding style
"===================
set shiftwidth=4 tabstop=4 softtabstop=4
let g:indent = '4'
function ToggleTab()
if g:indent == '4'
set shiftwidth=2 tabstop=2 softtabstop=2
echo "Using 2 space indent"
let g:indent = '2'
else
set shiftwidth=4 tabstop=4 softtabstop=4
echo "Using 4 space indent"
let g:indent = '4'
endif
endfunction
map <leader>e :exec ToggleTab()<cr><cr>
set expandtab
set cindent
" Prevent object literals in JS from being on column 0
" http://stackoverflow.com/questions/4321372/how-to-stop-vim-moving-javascript-object-keys-to-column-0
set cinkeys-=:
filetype plugin on
" Hive pseudo-support
au BufRead,BufNewFile *.q set filetype=sql
" 80 col limit
au BufNewFile,BufRead *.vimrc,*.c,*.cc,*.h,*.java,*.js,*.py,*.q match TooLong /\%>80v.\+/
hi link TooLong Warning
set colorcolumn=80
if has("gui")
hi Warning guifg=#ffffff guibg=#6e2e2e
else
hi Warning ctermbg=DarkRed ctermfg=Grey
endif
"===================
" Perforce
"===================
command! -nargs=* -complete=file PEdit :!p4 edit %
command! -nargs=* -complete=file PRevert :!p4 revert %
command! -nargs=* -complete=file PDiff :!p4 diff %
" Fuzzy matcher
"let g:fuf_file_exclude = '\v\~$|\.(o|exe|dll|bak|orig|rej|handlebars\.js|sw[po])$|(^|[/\\])\.(hg|git|bzr)($|[/\\])'
"map <leader>r :FufFile<cr>
"map <leader>f :FufRenewCache<cr>
" From Steve Losh (https://bitbucket.org/sjl/dotfiles/src/tip/vim/.vimrc):
" Split/Join {{{
"
" Basically this splits the current line into two new ones at the cursor position,
" then joins the second one with whatever comes next.
"
" Example: Cursor Here
" |
" V
" foo = ('hello', 'world', 'a', 'b', 'c',
" 'd', 'e')
"
" becomes
"
" foo = ('hello', 'world', 'a', 'b',
" 'c', 'd', 'e')
"
" Especially useful for adding items in the middle of long lists/tuples in Python
" while maintaining a sane text width.
nnoremap K h/[^ ]<cr>"zd$jyyP^v$h"zpJk:s/\v +$//<cr>:noh<cr>j^
" }}}
function! s:HgBlame()
let fn = expand('%:p')
wincmd v
wincmd h
edit __hgblame__
vertical resize 28
setlocal scrollbind winfixwidth nolist nowrap nonumber buftype=nofile ft=none
normal ggdG
execute "silent r!hg blame -undq " . fn
normal ggdd
execute ':%s/\v:.*$//'
wincmd l
setlocal scrollbind
syncbind
endf
command! -nargs=0 HgBlame call s:HgBlame()
nnoremap <leader>hb :HgBlame<cr>
function! s:HgDiff()
diffthis
let fn = expand('%:p')
let ft = &ft
wincmd v
edit __hgdiff_orig__
setlocal buftype=nofile
normal ggdG
execute "silent r!hg cat --rev . " . fn
normal ggdd
execute "setlocal ft=" . ft
diffthis
diffupdate
endf
command! -nargs=0 HgDiff call s:HgDiff()
nnoremap <leader>hd :HgDiff<cr>
" Git grep using navigation with Ggr
command -nargs=+ Ggr execute 'silent Ggrep!' <q-args> | cw | redraw!
" ----------------------------------------------------------------------------
" fzf
" ----------------------------------------------------------------------------
set rtp+=~/.fzf
nnoremap <silent> <Leader>r :FZF -m<CR>
"function! BufList()
"redir => ls
"silent ls
"redir END
"return split(ls, '\n')
"endfunction
"function! BufOpen(e)
"execute 'buffer '. matchstr(a:e, '^[ 0-9]*')
"endfunction