/
.vimrc
360 lines (304 loc) · 7.71 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
" Pathogen {{{
filetype off
runtime bundle/vim-pathogen/autoload/pathogen.vim
call pathogen#infect()
filetype plugin indent on
" }}}
" Globals {{{
if $VIM_CRONTAB == "true"
set nobackup
set nowritebackup
endif
set nocompatible
set modelines=0
set mouse=a
set autoread
set ttyfast
set viminfo=/10,'10,r/mnt/zip,r/mnt/floppy,f0,h,\"100
set wildmode=list:longest,full
set wildignore+=*.o,*.obj,.git,.svn,*.pyc
set wildignore+=*/.git/*,*/.svn/*
set hidden
set switchbuf=usetab,newtab
" }}}
" Tab/spaces {{{
set shiftwidth=4
set tabstop=4
set softtabstop=4
set expandtab
" }}}
" Backups {{{
if v:version >= 703
set undofile
set undodir=./.tmp,/tmp
else
let g:gundo_disable = 1
endif
set backupdir=./.tmp,.,/tmp
set directory=./.tmp,/tmp
set history=500
set undolevels=500
" }}}
" User Interface {{{
set guioptions-=T
set guioptions-=r
syntax on
set bg=dark
set number
if v:version >= 703
set relativenumber
set cc=80
endif
set listchars=tab:▸\ ,eol:¬,trail:·
set shortmess+=r
set showmode
set showcmd
set showmatch
set t_Co=256
colorscheme molokai
hi ColorColumn ctermbg=234
if has('gui_running')
set guifont=Menlo:h12
set go-=m
endif
set cursorline
set ruler
set backspace=indent,eol,start
set laststatus=2
set encoding=utf-8
let g:Powerline_symbols = 'fancy'
if exists('$TMUX')
let &t_SI = "\<Esc>Ptmux;\<Esc>\<Esc>]50;CursorShape=1\x7\<Esc>\\"
let &t_EI = "\<Esc>Ptmux;\<Esc>\<Esc>]50;CursorShape=0\x7\<Esc>\\"
else
let &t_SI = "\<Esc>]50;CursorShape=1\x7"
let &t_EI = "\<Esc>]50;CursorShape=0\x7"
endif
" }}}
" Leader {{{
let mapleader=','
" }}}
" Search {{{
set incsearch
set hlsearch
set nowrap
set shiftround
set autoindent
set ignorecase
set smartcase
set gdefault
" PulseCursorLine
nnoremap n nzzzv:call PulseCursorLine()<cr>
nnoremap N Nzzzv:call PulseCursorLine()<cr>
" }}}
" Text {{{
set formatoptions-=t
set textwidth=79
" }}}
" Scroll {{{
set scrolloff=3
set sidescroll=1
set sidescrolloff=10
" }}}
" Fn keys mapping {{{
" Get out of <esc>
inoremap gq <esc>
inoremap <esc> <nop>
nnoremap <F2> :set invpaste paste?<CR>
imap <F2> <C-O><F2>
set pastetoggle=<F2>
nnoremap <F3> :GundoToggle<CR>
nnoremap <silent> <F4> :YRShow<cr>
inoremap <silent> <F4> <ESC>:YRShow<cr>
nnoremap <F5> :execute 'set ' . (&relativenumber ? 'number' : 'relativenumber') <CR>
" }}}
" Yankring {{{
let g:yankring_max_history = 10
let g:yankring_max_element_length = 512000
let g:yankring_history_file = '.vim_yankring_history'
" }}}
" Bépo specific {{{
noremap é w
noremap É W
noremap è bbbe
" }}}
" Insert <Tab> or complete identifier {{{
" if the cursor is after a keyword character
function! MyTabOrComplete()
let col = col('.')-1
if !col || getline('.')[col-1] !~ '\k'
return "\<tab>"
else
return "\<C-N>"
endif
endfunction
inoremap <Tab> <C-R>=MyTabOrComplete()<CR>
" }}}
" Autocommands {{{
"
" Jumps to the last known position in a file , if the '"' mark is set:
:au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g`\"" | endif
" Save when losing focus
au FocusLost * :wa
" }}}
" Special filetype conf {{{
au FileType yaml setlocal ts=2 sts=2 sw=2 expandtab
au FileType coffee setlocal ts=2 sts=2 sw=2 expandtab
au FileType html setlocal textwidth=0
au BufNewFile,BufRead *.less setf less
au BufNewFile,BufRead *.map setf map
au BufNewFile,BufRead *.tmux.conf setf tmux
au BufNewFile,BufRead *.pp setf puppet
au BufNewFile,BufRead *.penta setf pentadactyl
au BufNewFile,BufRead .pentadactylrc setf pentadactyl
" }}}
" Execute function preserving state {{{
function! Preserve(command)
" Preparation: save last search, and cursor position.
let _s=@/
let l = line(".")
let c = col(".")
" Do the business:
execute a:command
" Clean up: restore previous search history, and cursor position
let @/=_s
call cursor(l, c)
endfunction
" }}}
" Utilities {{{
" Disable highlight
map <leader><space> :noh<cr>
" Hidden chars
nmap <leader>l :set list!<CR>
" remap Y to follow same principle as C, D
noremap Y y$
" Remove trailing spaces
nmap _$ :call Preserve("%s/\\s\\+$//e")<CR>
" Indent whole file
nmap _= :call Preserve("normal gg=G")<CR>
" Order CSS properties
nnoremap <leader>S ?{<CR>jV/}$<CR>k:sort<CR>:noh<CR>
" Quicker window switching
nnoremap <leader>, <c-w><c-w>
" ack-grep word under cursor
let g:ackprg="ack-grep -H --nocolor --nogroup --column --ignore-dir=buildout --ignore-dir=build"
noremap <leader># "ayiw:Ack <c-r>a<CR>
" Tabularize
noremap <leader>: :Tabularize /:<cr>
noremap <leader>= :Tabularize /=<cr>
noremap <leader>o vi{:Tabularize /:<cr>
" Select previous selection
nmap gV `[v`[
" Surround shortcut
nmap <leader>é ysiw
" Sudo save
cmap w!! w !sudo tee % >/dev/null
" From tab to vsplit
nnoremap <c-w>V mAZZ<c-w>v`A
" }}}
" Bubbling {{{
" Bubble single lines
nmap <C-k> [e
nmap <C-j> ]e
" Bubble multiple lines
vmap <C-k> [egv
vmap <C-j> ]egv
" }}}
" Fast file opening {{{
map <leader>ew :e <C-R>=expand("%:p:h") . "/" <CR>
map <leader>es :sp <C-R>=expand("%:p:h") . "/" <CR>
map <leader>ev :vsp <C-R>=expand("%:p:h") . "/" <CR>
map <leader>et :tabe <C-R>=expand("%:p:h") . "/" <CR>
map <leader>c :CtrlP<CR>
map <leader>b :CtrlPBuffer<CR>
let g:ctrlp_working_path_mode=2
let g:ctrlp_user_command = ['.git/', 'cd %s && git ls-files', 'find %s -type f']
" }}}
" Folding {{{
" Folding methods {{{
set foldmethod=marker
au FileType vim setlocal foldmethod=marker
au FileType css setlocal foldmethod=marker
au FileType pentadactyl setlocal foldmethod=marker
au BufNewFile,BufRead *.css setlocal foldmarker={,}
au FileType javascript setlocal foldmethod=marker
au FileType javascript setlocal foldmarker={,}
au FileType html setlocal foldmethod=manual
" }}}
nnoremap za
vnoremap za
function! MyFoldText() " {{{
let line = getline(v:foldstart)
let nucolwidth = &fdc + &number * &numberwidth
let windowwidth = winwidth(0) - nucolwidth - 3
let foldedlinecount = v:foldend - v:foldstart
" expand tabs into spaces
let onetab = strpart(' ', 0, &tabstop)
let line = substitute(line, '\t', onetab, 'g')
let line = strpart(line, 0, windowwidth - 2 -len(foldedlinecount))
let fillcharcount = windowwidth - len(line) - len(foldedlinecount)
return line . '…' . repeat(" ",fillcharcount) . foldedlinecount . '…' . ' '
endfunction " }}}
set foldtext=MyFoldText()
" }}}
" Pulse {{{
function! PulseCursorLine()
let current_window = winnr()
windo set nocursorline
execute current_window . 'wincmd w'
setlocal cursorline
redir => old_hi
silent execute 'hi CursorLine'
redir END
let old_hi = split(old_hi, '\n')[0]
let old_hi = substitute(old_hi, 'xxx', '', '')
hi CursorLine guibg=#2a2a2a ctermbg=233
redraw
sleep 20m
hi CursorLine guibg=#333333 ctermbg=235
redraw
sleep 20m
hi CursorLine guibg=#3a3a3a ctermbg=237
redraw
sleep 20m
hi CursorLine guibg=#444444 ctermbg=239
redraw
sleep 20m
hi CursorLine guibg=#4a4a4a ctermbg=237
redraw
sleep 20m
hi CursorLine guibg=#555555 ctermbg=235
redraw
sleep 20m
execute 'hi ' . old_hi
windo set cursorline
execute current_window . 'wincmd w'
endfunction
" }}}
" Abbreviations & commands {{{
" Typos
ab calss class
ab hig highlight
" Commands
command! -bang W w<bang>
command! -bang Q q<bang>
command! -bang Qa qa<bang>
command! -bang QA qa<bang>
command! -bang Wq wq<bang>
command! -bang WQ wq<bang>
" }}}
" Firefox Reload (UX) ---------------------------------------------------- {{{
function! UXReload()
python << EOF
from subprocess import call
browser = """
tell application "Firefox UX Nightly"
activate
tell application "System Events" to keystroke "r" using command down
end tell
"""
call(['osascript', '-e', browser])
EOF
endfunction
noremap <leader>r :call UXReload()<cr>
" }}}