-
Notifications
You must be signed in to change notification settings - Fork 0
/
vimrc
469 lines (391 loc) · 13.8 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
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
set nocompatible " Disable vi compatibility
" Getter/Setter generation
let g:phpgetset_getterTemplate =
\ " \n" .
\ " /**\n" .
\ " * Get %varname%.\n" .
\ " *\n" .
\ " * @return <type>\n" .
\ " */\n" .
\ " public function %funcname%()\n" .
\ " {\n" .
\ " return $this->%varname%;\n" .
\ " }"
let g:phpgetset_setterTemplate =
\ " \n" .
\ " /**\n" .
\ " * Set %varname%.\n" .
\ " *\n" .
\ " * @param <type> $%varname%\n" .
\ " * @return fluent\n" .
\ " */\n" .
\ " public function %funcname%($%varname%)\n" .
\ " {\n" .
\ " $this->%varname% = $%varname%;\n" .
\ " return $this;\n" .
\ " }"
let g:UltiSnipsUsePythonVersion = 2
set nofoldenable " disable code folding
let g:DisableAutoPHPFolding = 1 " disable autofolding for PHP
let g:PIVCreateDefaultMappings = 0 " disable creation of default mapping
let g:pdv_cfg_foldmarke = 0 " disable generation of fold marker for docblocks
" PIV PHP shortcuts - create single docblock in PHP
nmap <leader>cd <plug>PIVphpDocSingle
vmap <leader>cd <plug>PIVphpDocRange
" Pathogen plugin management
filetype off
call pathogen#infect() " Load plugin
call pathogen#helptags() " Load plugin help files
syntax on " Syntax highlighting on
filetype plugin indent on " Enable filetype-specific indenting and plugins
" powerline
set rtp+=~/dotfiles/powerline/powerline/bindings/vim
" ========================================================================
" General settings
" ========================================================================
set showcmd " show commands in the status bar
set noshowmode " don't show the current vim mode, powerline does it
" by default we go with 4 space indent and spaces
set expandtab
set softtabstop=4
set shiftwidth=4
set tabstop=4
set showtabline=1
set encoding=utf-8 " Utf-8 everything
set fileencodings=utf-8
set termencoding=utf-8
set laststatus=2 " Always show two line status
set ff=unix " Set file format to Unix
set history=1000 " Change history to 200 items
set wildmenu " use menu that looks like zsh
set wildmode=list:longest,full
" Color scheme
set t_Co=256
set background=dark
let g:solarized_contrast="normal"
let g:solarized_visibility="high"
colorscheme solarized
set autoread " Reload files that have not been modified
set autowrite " Automatically :write before running commands
set list " Show hidden characters
set listchars=tab:›\ ,eol:¬,trail:⋅ " Set the characters for the invisibles
set number
set relativenumber " Show relative line numbers
set scrolloff=999 " Keep the cursor centered in the screen
set showmatch " Highlight matching braces
set splitbelow " Splits show up below by default
set splitright " Splits go to the right by default
set textwidth=80
set colorcolumn=+1
set numberwidth=5
set showbreak=…
" Search settings
set hlsearch " Highlight results
set ignorecase " Ignore casing of searches
set incsearch " Start showing results as you type
set smartcase " Be smart about case sensitivity when searching
if ! has('gui_running')
set term=xterm-256color
endif
" performance improvements?
set nocursorline " Don't paint cursor line
set nocursorcolumn " Don't paint cursor column
" set cursorline
set lazyredraw " Wait to redraw
set ttyfast " Fast tty
" History undo
set history=1000 " remember more commands and search history
" GIT is there for this
set nobackup " no backup files
set nowritebackup " only in case you don't want a backup file while editing
set noswapfile " no swap files
" Misc
set modelines=5 " Enable mode line to tell vim what to do of odd files
set viminfo+=!
set smarttab
set gdefault " assume the /g flag is used for replace
set autoindent
set ignorecase smartcase
set grepprg=ack-grep
" (Hopefully) removes the delay when hitting esc in insert mode
set noesckeys
set ttimeout
set ttimeoutlen=1
" Don't add the comment prefix when I hit enter or o/O on a comment line.
"set formatoptions-=or
set formatoptions=qrn1
" Undo everything
set undodir=~/.vim/undo
set undofile
set undolevels=1000 " maximum number of changes that can be undone
set undoreload=10000 " maximum number lines to save for undo on a buffer reload
set shiftround " When at 3 spaces and I hit >>, go to 4, not 5.
" Don't wait so long for the next keypress (particularly in ambigious Leader
" situations.
"set timeoutlen=500
" ========================================================================
" Plugin settings
" ========================================================================
" vim-hardtime
let g:hardtime_maxcount = 2
let g:hardtime_allow_different_key = 1
let g:hardtime_ignore_buffer_patterns = [ "\.git/" ]
" easymotion
let g:EasyMotion_keys = 'abcdefghijklmnopqrstuvwxyz'
let g:EasyMotion_leader_key='t'
let g:EasyMotion_startofline = 0 " keep cursor colum when JK motion
let g:EasyMotion_use_upper = 1
"python import sys; sys.path.append("/Library/Python/2.7/site-packages")
"python from powerline.vim import setup as powerline_setup
"python powerline_setup()
"python del powerline_setup
" python from powerline.ext.vim import source_plugin; source_plugin()
let g:Powerline_symbols = 'fancy'
" Neocomplete
let g:neocomplete#enable_at_startup = 1 " Start it
let g:neocomplete#enable_auto_select = 0 " Disable autoselect
let g:neocomplete#max_list = 25 " show 25 results in popup
autocmd FileType html,markdown setlocal omnifunc=htmlcomplete#CompleteTags " customize omni completion
inoremap <expr><TAB> pumvisible() ? "\<C-n>" : "\<TAB>" " make tab select entry
" Ultisnip
if (has('gui_running'))
let g:UltiSnipsExpandTrigger="<C-CR>"
else
let g:UltiSnipsExpandTrigger="<C-J>"
endif
" Tweak some things for CtrlP
let g:ctrlp_map = '<c-p>'
let g:ctrlp_cmd = 'CtrlP'
set wildignore+=*/tmp/*,*.so,*.swp,*.zip,*/vendor/*
let g:ctrlp_custom_ignore = '\v[\/]\.(git|hg|svn)$'
let g:ctrlp_user_command = {
\ 'types' : {
\ 1: ['.git', 'cd %s && git ls-files'],
\ },
\ 'fallback': 'find %s -type f'
\ }
" ========================================================================
" Key mappings
" ========================================================================
" Disable Ex mode
map Q <Nop>
" Disable K looking stuff up
map K <Nop>
" Leader key
let mapleader = "\<Space>" " space as leader key
" easymotion
"map <leader>l <Plug>(easymotion-lineforward)
"map <leader>j <Plug>(easymotion-j)
"map <leader>k <Plug>(easymotion-k)
"map <leader>h <Plug>(easymotion-linebackward)
"map <leader>f <Plug>(easymotion-bd-f)
"map <leader>t <Plug>(easymotion-bd-t)
" clear out search buffer easier
nmap <silent> ,/ :let @/=""<CR>
" Switch between the last two files
nnoremap <leader><leader> <c-^>
" easily switch between vsplit 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
" save yourself if you forgot to use sudo to save something
cmap w!! w !sudo tee % >/dev/null
" tabularize shortcut
vmap t= :Tabularize /=><CR>
vmap t" :Tabularize /"<CR>
nnoremap <silent> <leader>t= :Tabularize /=><CR>
" Nerdtree support
map <C-n> :NERDTreeToggle<CR>
" Training wheels, disable arrows
inoremap <Up> <NOP>
inoremap <Down> <NOP>
inoremap <Left> <NOP>
inoremap <Right> <NOP>
noremap <Up> <NOP>
noremap <Down> <NOP>
noremap <Left> <NOP>
noremap <Right> <NOP>
" Shortcut to yanking to the system clipboard
map <leader>y "+y
map <leader>p "+p
" Let's be reasonable, shall we?
nmap k gk
nmap j gj
map <leader>P :call <SID>PasteFromTmux()<CR>
" Expand in command mode to the path of the currently open file
cnoremap %% <C-R>=expand('%:h').'/'<CR>
" Buffer management
nnoremap <leader>d :bd<cr>
" Toogle relative line number
nnoremap <silent><leader>n :set relativenumber!<cr>
" disable HL search
nmap <silent><leader>/ :nohlsearch<CR>
" Fugitive and GIT goodness
nnoremap <silent> <leader>gs :Gstatus<CR>
nnoremap <silent> <leader>gd :Gdiff<CR>
nnoremap <silent> <leader>gc :Gcommit<CR>
nnoremap <silent> <leader>gb :Gblame<CR>
nnoremap <silent> <leader>gl :Glog<CR>
nnoremap <silent> <leader>gp :Git push<CR>
"nnoremap <silent> <leader>gr :Gread<CR>
nnoremap <silent> <leader>gw :Gwrite<CR>
nnoremap <silent> <leader>ge :Gedit<CR>
" GIT workflow
" <space>gm = git checkout master
nnoremap <silent> <leader>gm :Git checkout master<CR>
" push my current work to live only works from master
nnoremap <silent> <leader>gli :Git pull --rebase<CR>:Git checkout live<CR>:Git pull --rebase origin live<CR>:Git merge master<CR>:Git push origin live<CR>:Git checkout master<CR>
" Remap a key sequence in insert mode to kick me out to normal
" mode. This makes it so this key sequence can never be typed
" again in insert mode, so it has to be unique.
inoremap jj <esc>
inoremap jJ <esc>
inoremap Jj <esc>
inoremap JJ <esc>
inoremap jk <esc>
inoremap jK <esc>
inoremap Jk <esc>
inoremap JK <esc>
" test tmux
let &t_ti = &t_ti . "\e[?2004h"
let &t_te = "\e[?2004l" . &t_te
let &pastetoggle = "\e[201~"
map <F10> <Esc>[201~
imap <F10> <Esc>[201~
map <special> <expr> <Esc>[200~ XTermPasteBegin("i")
imap <special> <expr> <Esc>[200~ XTermPasteBegin("")
cmap <special> <Esc>[200~ <nop>
cmap <special> <Esc>[201~ <nop>
" Ctrl s save
" Note that remapping C-s requires flow control to be disabled
" (e.g. in .bashrc or .zshrc)
map <C-s> <esc>:w<CR>
imap <C-s> <esc>:w<CR>
map <C-t> <esc>:tabnew<CR>
map <C-x> <C-w>c
" Emacs-like beginning and end of line.
imap <c-e> <c-o>$
imap <c-a> <c-o>^
map <leader>vi :tabe ~/.vimrc<cr>
:inoremap <c-f> <C-R>=expand("%:t:r")<CR>
" Disable esc and try to use Ctrl + [ or jj
" disabled for now because it breaks Ctrl + s
" inoremap <Esc> <Nop>
" ============================================================================
" Gvim
" ============================================================================
if has("gui_running")
" Disable any visual or audible bell
au GUIEnter * set vb t_vb=
" Set font
set guifont=Inconsolata\ for\ Powerline\ Bold\ 13
" remove superfluous chrome
set guioptions-=m
set guioptions-=l
set guioptions-=L
set guioptions-=t
set guioptions-=T
set guioptions+=c
set guioptions-=l
set guioptions-=r
set guioptions-=b
endif
" ============================================================================
" Functions/Macro
" ============================================================================
" this should be included by vim snippet but does not work somehow
fun! vim_snippets#Filename(...)
let template = get(a:000, 0, "$1")
let arg2 = get(a:000, 1, "")
let basename = expand('%:t:r')
if basename == ''
return arg2
else
return substitute(template, '$1', basename, 'g')
endif
endf
" Remove trailling spaces
fun! <SID>ReplaceTabs()
let l = line(".")
let c = col(".")
%s/\t/ /e
call cursor(l, c)
endfun
" Strip trailing whitespaces
function! <sid>StripTrailingWhitespaces()
" Preparation: save last search, and cursor position.
let _s=@/
let l = line(".")
let c = col(".")
" Do the business:
%s/\s\+$//e
" Clean up: restore previous search history, and cursor position
let @/=_s
call cursor(l, c)
endfunction
" Handle paste in vim from tmux
fun! <SID>PasteFromTmux()
set paste
startinsert
!tmux paste-buffer -p
!tmux send-keys Escape ":set nopaste" Enter
endfun
" used to paste from tmux
function! XTermPasteBegin(ret)
set paste
return a:ret
endfunction
" create directory for current buffer
function! <sid>MkdirsIfNotExists(directory)
if(!isdirectory(a:directory))
call system('mkdir -p '.shellescape(a:directory))
endif
endfunction
" ========================================================================
" File type related settings
" ========================================================================
if has('autocmd')
augroup GeneralConfig
au FocusLost silent! :wa
au FileType helpfile setlocal nonumber
augroup END
augroup FileTypes
autocmd!
au BufRead,BufNewFile *.php setlocal filetype=php iskeyword-=$
au BufRead,BufNewFile *.twig setlocal filetype=jinja
au BufRead,BufNewFile *.html.twig setlocal filetype=htmljinja
au BufRead,BufNewFile *.js.twig setlocal filetype=javascript
au BufRead,BufNewFile *.ejs setlocal filetype=html
au BufRead,BufNewFile *.json setlocal filetype=javascript
au BufRead,BufNewFile *.pp setlocal filetype=ruby
augroup END
augroup TabsConfig
autocmd!
au BufRead,BufNewFile *.feature setlocal tabstop=2 shiftwidth=2 softtabstop=2
au BufRead,BufNewFile *.css setlocal tabstop=2 shiftwidth=2 softtabstop=2
au BufRead,BufNewFile *.scss setlocal tabstop=2 shiftwidth=2 softtabstop=2
au BufRead,BufNewFile *.less setlocal tabstop=2 shiftwidth=2 softtabstop=2
au BufRead,BufNewFile *.ruby setlocal tabstop=2 shiftwidth=2 softtabstop=2
au BufRead,BufNewFile *.js setlocal tabstop=2 shiftwidth=2 softtabstop=2
au BufRead,BufNewFile *.coffee setlocal tabstop=2 shiftwidth=2 softtabstop=2
au BufRead,BufNewFile vim setlocal tabstop=8 shiftwidth=2 softtabstop=2
au Filetype gitcommit setlocal spell textwidth=72
augroup END
" activate vim-hardtime
augroup HardTime
autocmd!
au BufRead,BufNewFile *.php,*.html,*.phtml HardTimeOn
augroup END
" reload vimrc automatically
augroup Vim
autocmd!
au bufwritepost .vimrc source %
au bufwritepost vimrc source %
augroup END
augroup Commands
autocmd!
au BufWrite *.php,*.js,*.feature,*.json :call <sid>StripTrailingWhitespaces()
au BufWrite * :call <sid>MkdirsIfNotExists(expand('<afile>:h'))
augroup END
endif