-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path.vimrc
392 lines (316 loc) · 8.88 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
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
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
" ------------------------------------------------------------
" Setup
" ------------------------------------------------------------
set nocompatible
filetype off
set rtp+=~/.vim/bundle/Vundle.vim
set rtp+=/usr/local/opt/fzf
call vundle#begin()
Plugin 'VundleVim/Vundle.vim'
Plugin 'Townk/vim-autoclose'
Plugin 'austintaylor/vim-commaobject'
Plugin 'austintaylor/vim-indentobject'
Plugin 'austintaylor/vim-objectcompletion'
Plugin 'austintaylor/vim-open'
Plugin 'kana/vim-fakeclip'
Plugin 'kien/ctrlp.vim'
Plugin 'rking/ag.vim'
Plugin 'msanders/snipmate.vim'
Plugin 'scrooloose/syntastic'
Plugin 'tpope/vim-rhubarb'
Plugin 'tpope/vim-haystack'
Plugin 'tpope/vim-projectionist'
Plugin 'tpope/vim-vinegar'
Plugin 'tpope/vim-commentary'
Plugin 'tpope/vim-endwise'
Plugin 'tpope/vim-fugitive'
Plugin 'tpope/vim-rails'
Plugin 'tpope/vim-repeat'
Plugin 'tpope/vim-surround'
Plugin 'tpope/vim-unimpaired'
Plugin 'oscarh/vimerl'
Plugin 'rizzatti/funcoo.vim'
Plugin 'rizzatti/dash.vim'
Plugin 'leafgarland/typescript-vim'
Plugin 'Shougo/vimproc.vim'
Plugin 'Quramy/tsuquyomi'
Plugin 'fatih/vim-go'
Plugin 'jlanzarotta/bufexplorer'
Plugin 'chrisbra/csv.vim'
Plugin 'posva/vim-vue'
Plugin 'jremmen/vim-ripgrep'
call vundle#end()
let g:loaded_syntastic_plugin = 1
let g:tsuquyomi_disable_quickfix = 1
let g:project_dir = "~/dev"
let g:go_fmt_command = "goimports"
filetype plugin indent on
" ------------------------------------------------------------
" Settings
" ------------------------------------------------------------
let mapleader = ","
syntax on
if has("gui_running")
colorscheme jellybeans
hi markdownCode guifg=#a0a9bf
hi markdownCodeBlock guifg=#a0a9bf
else
colorscheme pyte
endif
set encoding=utf-8
set nowrap
" set cursorline
set nocursorline " this is too laggy in terminal mode
set wildmenu
set wildmode=list:longest
set number
set history=1000
set scrolloff=3
set ttyfast
set autoread
set ttimeout
set ttimeoutlen=100
set backspace=2
set laststatus=2 " always show a status line
" Disable hover tooltips
set noballooneval
let g:ruby_balloonexpr = 0
let g:netrw_nobeval = 1
" No bells
set visualbell t_vb=
" Indentation
set autoindent
set expandtab
set smarttab
set shiftwidth=2
set tabstop=2
set shiftround
" Split behavior
set splitbelow
set splitright
set sessionoptions=blank,curdir,folds,help,tabpages,winsize
" Search behavior
set ignorecase
set smartcase
set gdefault
set incsearch
set showmatch
set hlsearch
nnoremap / /\V
vnoremap / /\V
nnoremap <silent> <leader><space> :nohlsearch<cr>
" Persistent undo
if v:version >= 703
set undofile
set undodir=~/.vim/tmp
endif
" .vim-tmp
set backupdir=~/.vim/tmp
set directory=~/.vim/tmp
" matchparen is slow in the terminal
let loaded_matchparen = 1
" ------------------------------------------------------------
" Plugin options
" ------------------------------------------------------------
let g:ctrlp_cmd = 'CtrlPMRUFiles'
let g:ctrlp_mruf_relative=1
nnoremap <leader>f :FZF<CR>
let g:ctrlp_custom_ignore = {
\ 'dir': '\v(public|bower_components|node_modules|coverage|sso|tmp|\.git|\.vagrant|\.sass-cache)'
\ }
let g:syntastic_javascript_checkers = ['jshint']
let g:syntastic_enable_signs=1
let g:syntastic_mode_map = { 'mode': 'passive',
\ 'active_filetypes': [] }
let g:dash_map = {
\ 'ruby' : '_rails',
\ 'javascript' : '_js',
\ 'scss' : '_css',
\ 'eruby' : '_html' }
" ------------------------------------------------------------
" Autocmd
" ------------------------------------------------------------
augroup vimrc
autocmd!
au BufRead,BufNewFile Capfile set filetype=ruby
au BufRead,BufNewFile Gemfile set filetype=ruby
au BufRead,BufNewFile Guardfile set filetype=ruby
au BufRead,BufNewFile *.prawn set filetype=ruby
au BufRead,BufNewFile config.ru set filetype=ruby
au BufRead,BufNewFile *.handlebars set filetype=html
au BufRead,BufNewFile *.json set filetype=javascript
au BufRead,BufNewFile *.js.erb set filetype=javascript
au FileType vue syntax sync fromstart
" Auto-reload
au BufWritePost .vimrc source %
" Strip trailing whitespace
" (disabled because it was interfering with tab behavior)
"au BufWritePre * :%s/\s\+$//e
augroup END
" Reload things
set autoread updatetime=2000
augroup checktime
autocmd!
if !has("gui_running")
autocmd BufEnter * silent! checktime
autocmd CursorHold * silent! checktime
autocmd CursorHoldI * silent! checktime
endif
augroup END
" ------------------------------------------------------------
" Mappings
" ------------------------------------------------------------
" Fundamentals
nnoremap j gj
nnoremap k gk
nnoremap Y y$
nnoremap Q gqip
imap <C-D> <DEL>
imap <C-F> <RIGHT>
imap <C-B> <LEFT>
vnoremap p "0p
noremap H ^
noremap L g_
nnoremap \ ,
cnoremap <C-G> <C-C>
" Open my private todo file
nmap <leader>t :sp .todo<CR>
nmap <leader><leader>t :sp ~/Dropbox/todos/global.todo<CR>
" Scroll left/right
nmap <C-h> zH
nmap <C-l> zL
" Make C-w C-o (only window) reversible by opening a tab
nnoremap <C-W><C-O> :tabnew %<CR>
" Tree commands
map <leader>d :execute 'NERDTreeToggle ' . getcwd()<CR>
map <leader>R :NERDTreeFind<CR>
map <leader>e :e =system("pbpaste \| awk -F: '{print $1 \"\|\" $2}'")<CR><CR>
" Rg
nnoremap <leader>a :Rg<space>
vnoremap <leader>a "ry:Rg<space>"r"
" Reselect pasted text
nnoremap <leader>p `[v`]
" TM inspired keys
imap <C-L> <space>=><space>
" uppercase
imap <c-u> <esc>viwUgv<esc>a
" Symbols and strings
nmap <leader>: ds'ds"i:<Esc>e
nmap <leader>" ebhxcsw"
nmap <leader>' ebhxcsw'
" Extract local variable
nmap <leader>xl O. = "<ESC>
" Extract method (only works with character-wise selections, at the moment)
nmap <leader>xm ?def<CR>jvii<ESC>jo<CR>def .<CR>"<ESC>
" object && object.method
" Note: Cursor should be on the dot between object and method
map <leader>& mayB`ai<space>&&<space><esc>pl
" Add semicolon
nmap <leader>; ma:s/;\?$/;/\|let @/=''<CR>`a
nnoremap zp :put *<cr>`[v`]=
" I do this all the time.
command! Q :q
command! W :w
" command! X :x
inoremap <c-u> <esc>gUiwea
" Dash
nmap <silent> K <Plug>DashSearch
" relative open file
function! RelativeFile()
let file = expand('%')
if isdirectory(file)
let prefix = file . '/'
else
let prefix = expand('%:h') . '/'
endif
return prefix
endfunction
nnoremap <leader>e :e <c-r>=RelativeFile()<CR>
" Find & Replace
nnoremap <leader>r :%s//
vnoremap <leader>r "ry:%s/r/
vnoremap <leader>f "fy:/f
" Sections
nmap <leader>- o<esc>60i-<esc>\\\yyppkwC<space>
" Format XML
vmap <leader>x :!sed -e 's/ *//' \| xmllint --format -<CR>
" Open
nmap <leader>o "oyiW:!open o<cr><cr>
function! WordCount()
let s:old_status = v:statusmsg
let position = getpos(".")
exe ':silent normal g\'
let stat = v:statusmsg
let s:word_count = 0
if stat != '--No lines in buffer--'
let s:word_count = str2nr(split(v:statusmsg)[11])
let v:statusmsg = s:old_status
end
call setpos('.', position)
return s:word_count
endfunction
" ------------------------------------------------------------
" obj-c stuff
" ------------------------------------------------------------
" Upgrade a local var to a property
nmap <leader><leader>p vf*e"aymacf*self.:w,A/\@inter$%Oa;/\@prop}O@property (nonatomic, retain) a;h"byiw:w,Agg/\@syn}O@synthesize b;/super deallocOself.b = nil;:w`a
" Declare a method in the header
nmap <leader><leader>m 0vt{ge"ayma,A/prop}oa;:w,A`a
function! OpenLine()
let l:repo = substitute(system("cat .git/config | awk 'BEGIN { FS = /\s+/ }; /url =/ {print $3; exit}'"), '.git\n$', '', '')
let l:branch = substitute(system("git branch | awk '{print $2}'"), '\n$', '', '')
let l:file = expand('%')
let l:line = line('.')
let l:url = l:repo."/blob/".l:branch."/".l:file."#L".l:line
call system('open "'.l:url.'"')
endfunction
function! s:Creators(args)
redraw
echo "Searching..."
let g:creatorsformat="%f"
let g:creatorsprg="./find_creators.sh ".a:args
let grepprg_bak=&grepprg
let grepformat_bak=&grepformat
try
let &grepprg=g:creatorsprg
let &grepformat=g:creatorsformat
silent execute 'grep'
finally
let &grepprg=grepprg_bak
let &grepformat=grepformat_bak
endtry
botright copen
redraw!
endfunction
command! -nargs=1 Creators call s:Creators(<q-args>)
" ------------------------------------------------------------
" Snippet Support
" ------------------------------------------------------------
function! Camelize(name)
return substitute(a:name, '\v%(^(.)|_(.))', '\u\1\u\2', 'g')
endfunctio
function! ModelName()
return substitute(Filename('', 'model'), 's_controller', '', '')
endfunction
function! CamelModelName()
return Camelize(ModelName())
endfunction
" ------------------------------------------------------------
" Tab Label
" ------------------------------------------------------------
function! TabLabel()
if exists("t:directory")
return t:directory
else
return ""
endif
endfunction