This repository has been archived by the owner on Mar 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvimrc
399 lines (331 loc) · 11.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
set nocompatible
let g:dotvim = fnamemodify($MYVIMRC, ':h')
let g:mapleader="\<Space>"
call plug#begin(g:dotvim.'/bundle')
let g:plug_window = 'tabnew'
Plug 'vheon/vim-colors-solarized'
Plug 'tpope/vim-commentary'
Plug 'tpope/vim-sensible'
Plug 'tpope/vim-fugitive'
Plug 'tpope/vim-surround'
Plug 'tpope/vim-sleuth'
Plug 'tpope/vim-repeat'
Plug 'tpope/vim-vinegar'
let g:netrw_altfile = 1
" XXX: do I relly need this plugin? I have to type the closing brackets anyway
" to jump them so why not type them to close them?
Plug 'vheon/delimitMate', { 'branch': 'fix-abbr-pumvisible', 'on': [] }
let g:delimitMate_expand_cr = 1
let g:delimitMate_expand_space = 1
let delimitMate_excluded_regions = 'Comment,String'
augroup load_delimitmate
autocmd!
autocmd! InsertEnter * call plug#load('delimitMate') | autocmd! load_delimitmate
augroup END
Plug 'tpope/vim-endwise'
let g:endwise_abbreviations = 1
let g:endwise_no_mappings = 1
Plug 'Valloric/ListToggle'
Plug 'tpope/vim-unimpaired'
Plug 'tpope/vim-abolish'
Plug 'tpope/vim-rsi'
" TextObj-User
Plug 'kana/vim-textobj-user'
Plug 'thinca/vim-textobj-function-javascript'
Plug 'kana/vim-textobj-function'
Plug 'kana/vim-textobj-help'
Plug 'machakann/vim-textobj-delimited'
Plug 'PeterRincker/vim-argumentative'
Plug 'bronson/vim-visual-star-search'
Plug 'tommcdo/vim-lion'
Plug 'tommcdo/vim-exchange'
Plug 'AndrewRadev/splitjoin.vim'
Plug 'AndrewRadev/inline_edit.vim'
Plug 'AndrewRadev/linediff.vim'
Plug 'Valloric/YouCompleteMe', { 'on': [], 'do': function('startup#YCMInstall') }
let g:ycm_confirm_extra_conf = 0
let g:ycm_complete_in_comments = 1
let g:ycm_global_ycm_extra_conf = g:dotvim.'/ycm.py'
let g:ycm_extra_conf_vim_data = ['&filetype']
let g:ycm_seed_identifiers_with_syntax = 1
augroup load_ycm
autocmd!
autocmd! InsertEnter * call plug#load('YouCompleteMe')
\| if exists('g:loaded_youcompleteme')
\| call youcompleteme#Enable()
\| endif
\| autocmd! load_ycm
augroup END
" XXX: take a deeper look a make a new one from scratch for YCM integration
Plug 'vheon/vimomni.vim'
let g:ycm_semantic_triggers = {
\ 'vim': ['re!let\s+', 're!call\s+'],
\ }
Plug 'tpope/vim-scriptease'
Plug 'tpope/vim-dispatch'
Plug 'adimit/prolog.vim'
Plug 'Valloric/MatchTagAlways'
" XXX: I should use something a little more generic. See gary bernhardt setup
" Plug 'thoughtbot/vim-rspec'
" let g:rspec_command = "!rspec --color {spec}"
" XXX: note to self for using eclim and putting it inside the plugged
" directory
" Plug g:plug_home.'/eclim'
Plug 'airblade/vim-gitgutter'
let g:gitgutter_sign_column_always = 1
nmap [h <Plug>GitGutterPrevHunk
nmap ]h <Plug>GitGutterNextHunk
Plug 'fatih/vim-go', { 'do': function('startup#GoBinsInstall')}
" XXX: consider to switch back to single plugin for the language that I use
Plug 'vheon/vim-polyglot'
let g:scala_use_default_keymappings = 0
let g:rubycomplete_buffer_loading = 1
let g:rubycomplete_rails = 1
Plug 'idbrii/vim-mark'
let g:mark_no_mappings = 1
nmap mw <Plug>MarkSet
xmap mw <Plug>MarkSet
call plug#end()
runtime! macros/matchit.vim
runtime plugin/sensible.vim
" In the standart runtime there's a filetype.vim that can handle file.m either
" as matlab file or as objc file if the file is not empty. On empty file it
" fallback to g:filetype_m if specified or 'matlab'
let g:filetype_m = 'objc'
" Set them in this order to avoid sourcing color/solarized.vim more than one
set t_Co=16
set background=dark
colorscheme solarized
set synmaxcol=512
hi! MarkWord1 ctermbg=6 ctermfg=Black
hi! MarkWord2 ctermbg=4 ctermfg=Black
hi! MarkWord3 ctermbg=2 ctermfg=Black
hi! MarkWord4 ctermbg=5 ctermfg=Black
hi! MarkWord5 ctermbg=3 ctermfg=Black
hi! MarkWord6 ctermbg=9 ctermfg=Black
set encoding=utf-8
set showmatch
set completeopt-=preview
set completeopt+=menuone
set pumheight=30
set cindent
set cinoptions=L0,g0,N-s,t0,(0
set shiftround
set timeoutlen=500
set updatetime=500
set lazyredraw
set smartcase
set ignorecase
if executable('ag')
set grepprg=ag\ --nogroup\ --column\ --smart-case\ --nocolor\ --follow
set grepformat=%f:%l:%c:%m
endif
" Cursor Mode
" XXX: should I extract it in a plugin?
" if !has('gui_running')
" let &statusline .= '%{CursorMode()}'
" else
" " Setup 'guicursor' with the same colors
" endif
"
" Change the color of the cursor based on the mode we're in.
" Idea stolen from http://www.blaenkdenum.com/posts/a-simpler-vim-statusline/
" He uses the 'guicursor' option which it's for GUI, MSDOW and Win32 console only
" but I use terminal vim on iTerm2 only at the moment so I send escape keys to
" iTerm2 to change the cursor color. The colors are in the form of '#rrggbb'
" because iTerm2 expect 'rrggbb', I put the '#' in there to prevent me to support
" eventually other terminal emulator that use 256 colors or 16 colors. I don't
" even know if it's a good idea.
let s:cursor_mode_color_map = {
\ "n": "#839496",
\ "i": "#268bd2",
\ "v": "#cb4b16",
\ "V": "#b58900",
\ "\<C-V>": "#6c71c4",
\ }
let s:last_mode = ''
let s:escape_template = '"%s\033]Pl%s\033\\"'
let s:escape_prefix = exists('$TMUX') ? '\033Ptmux;\033' : ''
function! CursorMode()
let mode = mode()
if mode !=# s:last_mode
let s:last_mode = mode
if has_key(s:cursor_mode_color_map, mode)
let color = substitute(s:cursor_mode_color_map[mode], '^#', '', '')
let escape = printf(s:escape_template, s:escape_prefix, color)
let command = printf('printf %s > /dev/tty', escape)
" Sometime the call to system takes long enough to let vim fire some
" autocmd, like the one mentioned in `:h last-position-jump` so we save
" the view and restore it later, but it doesn't work always anyway :(
let view = winsaveview()
call system(command)
call winrestview(view)
endif
endif
return ''
endfunction
let &statusline = ''
let &statusline .= '%h%w '
let &statusline .= '%<%f '
let &statusline .= '%{fugitive#statusline()}'
let &statusline .= '%-4(%m%r%)'
let &statusline .= '%='
let &statusline .= '%y '
let &statusline .= '%-14(%P %3l:%02c%)'
let &statusline .= '[%{strlen(&l:fenc) ? &enc : &l:fenc}]'
let &statusline .= has('gui_running') ? '' : '%{CursorMode()}'
set cmdheight=2
set noshowmode
set wildmode=list:longest
set wildignore+=.hg,.git,.svn
set wildignore+=*.o,*.obj,*~
set wildignore+=*.DS_Store
set wildignore+=*.png,*.jpg,*.jpeg,*.gif
set wildignore+=*.mkv,*.avi
set wildignore+=*.pyc
set wildignore+=*.class
set nomore
set noautochdir
set hidden
set cursorline
set colorcolumn=81
set viminfo=!,'10,<50,s20,h
set nostartofline
set noerrorbells
set novisualbell
set t_vb=
" Prevent Vim from clobbering the scroll back buffer. See
" http://www.shallowsky.com/linux/noaltscreen.html
set t_ti= t_te=
set noswapfile
set nobackup
set nowritebackup
if v:version + has('patch541') >= 704
set formatoptions+=j
endif
set formatoptions-=oa
set nofoldenable
set foldlevelstart=99
set foldminlines=5
set foldmethod=manual
set list
let &listchars = "tab:\u21e5 ,trail:\u2423,extends:\u21c9,precedes:\u21c7,nbsp:\u26ad"
let &showbreak = "\u21aa "
if has('mouse')
set mouse=a
endif
" Sudo write
command! W exec 'w !sudo tee % > /dev/null' | e!
command! -nargs=0 StripWhitespace call functions#StripWhitespace()
command! -nargs=0 FollowSymlink call functions#FollowSymlink()
command! -nargs=* Stab call functions#Stab(<f-args>)
command! -nargs=0 Rename call functions#Rename()
command! -bar -nargs=* Scratch call functions#ScratchEdit(<q-args>)
" this is for stop profiling after starting vim with
" vi --cmd 'profile start vimrc.profile' --cmd 'profile func *' --cmd 'profile file *'
" I have a script in ~/bin which start vim like this
command! -nargs=0 StopProfiling call profile#stop()
" If I want to profile something after that vim started
command! -nargs=0 StartProfiling call profile#start()
" more consistent with other operator
nnoremap Y y$
" possible mnemonic? let say is for YELL
inoremap <C-y> <esc>gUiw`]a
" Practical Vim tip #34
cnoremap <C-n> <Down>
cnoremap <C-p> <Up>
" copy the first range address and add + or -
function! s:command_replicate_address(lhs, direction)
let match = matchstr(getcmdline(), '^.\{-1,}\ze,$')
return match == '' ? a:lhs : match.a:direction
endfunction
cnoremap > <C-R>=<SID>command_replicate_address(">", "+")<Cr>
cnoremap < <C-R>=<SID>command_replicate_address("<", "-")<Cr>
cnoremap <C-X>> >
cnoremap <C-X>< <
nnoremap <silent> <leader>ev :e $MYVIMRC<CR>
nnoremap <silent> <leader>ez :e ~/.zshrc<CR>
nnoremap <silent> <leader>et
\ :call selecta#command("files -a -A ~/.cache/vtests", "", ":e")<cr>
" http://vimcasts.org/episodes/the-edit-command
" https://twitter.com/garybernhardt/status/40292706609532928
cnoremap %% <C-R>=expand('%:h').'/'<CR>
nmap <leader>e. :edit %%
nmap <leader>v. :view %%
nnoremap <C-n> :set invnumber<cr>
nnoremap <silent> <Leader>* :let @/ = '\<'.expand('<cword>').'\>' <Bar> set hlsearch<cr>
" Since the * is on the 8 symbol and is used to search for the word under the
" cursor, seems reasonable
nnoremap <silent> <Leader>8 :set hlsearch<cr>
" XXX: see if is necessary now that I don't start with nohlsearch
" cnoremap <silent> <expr> <cr>
" \ getcmdtype() =~ '[/?]' ? '<cr>:nohlsearch<cr>' : '<cr>'
" Make selecting inside an HTML tag better
xnoremap <silent> it itVkoj
xnoremap <silent> at atV
" CTRL-U and CTRL-W in insert mode cannot be undone. Use CTRL-G u to first
" break undo, so that we can undo those changes after inserting a line break.
" For more info, see: http://vim.wikia.com/wiki/Recover_from_accidental_Ctrl-U
inoremap <C-u> <C-g>u<C-u>
inoremap <C-w> <C-g>u<C-w>
nnoremap <silent> <Leader>s
\ :call selecta#command("files -A", "", ":e")<cr>
nnoremap <silent> <Leader>g
\ :call selecta#command("files -A", "-s ".expand('<cword>'), ":e")<cr>
" ##########
" Autocmd(s)
" ##########
augroup no_cursor_line_in_insert_mode
autocmd!
autocmd BufEnter,WinEnter,InsertLeave * set cursorline
autocmd BufLeave,WinLeave,InsertEnter * set nocursorline
augroup END
augroup last_position_jump
autocmd!
autocmd BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$")
\| execute 'normal! g`"zvzz'
\| endif
augroup END
" Every ftplugin in macvim runtime file override this
augroup remove_formatoptions_o
autocmd!
autocmd FileType * setlocal formatoptions-=o
augroup END
" for profiling
augroup profiling_vimrc
autocmd!
autocmd BufReadPost vim.profile setl ft=vim nolist
augroup END
augroup lcd_to_git_root_or_restore_last_set
autocmd!
autocmd BufLeave * let b:last_cwd = getcwd()
autocmd BufEnter * if exists('b:last_cwd')
\| execute 'lcd' b:last_cwd
\| else
\| try
\| execute 'lcd' '`=fugitive#repo().tree()`'
\| catch
\| endtry
\| endif
augroup END
" When switching colorscheme in terminal vim change the profile in iTerm as well.
if !has('gui_running')
let s:iterm2_profile = 'printf "\033]50;SetProfile=%s\x7" > /dev/tty'
augroup change_iterm2_profile
autocmd!
autocmd VimEnter,ColorScheme * if g:colors_name == "solarized"
\| call system(printf(s:iterm2_profile, 'solarized_'.&background))
\| else
\| call system(printf(s:iterm2_profile, g:colors_name))
\| endif
augroup END
endif
" XXX:
augroup temporary_prolog_settings
autocmd!
autocmd BufNewFile,BufRead *.pl setlocal filetype=prolog
autocmd Filetype prolog setl et sts=8 ts=8 sw=8
autocmd Filetype prolog let b:start = 'swipl %' | let b:dispatch = b:start
autocmd Filetype prolog nnoremap <buffer> <CR> :w<Bar>:Start<cr>
augroup END
" Just so I don't lose them xD ᕕ( ᐛ )ᕗ ¯\_(ツ)_/¯