forked from drewdeponte/dotvim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvimrc
422 lines (341 loc) · 13.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
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
" open to overrides from others
if filereadable(expand('~/.vimrc-ext'))
source ~/.vimrc-ext
endif
" enable pathogen to load all the vim bundles in ~/.vim/bundle/
call pathogen#infect()
" set the clipboard to unnamed so it uses the system clipboard
" set clipboard=unnamed
" Set the visual bell instead of audible
set vb
" Set the font when using MacVim.app, this is ignored for console vim as it
" simply uses the console font.
set gfn=Monaco:h15
" tell vim NOT to run in Vi compatible mode
set nocompatible
" show line numbers
set relativenumber
set number
set ruler
" set regexp engine to old one full featured one. Turns out that the newer NFA
" regexp engine does NOT play nice with Ruby lang syntax highlighting.
" Switching to the older non NFA regexp engine drastically increases
" performance.
if exists('+regexpengine')
set regexpengine=1
endif
" keep buffers opened in background until :q or :q!
set hidden
" Number of : command entries to keep track of as history
set history=10000
" Set the word wrap character limit, this will force word wrap past the
" specified column.
set textwidth=78
" Set the visual color column. This is usually used to indicate the text wrap
" boundaries.
" set colorcolumn=79
" Default to tab size of two spaces and enable auto indent
set expandtab
set tabstop=2
set shiftwidth=2
set softtabstop=2
set autoindent
" Show matching bracket when a bracket is inserted
set showmatch
" Show matching pattern as typing search pattern
set incsearch
" Highlight searches matching the search pattern
set hlsearch
" Make searches case-sensetive only if they include upper-case characters
set ignorecase smartcase
" Highlight the line the cursor is currently on for easy spotting
" set cursorline
" Highlight the column the cursor is currently on for easy spottintg
" (Note: This seems to make even small ruby files with syntax highlighting on
" super slow when using h,l to move the cursor left or right.)
" set cursorcolumn
" Make the command entry area consume two rows
set cmdheight=2
" Set preference for switching butters, :help switchbuf for details
set switchbuf=useopen
" Min number of characters to use for line number column
set numberwidth=5
" Show tab lines always
set showtabline=2
" Soft min width for the active window
set winwidth=15
" Soft min height for the active window
set winheight=5
" Min height for non active window
set winminheight=5
" The shell to use when using :!
set shell=zsh
" Prevent Vim from clobbering the scrollback buffer. See
" http://www.shallowsky.com/linux/noaltscreen.html
set t_ti= t_te=
" Minimum number of lines of context to keep around cursor
set scrolloff=3
" Settings for file swaps and backups
set backup
set backupdir=~/.vim-tmp,~/.tmp,~/tmp,/var/tmp,/tmp
set directory=~/.vim-tmp,~/.tmp,~/tmp,/var/tmp,/tmp
" allow backspacing over everything in insert mode
set backspace=indent,eol,start
" show incomplete command
set showcmd
" allow backspacing over everything in insert mode
set backspace=indent,eol,start
" enable syntax
syntax on
" enable automatic code folder on indent
set foldmethod=syntax
" do NOT fold by default
set nofoldenable
" number of levels to auto fold when open a file
set foldlevel=1
" Set my leader key to be a comma
let mapleader = ","
" Enable file type detection.
" " Use the default filetype settings, so that mail gets 'tw' set to 72,
" " 'cindent' is on in C files, etc.
" " Also load indent files, to automatically do language-dependent indenting.
filetype plugin indent on
" tab completion mode for files, etc.
set wildmode=list:longest,list:full
" scan current buffer, buffers of other windows, loaded buffers in buffer
" list, unloaded buffers, tags
set complete=.,w,b,u,t
" enable menu and extra info about completion
set completeopt=menu,preview
" make tab completion for files/buffers act like bash
set wildmenu
" set ack.vim to use ag instead of ack
let g:ackprg = 'ag --nogroup --nocolor --column'
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" CUSTOM AUTOCMDS
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
augroup vimrcEx
" Clear all autocmds in the group
autocmd!
autocmd FileType text setlocal textwidth=78
" Jump to last cursor position unless it's invalid or in an event handler
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal g`\"" |
\ endif
"for ruby, autoindent with two spaces, always expand tabs
autocmd FileType ruby,haml,eruby,yaml,html,javascript,sass,cucumber set ai sw=2 sts=2 et
autocmd FileType python set sw=4 sts=4 et
autocmd! BufRead,BufNewFile *.sass setfiletype sass
autocmd! BufRead,BufNewFile *.pp setfiletype ruby
autocmd! BufRead,BufNewFile *.god setfiletype ruby
autocmd BufRead *.mkd set ai formatoptions=tcroqn2 comments=n:>
autocmd BufRead *.markdown set ai formatoptions=tcroqn2 comments=n:>
" Before writing a file check if the path for it exists. If it doesn't then
" mkdir -p the path so that the file can be saved.
autocmd BufWritePre * if expand("<afile>")!~#'^\w\+:/' && !isdirectory(expand("%:h")) | execute "silent! !mkdir -p ".shellescape(expand('%:h'), 1) | redraw! | endif
" Indent p tags, I commented the below out because I don't have the
" dependencies necessary to get it to work and I am not sure if I
" actually want it. I took it from the DestoryAllSoftware vimrc screencast.
" autocmd FileType html,eruby if g:html_indent_tags !~ '\\|p\>' | let g:html_indent_tags .= '\|p\|li\|dt\|dd' | endif
" Don't syntax highlight markdown because it's often wrong
" autocmd! FileType mkd setlocal syn=off
autocmd! FileType mkd setlocal spell
autocmd! FileType gitcommit setlocal spell
" Don't screw up folds when inserting text that might affect them, until
" " leaving insert mode. Foldmethod is local to the window. Protect against
" " screwing up folding when switching between windows.
"
" Note: I added the following because I was seeing very bad performance when
" using Ctrl+n or Ctrl+p or Ctrl+x Ctrl+o to do wordcompletion. I did
" googling and found out it was due to the foldmethod=syntax and that there
" is a work around to set foldmethod=manual while in insert mode and then
" back to the configured value when exiting insert mode. This resolves the
" performance issues I was having and code folding still works properly,
" WIN!
" http://vim.wikia.com/wiki/Keep_folds_closed_while_inserting_text
autocmd InsertEnter * if !exists('w:last_fdm') | let w:last_fdm=&foldmethod | setlocal foldmethod=manual | endif
autocmd InsertLeave,WinLeave * if exists('w:last_fdm') | let &l:foldmethod=w:last_fdm | unlet w:last_fdm | endif
augroup END
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" COLOR
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" set background=light
" colorscheme scott
" Tell it to use the solarized color scheme
" http://ethanschoonover.com/solarized
" In order to have this work properly in iTerm2 you also need to setup the
" iTerm2 solarized color scheme.
set background=dark
colorscheme solarized
" Tell it to use the ir_black color scheme
" http://blog.toddwerth.com/entries/8
" set background=dark
" colorscheme ir_black
" set background=dark
" colorscheme drew_jellybeans
" colorscheme xoria256
" set background=dark
" colorscheme herald
" set background=dark
" colorscheme grb256
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" STATUS LINE
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
:set statusline=%<%f\ (%{&ft})\ %-4(%m%)%=%-19(%3l,%02c%03V%)
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" MISC KEY MAPS
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
map <leader>y "*y
" Move around splits with <c-hjkl>
nnoremap <c-j> <c-w>j
nnoremap <c-k> <c-w>k
nnoremap <c-h> <c-w>h
nnoremap <c-l> <c-w>l
" Insert a hash rocket with <c-l>
imap <c-l> <space>=><space>
" Erb statement generators
nmap <leader>- i<%<space><space>-%><esc>bhi
nmap <leader>= i<%=<space><space>%><esc>bhi
imap <leader>- <%<space><space>-%><esc>bhi
imap <leader>= <%=<space><space>%><esc>bhi
"imap <c-n> <%<space><space>%><esc>bhi
"imap <c-r> <%=<space><space>%><esc>bhi
" Can't be bothered to understand ESC vs <c-c> in insert mode
imap <c-c> <esc>
" Clear the search buffer when hitting return
:nnoremap <CR> :nohlsearch<cr>
nnoremap <leader><leader> <c-^>
" make pasting correctly from system clip board easier.
map <leader>p :set paste<CR>^"+p:set nopaste<CR>
map <leader>P :set paste<CR>^"+P:set nopaste<CR>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" MAPS TO JUMP TO SPECIFIC TARGETS AND FILES
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
function! SelectaCommand(choice_command, selecta_args, vim_command)
try
silent let selection = system(a:choice_command . " | ~/.vim/bin/selecta " . a:selecta_args)
catch /Vim:Interrupt/
" Swallow the ^C so that the redraw below happens; otherwise there will be
" leftovers from selecta on the screen
redraw!
return
endtry
redraw!
exec a:vim_command . " " . selection
endfunction
" Find all tags in the tags database, then open the tag that the user selects
command! SelectaTag :call SelectaCommand("awk '{print $1}' tags | sort -u | grep -v '^!'", "", ":tag")
fu! GetBuffers()
let ids = filter(range(1, bufnr('$')), 'empty(getbufvar(v:val, "&bt"))'
\ .' && getbufvar(v:val, "&bl")')
let bufs = [[], []]
for id in ids
let bname = bufname(id)
let ebname = bname == ''
let fname = fnamemodify(ebname ? '['.id.'*No Name]' : bname, ':.')
if bname != expand('%')
cal add(bufs[ebname], fname)
endif
endfo
retu join(bufs[0] + bufs[1], "\n")
endf
map <leader>gr :topleft :split config/routes.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>
map <leader>gg :topleft 100 :split Gemfile<cr>
map <leader>b :CtrlPBuffer<cr>
map <leader>gv :CtrlP app/views<cr>
" map <leader>gc :call SelectaCommand("find app/controllers -type f", "", ":e")<cr>
map <leader>gm :CtrlP app/models<cr>
map <leader>gh :CtrlP app/helpers<cr>
map <leader>gl :CtrlP lib<cr>
" map <leader>gp :call SelectaCommand("find public -type f", "", ":e")<cr>
" map <leader>gs :call SelectaCommand("find app/assets/stylesheets -type f", "", ":e")<cr>
map <leader>gf :CtrlP features<cr>
" fuzzy-match files except for stuff in tmp/*, log/*, tags
map <leader>f :CtrlP<cr>
map <leader>gt :SelectaTag<cr>
" jump to buffer if already open, even if in another tab
let g:ctrlp_switch_buffer = 2
" set the local working directory to the nearest .git/ .hg/ .svn/ .bzr/
let g:ctrlp_working_path_mode = 2
" enable cross-session caching by not deleting cache files on exit
let g:ctrlp_clear_cache_on_exit = 0
" set the best match to be the top
let g:ctrlp_match_window_reversed = 0
" set max height of match window
let g:ctrlp_max_height = 20
" tell ctrlp to ignore some files
let g:ctrlp_custom_ignore = 'tags$\|\.DS_Store$\|\.git$\|_site$'
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" GIT SHORTCUTS
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
map <leader>gs :Gstatus<cr>
map <leader>gc :Gcommit<cr>
map <leader>gp :!git push<cr>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" ARROW KEYS ARE UNACCEPTABLE
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
map <Left> :echo "no!"<cr>
map <Right> :echo "no!"<cr>
map <Up> :echo "no!"<cr>
map <Down> :echo "no!"<cr>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" MULTIPURPOSE TAB KEY
" Indent if we're at the beginning of a line. Else, do completion.
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 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>
" inoremap <s-tab> <c-n>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" OPEN FILES IN DIRECTORY OF CURRENT FILE
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
cnoremap %% <C-R>=expand('%:h').'/'<cr>
map <leader>e :edit %%
map <leader>v :view %%
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" RENAME CURRENT FILE
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
function! RenameFile()
let old_name = expand('%')
let new_name = input('New file name: ', expand('%'), 'file')
if new_name != '' && new_name != old_name
exec ':saveas ' . new_name
exec ':silent !rm ' . old_name
redraw!
endif
endfunction
map <leader>n :call RenameFile()<cr>
" Alternate between test files and paired code files
nnoremap <leader>. :OpenAlternate<cr>
" Map all the run test calls provided by vim-test-recall
map <leader>t :call RunAllTestsInCurrentTestFile()<cr>
map <leader>T :call RunNearestTest()<cr>
map <leader>a :call RunAllRSpecTests()<cr>
map <leader>c :call RunAllCucumberFeatures()<cr>
map <leader>w :call RunWipCucumberFeatures()<cr>
" Ping the cursor like an old radar to find it fast
nnoremap <leader>C :PingCursor<cr>