forked from duff/dot_vim_directory
-
Notifications
You must be signed in to change notification settings - Fork 1
/
.vimrc
322 lines (261 loc) · 10.4 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
" ---------------------------------------------------------------------------
" General
" ---------------------------------------------------------------------------
call pathogen#runtime_append_all_bundles() " using pathogen for a bunch of plugins
set nocompatible
let mapleader = ","
set history=1000 " lots of command line history
filetype plugin indent on " load filetype plugin
set viminfo='10,\"100,:20,%,n~/.viminfo " remember certain things when we exit
set autoread " reload files changed outside of Vim
set autowrite " some commands should cause an automatic write
" ----------------------------------------------------------------------------
" UI
" ----------------------------------------------------------------------------
set ruler " show the cursor position all the time
set backspace=start,indent,eol " allow backspacing over anything in insert mode
set guioptions=eg " disable scrollbars, etc
set wm=2 " wrap margin on the right
let NERDTreeWinSize=31 " how wide nerdtree ought to be
" ----------------------------------------------------------------------------
" Visual cues
" ----------------------------------------------------------------------------
set incsearch " do incremental searching
set laststatus=2 " always show the status line
set nohlsearch " don't highlight searches
set visualbell " quiet
set noerrorbells " quiet
" ----------------------------------------------------------------------------
" Text formatting
" ----------------------------------------------------------------------------
set autoindent " automatically indent new lines
set expandtab " expand tabs to spaces
set nowrap " do not wrap lines
set softtabstop=2 " yep, two
set shiftwidth=2
set tabstop=4
set nosmarttab " no tabs, thanks.
" ----------------------------------------------------------------------------
" Backups
" ----------------------------------------------------------------------------
set nobackup " do not keep backups after close
set nowritebackup " do not keep a backup while working
set noswapfile " don't keep swp files either
set backupdir=~/.vim/backups " store backups under ~/.vim/backup
set backupcopy=yes " keep attributes of original file
set backupskip=/tmp/*,$TMPDIR/*,$TMP/*,$TEMP/*
set directory=~/.vim/tmp " where to keep swp files
" ---------------------------------------------------------------------------
" Mappings
" ---------------------------------------------------------------------------
" show/hide nerdtree
map <leader>d :execute 'NERDTreeToggle ' . getcwd()<CR>
map <leader>n :NERDTreeFind<CR>
" navigating search results
map <leader>1 :cprevious <CR>
map <leader>2 :cnext <CR>
" clean up cucumber tables
map <leader>= :Tabularize /\|<CR>
" move between windows
map <C-J> <C-W>j
map <C-K> <C-W>k
map <C-H> <C-W>h
map <C-L> <C-W>l
" method navigation
map <leader>j ]m
map <leader>J ]M
map <leader>k [m
map <leader>K [M
" edit vimrc
map <leader>v :sp ~/.vimrc<CR><C-W>_
map <leader>V :source ~/.vimrc<CR>:filetype detect<CR>:exe ":echo 'vimrc reloaded'"<CR>
" command-t plugin
silent! nmap <unique> <silent> <Leader>f :CommandT<CR>
map <leader>F :CommandTFlush<CR>
set wildignore+=bundler_gems,legacy_gems,coverage,images,activesupport,actionpack,railties,actionmailer
" ack shortcuts
map <leader>A :Ack<cword><CR>
map <leader>a :Ack<Space>
" normal mode shortcuts
nmap <leader><Enter> _i<Enter><Esc>
nmap <leader><Space> i<Space><Esc>
" switch between a symbol and a string
nmap <leader>: ds"i:<Esc>e
nmap <leader>" bhxcsw"
" ctags shortcuts
nmap <C-\> <C-]>
nmap g<C-\> g<C-]>
" easily back to normal mode
imap ;; <Esc>
" auto complete shortcut
imap <S-Space> <C-n>
" hash syntax shortcut
imap <C-l> <Space>=><Space>
" paste the last thing really yanked rather than deleted. Useful for
" repeatedly replacing some text with something previously yanked.
vmap <leader>p "0p
vmap <leader>P "0P
" ---------------------------------------------------------------------------
" rails.vim plugin mappgins
" ---------------------------------------------------------------------------
nmap <leader>r :Rake<CR>
nmap <leader>R :.Rake<CR>
nmap <leader><leader>c :Rcontroller
nmap <leader><leader>m :Rmodel
nmap <leader><leader>v :Rview
nmap <leader><leader>h :Rhelper
nmap <leader><leader>i :Rinitializer
nmap <leader><leader>e :Renvironment
nmap <leader><leader>l :Rlib
nmap <leader><leader>s :Rintegrationtest
nmap <leader><leader>u :Runittest
" ---------------------------------------------------------------------------
" Status line customization
" ---------------------------------------------------------------------------
set statusline=
set statusline+=%-3.3n\ " buffer number
set statusline+=%f\ " filename
set number " show line numbers
set statusline+=%h%m%r%w " status flags
set statusline+=\[%{strlen(&ft)?&ft:'none'}] " file type
set statusline+=\ %{fugitive#statusline()} " fugitive
set statusline+=%= " right align remainder
set statusline+=%-14(%l,%c%V%) " line, character
set statusline+=%<%P " file position
" ---------------------------------------------------------------------------
" Command-t customization
" ---------------------------------------------------------------------------
let g:CommandTMaxHeight=20
" ---------------------------------------------------------------------------
" Colors/Theme
" ---------------------------------------------------------------------------
colorscheme vividchalk
syntax on
" ---------------------------------------------------------------------------
" Surround plugin - allow # to be used for string interpolation.
" ---------------------------------------------------------------------------
autocmd FileType ruby let g:surround_113 = "#{\r}" " v
autocmd FileType ruby let g:surround_35 = "#{\r}" " #
" ---------------------------------------------------------------------------
" Misc stuff
" ---------------------------------------------------------------------------
set clipboard+=unnamed
set grepprg=ack
set grepformat=%f:%l:%m
inoremap <expr> <C-n> pumvisible() ? '<C-n>' : '<C-n><C-r>=pumvisible() ? "\<lt>Down>" : ""<CR>'
set completeopt=longest,menu,preview " insert mode comletion options
set complete=.
set lines=79 columns=272
" Write all named, changed buffers when Vim loses focus
au FocusLost * :wall
augroup myfiletypes
"clear old autocmds in group
autocmd!
"for ruby, autoindent with two spaces, always expand tabs
autocmd FileType ruby,haml,eruby,yaml set ai sw=2 sts=2 et
augroup END
augroup markdown
autocmd BufRead *.markdown set ai formatoptions=tcroqn2 comments=n:>
augroup END
let g:liquid_highlight_types=["html","erb=eruby","html+erb=eruby.html"]
" ---------------------------------------------------------------------------
" Jump to last saved position of buffer when re-opening
" ---------------------------------------------------------------------------
augroup JumpCursorOnEdit
au!
autocmd BufReadPost *
\ if expand("<afile>:p:h") !=? $TEMP |
\ if line("'\"") > 1 && line("'\"") <= line("$") |
\ let JumpCursorOnEdit_foo = line("'\"") |
\ let b:doopenfold = 1 |
\ if (foldlevel(JumpCursorOnEdit_foo) > foldlevel(JumpCursorOnEdit_foo - 1)) |
\ let JumpCursorOnEdit_foo = JumpCursorOnEdit_foo - 1 |
\ let b:doopenfold = 2 |
\ endif |
\ exe JumpCursorOnEdit_foo |
\ endif |
\ endif
" Need to postpone using "zv" until after reading the modelines.
autocmd BufWinEnter *
\ if exists("b:doopenfold") |
\ exe "normal zv" |
\ if(b:doopenfold > 1) |
\ exe "+".1 |
\ endif |
\ unlet b:doopenfold |
\ endif
augroup END
" ---------------------------------------------------------------------------
" Open url on current line in browser
" ---------------------------------------------------------------------------
function! HandleURI()
let s:uri = matchstr(getline("."), '[a-z]*:\/\/[^ >,;:]*')
echo s:uri
if s:uri != ""
exec "!open \"" . s:uri . "\""
else
echo "No URI found in line."
endif
endfunction
nmap <Leader>b :call HandleURI()<CR>
" ---------------------------------------------------------------------------
" Allow toggling of the quickfix window
" ---------------------------------------------------------------------------
command! -bang -nargs=? QFix call QFixToggle(<bang>0)
function! QFixToggle(forced)
if exists("g:qfix_win") && a:forced == 0
cclose
else
execute "copen 15"
endif
endfunction
nmap <Leader>q :QFix<CR>
augroup QFixToggle
autocmd!
autocmd BufWinEnter quickfix let g:qfix_win = bufnr("$")
autocmd BufWinLeave * if exists("g:qfix_win") && expand("<abuf>") == g:qfix_win | unlet! g:qfix_win | endif
augroup END
" ---------------------------------------------------------------------------
" Operate on indent levels. Awesomeness.
" ---------------------------------------------------------------------------
onoremap <silent>ai :<C-u>cal IndTxtObj(0)<CR>
onoremap <silent>ii :<C-u>cal IndTxtObj(1)<CR>
vnoremap <silent>ai :<C-u>cal IndTxtObj(0)<CR><Esc>gv
vnoremap <silent>ii :<C-u>cal IndTxtObj(1)<CR><Esc>gv
function! IndTxtObj(inner)
if &filetype == 'haml' || &filetype == 'sass' || &filetype == 'python'
let meaningful_indentation = 1
else
let meaningful_indentation = 0
endif
let curline = line(".")
let lastline = line("$")
let i = indent(line(".")) - &shiftwidth * (v:count1 - 1)
let i = i < 0 ? 0 : i
if getline(".") =~ "^\\s*$"
return
endif
let p = line(".") - 1
let nextblank = getline(p) =~ "^\\s*$"
while p > 0 && (nextblank || indent(p) >= i )
-
let p = line(".") - 1
let nextblank = getline(p) =~ "^\\s*$"
endwhile
if (!a:inner)
-
endif
normal! 0V
call cursor(curline, 0)
let p = line(".") + 1
let nextblank = getline(p) =~ "^\\s*$"
while p <= lastline && (nextblank || indent(p) >= i )
+
let p = line(".") + 1
let nextblank = getline(p) =~ "^\\s*$"
endwhile
if (!a:inner && !meaningful_indentation)
+
endif
normal! $
endfunction