forked from NARKOZ/dotfiles
/
.vimrc
286 lines (232 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
" ---------------------------------------------------------------------------
" General
" ---------------------------------------------------------------------------
set nocompatible " essential
set history=1000 " lots of command line history
set cf " error files / jumping
set ffs=unix,dos,mac " support these files
set isk+=_,$,@,%,#,- " none word dividers
set viminfo='1000,f1,:100,@100,/20
set modeline " make sure modeline support is enabled
set autoread " reload files (no local changes only)
set tabpagemax=50 " open 50 tabs max
call pathogen#runtime_append_all_bundles()
filetype plugin indent on
" ---------------------------------------------------------------------------
" Colors / Theme
" ---------------------------------------------------------------------------
if &t_Co > 2 || has("gui_running")
if has("terminfo")
set t_Co=16
set t_AB=[%?%p1%{8}%<%t%p1%{40}%+%e%p1%{92}%+%;%dm
set t_AF=[%?%p1%{8}%<%t%p1%{30}%+%e%p1%{82}%+%;%dm
else
set t_Co=16
set t_Sf=[3%dm
set t_Sb=[4%dm
endif
syntax on
set hlsearch
colorscheme slate2
endif
" ---------------------------------------------------------------------------
" Highlight
" ---------------------------------------------------------------------------
highlight Comment ctermfg=DarkGrey guifg=#444444
highlight StatusLineNC ctermfg=Black ctermbg=DarkGrey cterm=bold
highlight StatusLine ctermbg=Black ctermfg=LightGrey
" ----------------------------------------------------------------------------
" Highlight Trailing Whitespace
" ----------------------------------------------------------------------------
set list listchars=trail:.,tab:>.
highlight SpecialKey ctermfg=DarkGray ctermbg=Black
" ----------------------------------------------------------------------------
" 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=$HOME/.vim/backup " store backups under ~/.vim/backup
set backupcopy=yes " keep attributes of original file
set backupskip=/tmp/*,$TMPDIR/*,$TMP/*,$TEMP/*
set directory=~/.vim/swap,~/tmp,. " keep swp files under ~/.vim/swap
" ----------------------------------------------------------------------------
" UI
" ----------------------------------------------------------------------------
set ruler " show the cursor position all the time
set noshowcmd " don't display incomplete commands
set nolazyredraw " turn off lazy redraw
set number " line numbers
set wildmenu " turn on wild menu
set wildmode=list:longest,full
set ch=2 " command line height
set backspace=2 " allow backspacing over everything in insert mode
set whichwrap+=<,>,h,l,[,] " backspace and cursor keys wrap to
set shortmess=filtIoOA " shorten messages
set report=0 " tell us about changes
set nostartofline " don't jump to the start of line when scrolling
" ----------------------------------------------------------------------------
" Visual Cues
" ----------------------------------------------------------------------------
set showmatch " brackets/braces that is
set mat=5 " duration to show matching brace (1/10 sec)
set incsearch " do incremental searching
set laststatus=2 " always show the status line
set ignorecase " ignore case when searching
set nohlsearch " don't highlight searches
set visualbell " shut the fuck up
" ----------------------------------------------------------------------------
" Text Formatting
" ----------------------------------------------------------------------------
set autoindent " automatic indent new lines
set smartindent " be smart about it
set nowrap " do not wrap lines
set softtabstop=2 " yep, two
set shiftwidth=2 " ..
set tabstop=4
set expandtab " expand tabs to spaces
set nosmarttab " fuck tabs
set formatoptions+=n " support for numbered/bullet lists
set textwidth=80 " wrap at 80 chars by default
set virtualedit=block " allow virtual edit in visual block ..
" ----------------------------------------------------------------------------
" Mappings
" ----------------------------------------------------------------------------
" remap <LEADER> to ',' (instead of '\')
let mapleader = ","
" quickfix mappings
map <F7> :cn<CR>
map <S-F7> :cp<CR>
map <A-F7> :copen<CR>
" emacs movement keybindings in insert mode
imap <C-a> <C-o>0
imap <C-e> <C-o>$
map <C-e> $
map <C-a> 0
" reflow paragraph with Q in normal and visual mode
nnoremap Q gqap
vnoremap Q gq
" sane movement with wrap turned on
nnoremap j gj
nnoremap k gk
vnoremap j gj
vnoremap k gk
nnoremap <Down> gj
nnoremap <Up> gk
vnoremap <Down> gj
vnoremap <Up> gk
inoremap <Down> <C-o>gj
inoremap <Up> <C-o>gk
" do not menu with left / right in command line
cnoremap <Left> <Space><BS><Left>
cnoremap <Right> <Space><BS><Right>
" ----------------------------------------------------------------------------
" Auto Commands
" ----------------------------------------------------------------------------
" jump to last position of buffer when opening
au BufReadPost * if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal g'\"" | endif
" don't use cindent for javascript
autocmd FileType javascript setlocal nocindent
" ----------------------------------------------------------------------------
" dbext - connect to any database and do crazy shit
" ----------------------------------------------------------------------------
let g:dbext_default_buffer_lines = 20 " result buffer size
let g:dbext_default_use_result_buffer = 1
let g:dbext_default_use_sep_result_buffer = 1 " multiple result buffers
let g:dbext_default_type = 'pgsql'
let g:dbext_default_replace_title = 1
let g:dbext_default_history_file = '~/.dbext_history'
let g:dbext_default_history_size = 200
" ----------------------------------------------------------------------------
" LookupFile
" ----------------------------------------------------------------------------
let g:LookupFile_TagExpr = '".ftags"'
let g:LookupFile_MinPatLength = 2
let g:LookupFile_ShowFiller = 0 " fix menu flashiness
let g:LookupFile_PreservePatternHistory = 1 " preserve sorted history?
let g:LookupFile_PreserveLastPattern = 0 " start with last pattern?
nmap <unique> <silent> <D-f> <Plug>LookupFile
imap <unique> <silent> <D-f> <C-O><Plug>LookupFile
" ----------------------------------------------------------------------------
" PATH on MacOS X
" ----------------------------------------------------------------------------
if system('uname') =~ 'Darwin'
let $PATH = $HOME .
\ '/usr/local/bin:/usr/local/sbin:' .
\ '/usr/pkg/bin:' .
\ '/opt/local/bin:/opt/local/sbin:' .
\ $PATH
endif
" ---------------------------------------------------------------------------
" sh config
" ---------------------------------------------------------------------------
au Filetype sh,bash set ts=4 sts=4 sw=4 expandtab
let g:is_bash = 1
" ---------------------------------------------------------------------------
" Misc mappings
" ---------------------------------------------------------------------------
" duplicate current tab with same file+line
map ,t :tabnew %<CR>
" open directory dirname of current file, and in new tab
map ,d :e %:h/<CR>
map ,dt :tabnew %:h/<CR>
" open gf under cursor in new tab
map ,f :tabnew <cfile><CR>
" open tag under cursor in new tab
map <C-\> :tab split<CR>:exec("tag ".expand("<cword>"))<CR>
" I use these commands in my TODO file
map ,a o<ESC>:r!date +'\%A, \%B \%d, \%Y'<CR>:r!date +'\%A, \%B \%d, \%Y' \| sed 's/./-/g'<CR>A<CR><ESC>
map ,o o[ ]
map ,O O[ ]
map ,x :s/^\[ \]/[x]/<CR>
map ,X :s/^\[x\]/[ ]/<CR>
" ---------------------------------------------------------------------------
" Open URL on current line in browser
" ---------------------------------------------------------------------------
function! Browser ()
let line0 = getline (".")
let line = matchstr (line0, "http[^ )]*")
let line = escape (line, "#?&;|%")
exec ':silent !open ' . "\"" . line . "\""
endfunction
map ,w :call Browser ()<CR>
" ---------------------------------------------------------------------------
" Strip all trailing whitespace in file
" ---------------------------------------------------------------------------
function! StripWhitespace ()
exec ':%s/ \+$//gc'
endfunction
map ,s :call StripWhitespace ()<CR>
" ---------------------------------------------------------------------------
" File Types
" ---------------------------------------------------------------------------
au BufRead,BufNewFile *.rpdf set ft=ruby
au BufRead,BufNewFile *.rxls set ft=ruby
au BufRead,BufNewFile *.ru set ft=ruby
au BufRead,BufNewFile *.god set ft=ruby
au BufRead,BufNewFile *.rtxt set ft=html spell
au BufRead,BufNewFile *.sql set ft=pgsql
au BufRead,BufNewFile *.rl set ft=ragel
au BufRead,BufNewFile *.svg set ft=svg
au BufRead,BufNewFile *.haml set ft=haml
au BufRead,BufNewFile *.md set ft=mkd tw=80 ts=2 sw=2 expandtab
au BufRead,BufNewFile *.markdown set ft=mkd tw=80 ts=2 sw=2 expandtab
au BufRead,BufNewFile *.ronn set ft=mkd tw=80 ts=2 sw=2 expandtab
au Filetype gitcommit set tw=68 spell
au Filetype ruby set tw=80 ts=2
au Filetype html,xml,xsl,rhtml source $HOME/.vim/scripts/closetag.vim
au BufNewFile,BufRead *.mustache setf mustache
" --------------------------------------------------------------------------
" ManPageView
" --------------------------------------------------------------------------
let g:manpageview_pgm= 'man -P "/usr/bin/less -is"'
let $MANPAGER = '/usr/bin/less -is'
" --------------------------------------------------------------------------
" rails.vim
" --------------------------------------------------------------------------
let g:rails_subversion=1
let g:rails_menu=2
" make file executable
command -nargs=* Xe !chmod +x <args>
command! -nargs=0 Xe !chmod +x %