this repo has no description
1packadd chezmoi.vim
2runtime macros/matchit.vim " Enable matchit for textobj-rubyblock
3let g:polyglot_disabled = ['autoindent']
4execute pathogen#infect()
5
6set nocompatible " We're running Vim, not Vi!
7set laststatus=2 " Always show status at window bottom
8set encoding=utf-8 " Use UTF-8 internally, not latin1
9set wildmode=longest,list " Bash-like tab completion for ex
10set history=10000 " Remember many ex commands
11set noswapfile " No swap files, no swap file warnings
12set scrolloff=3 " Keep a few lines visible around cursor
13set showmatch " Flash matching brackets and parens
14set nrformats= " Zero-lead numbers are decimal, not octal
15set showcmd " Show partial commands
16set noshowmode " Don't show default normal/insert message
17set shm+=I " Don't show intro message
18set number " Turn on line numbers
19set winheight=5
20set winminheight=5 " Never shrink splits below 5 lines
21set winheight=30 " Try for 30 line splits on focus
22set winwidth=15
23set winminwidth=15 " Never shrink splits below 15 columns
24set winwidth=80 " Try for 80 column splits on focus
25set wildignore+=*/tmp/*,*.so,*.swp,*.zip " Ignore un-editable files
26set nomodeline " Don't try to execute the entire file looking for modes
27
28set backupdir=~/.vim/backup// " Backup files in case of crashes
29set directory=~/.vim/swap// " Swap files for saving atomically
30
31set undofile " Save undo history across close/open
32set undodir=~/.vim/undo// " Where to save undo histories
33set undolevels=1000 " How many undos
34set undoreload=10000 " Number of lines to save for undo
35
36syntax on " Enable syntax highlighting
37filetype on " Enable filetype detection
38filetype indent on " Enable filetype-specific indenting
39filetype plugin on " Enable filetype-specific plugins
40
41
42""""""""""""""""
43" COLOR SCHEME "
44""""""""""""""""
45set background=dark
46
47if &background == "light"
48 " airline can't autodetect
49 let g:airline_solarized_bg = 'light'
50 " solarized doesn't detect gutter color
51 highlight LineNr ctermfg=grey ctermbg=white
52else
53 " highlight LineNr ctermfg=10 ctermbg=0
54 " highlight LineNr ctermfg=10
55endif
56
57if has("gui_running")
58 set gcr=a:blinkon0 " Stop blinking the cursor ahhhhh
59 set guifont=MenloNF-Regular:h14
60 colorscheme made-of-code
61else
62 let g:solarized_termtrans = 1
63 colorscheme solarized
64
65 " Change cursor shape in different modes
66 let &t_EI = "\033[2 q" " NORMAL █
67 let &t_SI = "\033[5 q" " INSERT |
68 let &t_SR = "\033[3 q" " REPLACE _
69endif
70
71if $COLORTERM ==# 'truecolor'
72 set termguicolors
73
74 " Work around forced background color erase
75 let &t_ut=''
76
77 " Correct RGB escape codes for vim inside tmux
78 if !has('nvim') && $TERM ==# 'screen-256color'
79 let &t_8f = "\<Esc>[38;2;%lu;%lu;%lum"
80 let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum"
81 endif
82
83 colorscheme made-of-code
84
85 " Light grey on dark grey line number gutter
86 highlight LineNr ctermbg=16 ctermfg=10
87endif
88
89let g:airline#extensions#tabline#enabled = 1
90let g:airline_powerline_fonts = 1
91let g:airline_theme = 'powerlineish'
92
93let g:netrw_dirhistmax = 0
94let g:commentary_map_backslash = 0
95
96let mapleader = " "
97let maplocalleader = " "
98" nnoremap <Space> :
99
100" Leave insert mode on jk
101inoremap jk <Esc>
102
103" mapping to make movements operate on 1 screen line in wrap mode
104function! ScreenMovement(movement)
105 if &wrap
106 return "g" . a:movement
107 else
108 return a:movement
109 endif
110endfunction
111onoremap <silent> <expr> j ScreenMovement("j")
112onoremap <silent> <expr> k ScreenMovement("k")
113onoremap <silent> <expr> 0 ScreenMovement("0")
114onoremap <silent> <expr> ^ ScreenMovement("^")
115onoremap <silent> <expr> $ ScreenMovement("$")
116nnoremap <silent> <expr> j ScreenMovement("j")
117nnoremap <silent> <expr> k ScreenMovement("k")
118nnoremap <silent> <expr> 0 ScreenMovement("0")
119nnoremap <silent> <expr> ^ ScreenMovement("^")
120nnoremap <silent> <expr> $ ScreenMovement("$")
121
122" Save on Return, but not inside quickfix windows
123nnoremap <CR> :w<CR>
124augroup allow_cr_in_quickfix
125 autocmd!
126 autocmd BufReadPost quickfix nnoremap <buffer> <CR> <CR>
127augroup END
128
129" Remove search highlight and redraw screen on ^L
130" nnoremap <C-l> :<C-u>nohlsearch<CR><C-l>
131
132nnoremap <Leader>ve :e $MYVIMRC<CR>
133augroup reload_vimrc
134 autocmd!
135 autocmd BufWritePost $MYVIMRC source $MYVIMRC
136 autocmd BufWritePost $MYVIMRC AirlineRefresh
137augroup END
138
139" Force all .md files to be markdown, not modula2
140augroup markdown_filetype
141 autocmd!
142 autocmd BufNewFile,BufReadPost *.md set filetype=markdown
143augroup END
144
145" <Leader>p to paste from the OS X clipboard without paste indent
146nnoremap <Leader>p :read!pbpaste<CR>
147
148" ,r to execute the current buffer as ruby, but only if unmapped
149function! RubyScratch()
150 if &filetype ==# ""
151 :set filetype=ruby
152 :setlocal ts=2 sts=2 sw=2
153 endif
154 :write !ruby --no-color
155endfunction
156if &filetype ==# ""
157 nnoremap <Leader>r :call RubyScratch()<CR>
158 " nnoremap <Leader>r :set filetype=ruby <bar> :setlocal ts=2 sts=2 sw=2 <bar> :write !ruby<CR>
159endif
160
161" <Leader><Leader> to jump to the last edited file
162nnoremap <Leader><Leader> <C-^>
163
164" select previous paste with gV
165noremap gV `[v`]
166
167let g:ctrlp_use_caching = 0
168" let g:ctrlp_user_command = 'ag %s -l --nocolor --hidden -g ""'
169let g:ctrlp_prompt_mappings = {
170 \ 'AcceptSelection("e")': ['<c-t>'],
171 \ 'AcceptSelection("t")': ['<cr>', '<2-LeftMouse>'],
172 \ }
173
174let g:path_to_matcher = expand('<sfile>:p:h') . "/.bin/matcher"
175
176let g:ctrlp_user_command = ['.git/', 'cd %s && git ls-files . -co --exclude-standard']
177
178let g:ctrlp_match_func = { 'match': 'GoodMatch' }
179
180function! GoodMatch(items, str, limit, mmode, ispath, crfile, regex)
181
182 " Create a cache file if not yet exists
183 let cachefile = ctrlp#utils#cachedir().'/matcher.cache'
184 if !( filereadable(cachefile) && a:items == readfile(cachefile) )
185 call writefile(a:items, cachefile)
186 endif
187 if !filereadable(cachefile)
188 return []
189 endif
190
191 " a:mmode is currently ignored. In the future, we should probably do
192 " something about that. the matcher behaves like "full-line".
193 let cmd = g:path_to_matcher.' --limit '.a:limit.' --manifest '.cachefile.' '
194 if !( exists('g:ctrlp_dotfiles') && g:ctrlp_dotfiles )
195 let cmd = cmd.'--no-dotfiles '
196 endif
197 let cmd = cmd.a:str
198
199 return split(system(cmd), "\n")
200
201endfunction
202
203" Start interactive EasyAlign in visual mode (e.g. vip<Enter>)
204vmap <Enter> <Plug>(EasyAlign)
205
206" Start interactive EasyAlign for a motion/text object (e.g. gaip)
207nmap ga <Plug>(EasyAlign)
208
209cmap %% <C-R>=expand("%")<CR>
210" In visual mode, "." will, for each line, go into normal mode and execute the "."
211
212" ===== Seeing Is Believing =====
213" Assumes you have a Ruby with SiB available in the PATH
214" If it doesn't work, you may need to `gem install seeing_is_believing`
215
216" function! WithoutChangingCursor(fn)
217" let cursor_pos = getpos('.')
218" let wintop_pos = getpos('w0')
219" let old_lazyredraw = &lazyredraw
220" let old_scrolloff = &scrolloff
221" set lazyredraw
222
223" call a:fn()
224
225" call setpos('.', wintop_pos)
226" call setpos('.', cursor_pos)
227" redraw
228" let &lazyredraw = old_lazyredraw
229" let scrolloff = old_scrolloff
230" endfun
231
232" function! SibAnnotateAll(scope)
233" call WithoutChangingCursor(function('execute', [a:scope . "!seeing_is_believing --timeout 12 --line-length 500 --number-of-captures 300 --alignment-strategy chunk"]))
234" endfun
235
236" function! SibAnnotateMarked(scope)
237" call WithoutChangingCursor(function('execute', [a:scope . "!seeing_is_believing --xmpfilter-style --timeout 12 --line-length 500 --number-of-captures 300 --alignment-strategy chunk"]))
238" endfun
239
240" function! SibCleanAnnotations(scope)
241" call WithoutChangingCursor(function('execute', [a:scope . "!seeing_is_believing --clean"]))
242" endfun
243
244" function! SibToggleMark()
245" let pos = getpos('.')
246" let line = getline(".")
247" if line =~ '^\s*$'
248" let line = '# => '
249" elseif line =~ '# =>'
250" let line = substitute(line, ' *# =>.*', '', '')
251" else
252" let line .= ' # => '
253" end
254" call setline('.', line)
255" call setpos('.', pos)
256" endfun
257
258" Enable seeing-is-believing mappings only for Ruby
259" augroup seeingIsBelievingSettings
260 " clear the settings if they already exist (so we don't run them twice)
261 " autocmd!
262 " autocmd FileType ruby nmap <buffer> <Leader>b :call SibAnnotateAll("%")<CR>;
263 " autocmd FileType ruby nmap <buffer> <Leader>n :call SibAnnotateMarked("%")<CR>;
264 " autocmd FileType ruby nmap <buffer> <Leader>v :call SibCleanAnnotations("%")<CR>;
265 " autocmd FileType ruby nmap <buffer> <S-Enter> :call SibToggleMark()<CR>;
266
267 " autocmd FileType ruby vmap <buffer> <S-Enter> :call SibToggleMark()<CR>;
268 " autocmd FileType ruby vmap <buffer> <Leader>b :call SibAnnotateAll("'<,'>")<CR>;
269 " autocmd FileType ruby vmap <buffer> <Leader>n :call SibAnnotateMarked("'<,'>")<CR>;
270 " autocmd FileType ruby vmap <buffer> <Leader>v :call SibCleanAnnotations("'<,'>")<CR>;
271" augroup END
272
273""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
274" OPEN FILES IN DIRECTORY OF CURRENT FILE
275""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
276map <leader>e :edit %%
277map <leader>v :view %%
278
279" Replace %/ with directory of current file (eg `:vs %/`)
280cmap %/ <C-R>=expand("%:p:h")."/"<CR>
281" Replace %% with current file (eg `:vs %%`)
282vnoremap . :norm.<CR>
283" Current file without extension
284cnoremap %$ <C-R>=expand('%:t')<cr>
285
286" Highlight colors in CSS files
287let g:colorizer_auto_filetype='css,scss,sass'
288
289" Save buffers on swap or unfocus
290augroup save_on_unfocus
291 autocmd!
292 autocmd BufLeave,FocusLost * silent! wall
293augroup END
294
295" Strip trailing whitespace on save
296fun! <SID>StripTrailingWhitespaces()
297 let l = line(".")
298 let c = col(".")
299 %s/\s\+$//e
300 call cursor(l, c)
301endfun
302
303augroup strip_whitespace_on_save
304 autocmd!
305 autocmd FileType c,cpp,css,ruby,python,json,javascript,css,scss,html,haml,erb,bash,vim autocmd BufWritePre <buffer> :call <SID>StripTrailingWhitespaces()
306 " or strip on save for any kind of file:
307 " autocmd BufWritePre * :call <SID>StripTrailingWhitespaces()
308augroup END
309
310" Open all folds on file open
311"autocmd FileType * exe "normal zR"
312
313" Open the current file in Marked 2
314nnoremap <leader>m :silent !open -a Marked\ 2.app '%:p'<cr>
315
316" Search for selected text.
317" http://vim.wikia.com/wiki/VimTip171
318let s:save_cpo = &cpo | set cpo&vim
319if !exists('g:VeryLiteral')
320 let g:VeryLiteral = 0
321endif
322function! s:VSetSearch(cmd)
323 let old_reg = getreg('"')
324 let old_regtype = getregtype('"')
325 normal! gvy
326 if @@ =~? '^[0-9a-z,_]*$' || @@ =~? '^[0-9a-z ,_]*$' && g:VeryLiteral
327 let @/ = @@
328 else
329 let pat = escape(@@, a:cmd.'\')
330 if g:VeryLiteral
331 let pat = substitute(pat, '\n', '\\n', 'g')
332 else
333 let pat = substitute(pat, '^\_s\+', '\\s\\+', '')
334 let pat = substitute(pat, '\_s\+$', '\\s\\*', '')
335 let pat = substitute(pat, '\_s\+', '\\_s\\+', 'g')
336 endif
337 let @/ = '\V'.pat
338 endif
339 normal! gV
340 call setreg('"', old_reg, old_regtype)
341endfunction
342vnoremap <silent> * :<C-U>call <SID>VSetSearch('/')<CR>/<C-R>/<CR>
343vnoremap <silent> # :<C-U>call <SID>VSetSearch('?')<CR>?<C-R>/<CR>
344vmap <kMultiply> *
345nmap <silent> <Plug>VLToggle :let g:VeryLiteral = !g:VeryLiteral
346 \\| echo "VeryLiteral " . (g:VeryLiteral ? "On" : "Off")<CR>
347if !hasmapto("<Plug>VLToggle")
348 nmap <unique> <Leader>vl <Plug>VLToggle
349endif
350let &cpo = s:save_cpo | unlet s:save_cpo
351
352" Generate documentation tags automatically
353silent! helptags ALL
354
355" Enable handlebars shortcuts
356let g:mustache_abbreviations = 1
357" Disable handlebars text objects (ie and ae conflict with vim-textobj-entire)
358let g:mustache_operators = 0
359
360" store all project tags in a global directory instead of per-project
361let g:gutentags_cache_dir = expand('<sfile>:p:h') . "/.vim/tags/"
362
363" set all .jsx files to be both JS and JSX
364autocmd BufNewFile,BufRead *.jsx set filetype=javascript.jsx
365
366" set all .jjdescription files to be JJ commit messages
367autocmd BufNewFile,BufRead *.jjdescription set filetype=jjdescription
368
369inoremap <M-o> <Esc>o
370inoremap <C-j> <Down>
371let g:ragtag_global_maps = 1
372
373" Start interactive EasyAlign in visual mode (e.g. vipga)
374xmap ga <Plug>(EasyAlign)
375" Start interactive EasyAlign for a motion/text object (e.g. gaip)
376nmap ga <Plug>(EasyAlign)
377
378nmap <leader>d :Dispatch
379
380" Use FZF instead of CtrlP
381nmap <C-P> :FZF<CR>
382nmap <C-Y> :Buffers<CR>
383
384nmap <leader>f :ALEFix<CR>