-
Notifications
You must be signed in to change notification settings - Fork 2
/
.vimrc
290 lines (232 loc) · 7.82 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
set nocompatible " don't attempt to be compatible with old-style vi
call pathogen#infect()
behave xterm
syntax on
syntax sync fromstart
colorscheme jellybeans
filetype plugin indent on
" editor behavior
set wildmenu " show matches on tab-completion
set incsearch " show matches while typing search string
set noshowmatch " don't jump to matching bracket after typing closing bracket
set foldmethod=syntax " fold code based on syntax
set foldlevel=3
set nostartofline " keep cursor in same column during motion commands
set modeline " read modelines
set mouse=a " enable mouse in all modes
set updatetime=100 " delay (ms) before CursorHold event
set dir=/tmp " write swap files to /tmp
set foldtext=getline(v:foldstart)
set fillchars="vert:|"
" indentation preferences
set smarttab
set expandtab
set tabstop=2
set shiftwidth=2
set backspace=2
set autoindent
set textwidth=100
" C formatting options
set cinoptions=t0,+2s,g0
set cinwords=if,unless,else,while,until,do,for,switch,case
set cindent
set formatoptions=croql
" display options
set number " show line numbers
set ruler " show current line, column, and relative position in file
set showmode " show current mode (insert, replace, visual)
set nowrap " don't wrap long lines
set novisualbell " no blinking
set noerrorbells " no noise
set list " show hidden characters
set listchars=tab:>=,trail:~,extends:>,precedes:<,nbsp:.
" highlight current line in active window
autocmd WinEnter * setlocal cursorline
autocmd WinLeave * setlocal nocursorline
autocmd InsertEnter * setlocal nocursorline
autocmd InsertLeave * setlocal cursorline
autocmd CursorHoldI * setlocal cursorline
autocmd CursorMovedI * setlocal nocursorline
setlocal cursorline " enable in active window just after vim loads
let mapleader = ","
" close preview window
nnoremap <Leader>p :pclose<CR>
" highlight past 80 columns
"highlight OverLength cterm=reverse
"match OverLength /\%81v.*/
" use ; to enter command mode
nnoremap ; :
" reselect visual block after shift
vnoremap < <gv
vnoremap > >gv
" shorter keystrokes for split navigation
noremap <C-h> <C-w>h
noremap <C-j> <C-w>j
noremap <C-k> <C-w>k
noremap <C-l> <C-w>l
" disable those damn arrow keys
nnoremap <up> <nop>
nnoremap <down> <nop>
nnoremap <left> <nop>
nnoremap <right> <nop>
inoremap <up> <nop>
inoremap <down> <nop>
inoremap <left> <nop>
inoremap <right> <nop>
" to write to protected files
cmap w!! %!sudo tee %
" fix pageup and pagedown behavior
map <PageUp> <C-U>
map <PageDown> <C-D>
imap <PageUp> <C-O><C-U>
imap <PageDown> <C-O><C-D>
" fix C-Page{Up,Down} in rxvt (sends different key codes)
nmap <ESC>[5^ <C-PageUp>
nmap <ESC>[6^ <C-PageDown>
" Save the last source buffer so that we can return to it after switching to helper windows, such as
" NERDTree or Tagbar.
" Returns true if the current buffer is a source file.
function! g:IsSourceBuffer()
return !(winnr() == g:NERDTreeWindow() || winnr() == g:TagbarWindow())
endfunction
" Saves the current source buffer so that it can be restored by g:RestoreLastSourceBuffer().
function! g:SaveLastSourceBuffer()
if g:IsSourceBuffer()
let t:LastSourceBuffer = bufnr('%')
endif
endfunction
" Returns to the last source file that was being edited.
function! g:RestoreLastSourceBuffer()
if exists('t:LastSourceBuffer')
execute bufwinnr(t:LastSourceBuffer) . 'wincmd w'
else
execute 'wincmd p'
endif
endfunction
" NERDTree
let NERDTreeChDirMode = 2 " keep working directory set to NERD's root node
let NERDTreeWinPos = "left"
let NERDTreeWinSize = 35
let NERDTreeQuitOnOpen = 1
let NERDTreeIgnore = ['\~$', '\.o$', '\.lo$', '\.la$', '\.log$', '^stamp-h1$', '^test-suite.log$', '_unittest']
function! g:NERDTreeWindow()
if exists('t:NERDTreeBufName')
return bufwinnr(t:NERDTreeBufName)
else
return -1
endif
endfunction
function! g:OpenNERDTreeWithSaveSourceBuffer()
call g:SaveLastSourceBuffer()
if g:NERDTreeWindow() < 0
NERDTreeToggle
else
execute g:NERDTreeWindow() . 'wincmd w'
endif
endfunction
" Alternates between the NERDTree window and a source window.
function! g:AlternateNERDTreeAndBuffer()
if winnr() == g:NERDTreeWindow()
call g:RestoreLastSourceBuffer()
else
call g:OpenNERDTreeWithSaveSourceBuffer()
endif
endfunction
" Focuses the NERDTree window on the current file
function! g:NERDTreeFocusCurrentBuffer()
if g:NERDTreeWindow() < 0
call g:OpenNERDTreeWithSaveSourceBuffer()
endif
if !g:IsSourceBuffer()
call g:RestoreLastSourceBuffer()
endif
NERDTreeFind
endfunction
noremap <silent> <F2> :NERDTreeToggle<CR>
nnoremap <silent> <Leader>f :call g:AlternateNERDTreeAndBuffer()<CR>
nnoremap <silent> <Leader>F :call g:NERDTreeFocusCurrentBuffer()<CR>
" open NERDTree if vim is launched without opening a file
autocmd VimEnter * if !argc() | NERDTree | endif
" quit vim if NERDTree is the only window left open
autocmd BufEnter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif
" NERDCommenter
let g:NERDCustomDelimiters = { 'toml': { 'left': '#' } }
" Tagbar
let g:tagbar_left = 0
let g:tagbar_width = 40
let g:tagbar_autofocus = 1
let g:tagbar_autoclose = 1
let g:tagbar_sort = 1
let g:tagbar_compact = 0
let g:tagbar_expand = 0
let g:tagbar_singleclick = 1
let g:tagbar_foldlevel = 4
let g:tagbar_iconchars = ['▶', '▼']
let g:tagbar_autoshowtag = 0
let g:tagbar_type_coffee = {
\ 'ctagstype' : 'coffee',
\ 'kinds' : [
\ 'f:functions',
\ 'v:variables'
\ ],
\ }
function! g:TagbarWindow()
return bufwinnr('__Tagbar__')
endfunction
function! g:OpenTagbarWithSaveSourceBuffer()
call g:SaveLastSourceBuffer()
call tagbar#OpenWindow('fj')
endfunction
function! g:AlternateTagbarAndBuffer()
if winnr() == g:TagbarWindow()
call g:RestoreLastSourceBuffer()
else
call g:OpenTagbarWithSaveSourceBuffer()
endif
endfunction
noremap <silent> <F3> :TagbarToggle<CR>
nnoremap <silent> <Leader>g :call g:AlternateTagbarAndBuffer()<CR>
" ctags
set tags=./tags;/
map <silent> <C-\> :vsplit <CR>:exec("tag ".expand("<cword>"))<CR>
map <silent> <C-S-\> :tab split <CR>:exec("tag ".expand("<cword>"))<CR>
" VimClojure
let vimclojure#SplitPos = "right"
let vimclojure#UseErrorBuffer=0
let vimclojure#FuzzyIndent=1
let vimclojure#HighlightBuiltins=1
let vimclojure#HighlightContrib=1
let vimclojure#DynamicHighlighting=1
let vimclojure#ParenRainbow=1
let vimclojure#WantNailgun=1
autocmd FileType ruby nnoremap <buffer> K :call ri#LookupNameUnderCursor()<CR>
" configure haskellmode-vim
let g:haddock_browser="/usr/bin/chromium-browser"
let $PATH = $PATH . ':' . expand("~/.cabal/bin")
" fix grep in OSX
map <F8> :GrepBuffer<CR><CR>
map <F9> :Rgrep<CR><CR>
let Grep_Find_Use_Xargs = 0
" tabs
nnoremap <silent> <C-PageUp> :tabprev<CR>
nnoremap <silent> <C-PageDown> :tabnext<CR>
" copy/cut/paste
vnoremap <C-X> "+x
vnoremap <C-C> "+y
nnoremap <C-V> "+gP
cnoremap <C-V> <C-R>+
" expand surrounding code-folds
nmap zp zozjzo2zkzozj
" remove trailing white-space when saving a file
autocmd BufWritePre * :%s/\s\+$//e
" treat hamlc as haml
autocmd BufRead,BufNewFile *.hamlc set filetype=haml
" use Dispatch and Zeus with vim-rspec
let g:rspec_command = "compiler rspec | set makeprg=zeus | Make rspec {spec}"
nnoremap <silent> <Leader>r :call RunCurrentSpecFile()<CR>
nnoremap <silent> <Leader>R :call RunNearestSpec()<CR>
nnoremap <silent> <Leader>s :call RunLastSpec()<CR>
" debug syntax highlighting
map <Leader>sn :echo "hi<" . synIDattr(synID(line("."),col("."),1),"name") . '> trans<'
\ . synIDattr(synID(line("."),col("."),0),"name") . "> lo<"
\ . synIDattr(synIDtrans(synID(line("."),col("."),1)),"name") . ">"<CR>