-
Notifications
You must be signed in to change notification settings - Fork 0
/
vimrc
378 lines (309 loc) · 11.6 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
""
"" Thanks:
"" Gary Bernhardt <destroyallsoftware.com>
"" Drew Neil <vimcasts.org>
"" Tim Pope <tbaggery.com>
"" Janus <github.com/carlhuda/janus>
"" Mislav Marohnić <[email protected]>
set nocompatible
set encoding=utf-8
filetype off
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" let Vundle manage Vundle
" required!
Plugin 'gmarik/vundle'
Plugin 'altercation/vim-colors-solarized'
Plugin 'tpope/vim-surround'
Plugin 'tpope/vim-repeat'
Plugin 'tpope/vim-rails'
Plugin 'tpope/vim-bundler'
Plugin 'tpope/vim-markdown'
Plugin 'tpope/vim-fugitive'
Plugin 'tpope/vim-endwise'
Plugin 'tpope/vim-commentary'
Plugin 'tpope/vim-eunuch'
Plugin 'tpope/vim-unimpaired'
Plugin 'tpope/vim-rvm'
Plugin 'tpope/vim-dispatch'
Plugin 'tpope/vim-abolish'
Plugin 'godlygeek/tabular'
Plugin 'vim-ruby/vim-ruby'
Plugin 'pangloss/vim-javascript'
Plugin 'chriseppstein/vim-haml'
Plugin 'kchmck/vim-coffee-script'
Plugin 'kien/ctrlp.vim'
Plugin 'rking/ag.vim'
Plugin 'mattn/webapi-vim'
Plugin 'mattn/gist-vim'
Plugin 'skalnik/vim-vroom'
Plugin 'Gundo'
Plugin 'kurkale6ka/vim-swap'
Plugin 't9md/vim-ruby-xmpfilter'
Plugin 'UltiSnips'
Plugin 'jgdavey/vim-blockle'
Plugin 'Townk/vim-autoclose'
Plugin 'kana/vim-textobj-user'
Plugin 'nelstrom/vim-textobj-rubyblock'
Plugin 'ervandew/supertab'
Plugin 'briancollins/vim-jst'
Plugin 'rizzatti/funcoo.vim'
Plugin 'rizzatti/dash.vim'
Plugin 'myusuf3/numbers.vim'
Plugin 'bling/vim-airline'
call vundle#end() " required
filetype plugin indent on "required
runtime macros/matchit.vim
syntax enable
set number " I like me some line numbers
" Use numbers plugin for switching between relative and absolute numbers
" if numbers show up where they shouldn't add them to this exclude list
" let g:numbers_exclude = ['unite', 'tagbar', 'startify', 'gundo', 'vimshell', 'w3m']$
set ruler " show the cursor position all the time
set cursorline " highlight the line of the cursor
set showcmd " show partial commands below the status line
set shell=bash " avoids munging PATH under zsh
let g:is_bash=1 " default shell syntax
set history=10000 " never forget!
set scrolloff=3 " have some context around the current line always on screen
" Allow backgrounding buffers without writing them, and remember marks/undo
" for backgrounded buffers
set hidden
" Whitespace
set nowrap " don't wrap lines
set tabstop=2 " a tab is two spaces
set shiftwidth=2 " an autoindent (with <<) is two spaces
set expandtab " use spaces, not tabs
set list " Show invisible characters
set backspace=indent,eol,start " backspace through everything in insert mode
" List chars
set listchars="" " Reset the listchars
set listchars=tab:\ \ " a tab should display as " ", trailing whitespace as "."
set listchars+=trail:. " show trailing spaces as dots
set listchars+=extends:> " The character to show in the last column when wrap is
" off and the line continues beyond the right of the screen
set listchars+=precedes:< " The character to show in the first column when wrap is
" off and the line continues beyond the left of the screen
"" Searching
set hlsearch " highlight matches
set incsearch " incremental searching
set ignorecase " searches are case insensitive...
set smartcase " ... unless they contain at least one capital letter
" Diffs
set diffopt=filler,vertical " Prefer vertical splits by default
let mapleader=","
function! s:setupWrapping()
set wrap
set wrapmargin=2
set textwidth=80
endfunction
if has("autocmd")
" In Makefiles, use real tabs, not tabs expanded to spaces
au FileType make set noexpandtab
" Make sure all markdown files have the correct filetype set and setup wrapping
au BufRead,BufNewFile *.{md,markdown,mdown,mkd,mkdn,txt} setf markdown | call s:setupWrapping()
" Treat JSON files like JavaScript
au BufNewFile,BufRead *.json set ft=javascript
" make Python follow PEP8 ( http://www.python.org/dev/peps/pep-0008/ )
au FileType python set softtabstop=4 tabstop=4 shiftwidth=4 textwidth=79
" Remember last location in file, but not for commit messages.
" see :help last-position-jump
au BufReadPost * if &filetype !~ '^git\c' && line("'\"") > 0 && line("'\"") <= line("$")
\| exe "normal! g`\"" | endif
" mark Jekyll YAML frontmatter as comment
au BufNewFile,BufRead *.{md,markdown,html,xml} sy match Comment /\%^---\_.\{-}---$/
" Indent p tags
" au FileType html,eruby if g:html_indent_tags !~ '\\|p\>' | let g:html_indent_tags .= '\|p\|li\|dt\|dd' | endif
" Make sure haml files are set correctly
au BufRead,BufNewFile *.haml set ft=haml
endif
" don't use Ex mode, use Q for formatting
map Q gq
" toggling for numbers.vim
nnoremap <F3> :NumbersToggle<CR>
nnoremap <F4> :NumbersOnOff<CR>
" clear the search buffer when hitting return
:nnoremap <CR> :nohlsearch<cr>
" map write
map <leader>w :w<cr>
"Dash Settings
let g:dash_map = {
\ 'ruby': 'rails'
\ }
" shortcut for looking up words in Dash
nmap <silent> <leader>d <Plug>DashSearch
nmap <silent> <leader>dg <Plug>DashGlobalSearch
" paste lines from unnamed register and fix indentation
nmap <leader>p pV`]=
nmap <leader>P PV`]=
let g:ctrlp_map = '<leader>f'
let g:ctrlp_cmd = 'CtrlP'
let g:ctrlp_max_height = 5
let g:ctrlp_match_window_reversed = 0
let g:ctrlp_match_window_bottom = 1
let g:ctrlp_switch_buffer = 2
let g:ctrlp_working_path_mode = 2
let g:ctrlp_mruf_include = '\.py$\|\.rb$|\.coffee|\.haml'
let g:ctrlp_custom_ignore = '\.git$\|\.hg$\|\.svn$'
let g:ctrlp_follow_symlinks = 1
let g:ctrlp_extensions = ['tag', 'buffertag', 'quickfix', 'dir', 'rtscript']
let g:ctrlp_user_command = {
\ 'types': {
\ 1: ['.git/', 'cd %s && git ls-files'],
\ 2: ['.hg/', 'hg --cwd %s locate -I .'],
\ },
\ 'fallback': 'ag %s -l --nocolor -g ""'
\ }
map <leader>ft :CtrlPTag<cr>
map <leader>fb :CtrlPBuffer<cr>
" http://vimcasts.org/e/14
cnoremap %% <C-R>=expand('%:h').'/'<cr>
" ignore Rubinius, Sass cache files
set wildignore+=tmp/**,*.rbc,.rbx,*.scssc,*.sassc
set wildmenu
set wildmode=list:longest
" switch between alternate buffers
nnoremap <leader><leader> <c-^>
" find merge conflict markers
nmap <silent> <leader>cf <ESC>/\v^[<=>]{7}( .*\|$)<CR>
command! KillWhitespace :normal :%s/ *$//g<cr><c-o><cr>
" easier navigation between split windows
nnoremap <c-j> <c-w>j
nnoremap <c-k> <c-w>k
nnoremap <c-h> <c-w>h
nnoremap <c-l> <c-w>l
" Resize pane mappings.
nnoremap <Home> :vertical resize +5<cr>
nnoremap <End> :vertical resize -5<cr>
nnoremap <PageUp> :resize +5<cr>
nnoremap <PageDown> :resize -5<cr>
" disable cursor keys in normal mode
map <Left> :echo "no!"<cr>
map <Right> :echo "no!"<cr>
map <Up> :echo "no!"<cr>
map <Down> :echo "no!"<cr>
set backupdir=~/.vim/_backup " where to put backup files.
set directory=~/.vim/_temp " where to put swap files.
if has("statusline") && !&cp
set laststatus=2 " always show the status bar
endif
let g:airline_powerline_fonts = 1
let g:AutoClosePairs = {'(': ')', '{': '}', '[': ']', '"': '"', "'": "'", '#{': '}', '|':'|' }
let g:AutoCloseProtectedRegions = ["Character"]
nmap <silent> <leader>s :set spell!<CR>
set spelllang=en_gb
" vimcasts.org/e/26 && unimpaired plugin
" Bubble single lines
nmap <C-Up> [e
nmap <C-Down> ]e
" Bubble multiple lines
vmap <C-Up> [egv
vmap <C-Down> ]egv
" vim-swap customisations
let g:swap_custom_ops = ['=>']
vmap <Leader>xx <plug>SwapSwapPivotOperands
nnoremap <F5> :GundoToggle<CR>
" Tabular plugin
if exists('g:tabular_loaded')
AddTabularPattern! symbols / :/l0
AddTabularPattern! hash /^[^>]*\zs=>/
AddTabularPattern! chunks / \S\+/l0
AddTabularPattern! assignment / = /l0
AddTabularPattern! comma /^[^,]*,/l1
AddTabularPattern! colon /:\zs /l0
AddTabularPattern! options_hashes /:\w\+ =>/
endif
if has("mac")
let g:gist_clip_command = 'pbcopy'
elseif has("unix")
let g:gist_clip_command = 'xclip -selection clipboard'
endif
" Gist settings
let g:gist_detect_filetype = 1
let g:gist_open_browser_after_post = 1
let g:gist_post_private = 1
let g:gist_show_privates = 1
" Insert a hash rocket with <c-l>
imap <c-l> <space>=><space>
" Rails stuff
map <leader>gg :topleft 100 :split Gemfile<cr>
map <leader>gr :topleft :split config/routes.rb<cr>
map <leader>ga :topleft :split app/models/ability.rb<cr>
function! ShowRoutes()
" Requires 'scratch' plugin
:topleft 100 :split __Routes__
" Make sure Vim doesn't write __Routes__ as a file
:set buftype=nofile
" Delete everything
:normal 1GdG
" Put routes output in buffer
:0r! rake -s routes
" Size window to number of lines (1 plus rake output length)
:exec ":normal " . line("$") . "_ "
" Move cursor to bottom
:normal 1GG
" Delete empty trailing line
:normal dd
endfunction
map <leader>gR :call ShowRoutes()<cr>
" Check ruby syntax
map <leader>cr :! ruby -c %<CR>
command! -nargs=0 -bar Qargs execute 'args ' . QuickfixFilenames()
function! QuickfixFilenames()
" Building a hash ensures we get each buffer only once
let buffer_numbers = {}
for quickfix_item in getqflist()
let buffer_numbers[quickfix_item['bufnr']] = bufname(quickfix_item['bufnr'])
endfor
return join(values(buffer_numbers))
endfunction
" =============== xmpfilter ========================
" Ensure rcodetools gem is installed
" Ensure that seeing_is_believing gem is installed
let g:xmpfilter_cmd = "seeing_is_believing"
autocmd FileType ruby nmap <buffer> <leader>mr <Plug>(seeing_is_believing-mark)
autocmd FileType ruby xmap <buffer> <leader>mr <Plug>(seeing_is_believing-mark)
autocmd FileType ruby imap <buffer> <leader>mr <Plug>(seeing_is_believing-mark)
autocmd FileType ruby nmap <buffer> <leader>rc <Plug>(seeing_is_believing-clean)
autocmd FileType ruby xmap <buffer> <leader>rc <Plug>(seeing_is_believing-clean)
autocmd FileType ruby imap <buffer> <leader>rc <Plug>(seeing_is_believing-clean)
" xmpfilter compatible
autocmd FileType ruby nmap <buffer> <leader>rr <Plug>(seeing_is_believing-run_-x)
autocmd FileType ruby xmap <buffer> <leader>rr <Plug>(seeing_is_believing-run_-x)
autocmd FileType ruby imap <buffer> <leader>rr <Plug>(seeing_is_believing-run_-x)
" auto insert mark at appropriate spot.
autocmd FileType ruby nmap <buffer> <leader>ra <Plug>(seeing_is_believing-run)
autocmd FileType ruby xmap <buffer> <leader>ra <Plug>(seeing_is_believing-run)
autocmd FileType ruby imap <buffer> <leader>ra <Plug>(seeing_is_believing-run)
" edit this file
map <silent> <leader>ev :e $MYVIMRC<cr>
" find all TODO comments and put in quickfix window
noremap <leader>t :noautocmd vimgrep /TODO/gj **/*.rb **/*.haml **/*.coffee **/*.js **/*.erb<CR>:cw<CR>
" turn off using bundle exec in vroom since it mucks up the color codes even
" with colors turned off
let g:vroom_use_bundle_exec = 0
function! PromoteToLet()
:normal! dd
:normal! P
:.s/\(\w\+\) = \(.*\)$/let(:\1) { \2 }/
:normal ==
endfunction
:command! PromoteToLet :call PromoteToLet()
:map <leader>l :PromoteToLet<cr>
:map <leader>ct :Dispatch! ctags -R --languages=ruby --exclude=.git --exclude=log --extra=+f<cr>
" Cleaning up crufty html using pandoc
" From http://vimcasts.org/episodes/using-external-filter-commands-to-reformat-html/
function! FormatprgLocal(filter)
if !empty(v:char)
return 1
else
let l:command = v:lnum.','.(v:lnum+v:count-1).'!'.a:filter
echo l:command
execute l:command
endif
endfunction
if has("autocmd")
let pandoc_pipeline = "pandoc --from=html --to=markdown"
let pandoc_pipeline .= " | pandoc --from=markdown --to=html"
autocmd FileType html setlocal formatexpr=FormatprgLocal(pandoc_pipeline)
endif