-
Notifications
You must be signed in to change notification settings - Fork 9
/
vimrc
368 lines (300 loc) · 14.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
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
" ----------------------------------------------------------------------------
" .vimrc {{{
" ----------------------------------------------------------------------------
" Allow vim to break compatibility with vi
set nocompatible " This must be first, because it changes other options
" }}}-------------------------------------------------------------------------
" Plugin {{{
" ----------------------------------------------------------------------------
" Installing the Plug plugin manager, and all the plugins are included in this
" other file.
source $HOME/.vim/plug.vim
" }}}-------------------------------------------------------------------------
" Base Options {{{
" ----------------------------------------------------------------------------
" Set the leader key to <space> instead of \ because it's easier to reach
let mapleader = "\<Space>"
"set notimeout " Turn off the timeout for the leader key
" Seems to break `n` in normal mode, so
" I turned it off
set encoding=utf-8 " I generally want utf-8 encoding
set spell " Turn on spelling
set spelllang=en_us " Set the spelling language
" Set my personal spelling file
set spellfile=$HOME/.vim/spell/en.utf-8.add
set nohidden " Don't allow buffers to exist in the background
set ttyfast " Indicates a fast terminal connection
set backspace=indent,eol,start " Allow backspaceing over autoindent, line breaks, starts of insert
set backupcopy=yes " Fixes some node watching tools: http://stackoverflow.com/a/35583907/1263117
set shortmess+=I " No welcome screen
set shortmess+=A " No .swp warning
set history=200 " Remember the last 200 :ex commands
set secure " disable unsafe commands in local .vimrc files
" }}}-------------------------------------------------------------------------
" Visual {{{
" ----------------------------------------------------------------------------
" Control Area (May be superseded by vim-airline)
set showcmd " Show (partial) command in the last line of the screen.
set wildmenu " Command completion
set wildmode=list:longest " List all matches and complete till longest common string
set laststatus=2 " The last window will have a status line always
set noshowmode " Don't show the mode in the last line of the screen, vim-airline takes care of it
set ruler " Show the line and column number of the cursor position, separated by a comma.
set lazyredraw " Don't update the screen while executing macros/commands
" My command line autocomplete is case insensitive. Keep vim consistent with
" that. It's a recent feature to vim, test to make sure it's supported first.
if exists("&wildignorecase")
set wildignorecase
endif
" Buffer Area Visuals
set scrolloff=7 " Minimal number of screen lines to keep above and below the cursor.
set visualbell " Use a visual bell, don't beep!
set cursorline " Highlight the current line
set number " Show line numbers
set wrap " Soft wrap at the window width
set linebreak " Break the line on words
set textwidth=79 " Break lines at just under 80 characters
if exists('+colorcolumn')
set colorcolumn=+1 " Highlight the column after `textwidth`
endif
set numberwidth=4 " Width of the line number column
" show fold column, fold by markers
set foldcolumn=0 " Don't show the folding gutter/column
set foldmethod=marker " Fold on {{{ }}}
set foldlevelstart=20 " Open 20 levels of folding when I open a file
" Open folds under the following conditions
set foldopen=block,hor,mark,percent,quickfix,search,tag,undo,jump
" Highlight tabs and trailing spaces
set listchars=tab:▸\ ,trail:•
set list " Make whitespace characters visible
" Splits
set splitbelow " Open new splits below
set splitright " Open new vertical splits to the right
" Function to trim trailing white space
" Make your own mappings
function! StripTrailingWhitespaces()
let l = line(".")
let c = col(".")
%s/\s\+$//e
call cursor(l, c)
endfun
" Character meaning when present in 'formatoptions'
" ------ ---------------------------------------
" c Auto-wrap comments using textwidth, inserting the current comment leader automatically.
" q Allow formatting of comments with "gq".
" r Automatically insert the current comment leader after hitting <Enter> in Insert mode.
" t Auto-wrap text using textwidth (does not apply to comments)
" n Recognize numbered lists
" 1 Don't break line after one-letter words
" a Automatically format paragraphs
set formatoptions=cqrn1
" Colors
syntax enable " This has to come after colorcolumn in order to draw it.
set t_Co=256 " enable 256 colors
colorscheme spacegray
let g:airline_theme='zenburn'
" When completing, fill with the longest common string
" Auto select the first option
set completeopt=longest,menuone
" Printing options
set printoptions=header:0,duplex:long,paper:letter,syntax:n
" header:0 Do not print a header
" duplex:long (default) Print on both sides (when possible), bind on long
" syntax:n Do not use syntax highlighting.
" }}}-------------------------------------------------------------------------
" Style for terminal vim
" ----------------------------------------------------------------------------
" Don't show the airline separators
" The angle bracket defaults look fugly
let g:airline_left_sep=' '
let g:airline_right_sep=' '
let g:airline_powerline_fonts=0
set mouse+=a " Add mouse support for 'all' modes, may require iTerm
if &term =~ '^screen'
" tmux knows the extended mouse mode
set ttymouse=xterm2
endif
" }}}-------------------------------------------------------------------------
" Search {{{
" ----------------------------------------------------------------------------
set incsearch " Show search results as we type
set showmatch " Show matching brackets
set hlsearch " Highlight search results
" Use regex for searches
nnoremap / /\v
vnoremap / /\v
nnoremap ? ?\v
vnoremap ? ?\v
set ignorecase " Ignore case when searching
set smartcase " Don't ignore case if we have a capital letter
" }}}-------------------------------------------------------------------------
" Tabs {{{
" ----------------------------------------------------------------------------
set tabstop=4 " Show a tab as four spaces
set shiftwidth=4 " Reindent is also four spaces
set softtabstop=4 " When hit <tab> use four columns
set expandtab " Create spaces when I type <tab>
set shiftround " Round indent to multiple of 'shiftwidth'.
set autoindent " Put my cursor in the right place when I start a new line
filetype plugin indent on " Rely on file plugins to handle indenting
" }}}-------------------------------------------------------------------------
" Custom commands {{{
" ----------------------------------------------------------------------------
" Edit the vimrc file
nmap <silent> <Leader>ev :vsplit $MYVIMRC<CR>
nmap <silent> <Leader>ez :vsplit $HOME/.zshrc<CR>
nmap <silent> <Leader>ep :vsplit $HOME/.vim/plug.vim<CR>
nmap <silent> <Leader>es :vsplit $HOME/.ssh/config<CR>
nmap <silent> <Leader>et :vsplit $HOME/.tmux.conf<CR>
nmap <silent> <Leader>sv :source $MYVIMRC<CR>
nmap <silent> <Leader>sp :source $HOME/.vim/plug.vim<CR>
" Faster save/quite/close
nmap <silent> <Leader>w :update<CR>
nmap <silent> <Leader>q :quit<CR>
nmap <silent> <Leader>c :bdelete<CR>
nmap <silent> <Leader>n :cnext<CR>
nmap <silent> <Leader>p :cprevious<CR>
" Trim trailing white space
nmap <silent> <Leader>t :call StripTrailingWhitespaces()<CR>
" Cd to the current file's directory
nnoremap <Leader>. :cd %:p:h<CR>:pwd<CR>
" Move current window to the far left using full height
nmap <silent> <Leader>h <C-w>H
" Move current window to the far right using full height
nmap <silent> <Leader>l <C-w>L
" Move current window to the top using full width
nmap <silent> <Leader>k <C-w>K
" Move current window to the bottom using full width
nmap <silent> <Leader>j <C-w>J
nmap <silent> <Leader>d :YcmCompleter GoToDefinition<CR>
" Clear search highlights
nnoremap <leader><space> :nohlsearch<cr>
nnoremap <leader>pp :%!python -m json.tool<cr>
" }}}-------------------------------------------------------------------------
" Configure My Plugins {{{
" ----------------------------------------------------------------------------
" Jump thought errors with :lnext and :lprev
let g:syntastic_always_populate_loc_list = 1
"let g:syntastic_auto_loc_list = 1
let g:syntastic_check_on_open = 1
let g:syntastic_check_on_wq = 0
" Return to last edit position when opening files, except git commit message
autocmd BufReadPost *
\ if &ft != 'gitcommit' && line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal g`\"" |
\ endif
" Gist Vim
let g:gist_clip_command = 'pbcopy'
let g:gist_detect_filetype = 1
let g:gist_open_browser_after_post = 1
" Ctrl-P
let g:ctrlp_working_path_mode = 'rw'
let g:ctrlp_custom_ignore = {
\ 'dir': '\v[\/]\.(git|hg|svn|sass-cache|pip_download_cache|wheel_cache)$',
\ 'file': '\v\.(png|jpg|jpeg|gif|DS_Store|pyc)$',
\ 'link': '',
\ }
let g:ctrlp_show_hidden = 1
let g:ctrlp_clear_cache_on_exit = 0
" Wait to update results (This should fix the fact that backspace is so slow)
let g:ctrlp_lazy_update = 1
" Show as many results as our screen will allow
let g:ctrlp_match_window = 'max:1000'
" CtrlP like mapings for opening quick fixes in new splits
let g:qfenter_vopen_map = ['<C-v>']
let g:qfenter_hopen_map = ['<C-CR>', '<C-s>', '<C-x>']
let g:qfenter_topen_map = ['<C-t>']
" If we have The Silver Searcher
if executable('ag')
" Use ag over grep
set grepprg=ag\ --nogroup\ --nocolor
" Use ag in CtrlP for listing files. Lightning fast and respects .gitignore
let g:ctrlp_user_command = 'ag %s --files-with-matches -g "" --hidden --ignore "\.git$\|\.hg$\|\.svn|\.pyc$"'
" ag is fast enough that CtrlP doesn't need to cache
let g:ctrlp_use_caching = 0
endif
" Undotree plugin.
nnoremap <F5> :UndotreeToggle<CR>
" Jedi Python Autocomplete
let g:jedi#use_tabs_not_buffers = 0 " Jedi needs you to unset this default to get to splits
let g:jedi#use_splits_not_buffers = "bottom"
" }}}-------------------------------------------------------------------------
" Custom filetypes {{{
" ----------------------------------------------------------------------------
" Auto detect filetype
autocmd BufRead,BufNewFile *.md,*.markdown set filetype=markdown
autocmd BufRead,BufNewFile *.lytex set filetype=tex
autocmd BufRead,BufNewFile ~/dotfiles/ssh/config set filetype=sshconfig
autocmd BufRead,BufNewFile *.git/config,.gitconfig,.gitmodules,gitconfig set ft=gitconfig
autocmd BufNewFile,BufRead *.html set filetype=htmldjango
autocmd BufNewFile,BufRead .eslintrc set filetype=javascript
autocmd BufNewFile,BufRead *.es6 set filetype=javascript
autocmd BufRead,BufNewFile *.py setlocal foldmethod=indent
" Override what is done in /vim/bundle/scss-syntax.vim/ftdetect/scss.vim
" This should prevent duplicate snippets
autocmd BufRead,BufNewFile *.scss set filetype=scss
" }}}-------------------------------------------------------------------------
" Custom mappings {{{
" ----------------------------------------------------------------------------
" When pasting, refill the default register with what you just pasted
xnoremap p pgvy
" Repurpose arrow keys to navigating windows
nnoremap <left> <C-w>h
nnoremap <right> <C-w>l
nnoremap <up> <C-w>k
nnoremap <down> <C-w>j
inoremap <up> <nop>
inoremap <down> <nop>
inoremap <left> <nop>
inoremap <right> <nop>
" To encourage the use of <C-[np]> instead of the arrow keys in ex mode, remap
" them to use <Up/Down> instead so that they will filter completions
cnoremap <C-p> <Up>
cnoremap <C-n> <Down>
" Navigate using displayed lines not actual lines
nnoremap j gj
nnoremap k gk
" Make Y consistent with D
nnoremap Y y$
" Reselect visual block after indent/outdent: http://vimbits.com/bits/20
vnoremap < <gv
vnoremap > >gv
vnoremap = =gv
" Allow saving of files as sudo when I forgot to start vim using sudo.
" Seems to have a problem where Vim sees that the file has changed and tries to
" reload it. When it does it thinks the file is blank (but it's not really).
cmap w!! %!sudo tee > /dev/null %
" Do what my fat fingers mean!
command! Bd bd
command! BD bd
command! Q q
command! W w
command! Cn cn
command! Cp cp
" Nobody ever uses "Ex" mode, and it's annoying to leave
noremap Q <nop>
" }}}-------------------------------------------------------------------------
" Undo, Backup and Swap file locations {{{
" ----------------------------------------------------------------------------
" Don't leave .swp files everywhere. Put them in a central place
set directory=$HOME/.vim/swapdir//
set backupdir=$HOME/.vim/backupdir//
if exists('+undodir')
set undodir=$HOME/.vim/undodir
set undofile
endif
" }}}-------------------------------------------------------------------------
" If there is a per-machine local .vimrc, source it here at the end {{{
" ----------------------------------------------------------------------------
if filereadable(glob("$HOME/.vimrc.local"))
source $HOME/.vimrc.local
endif
" }}}-------------------------------------------------------------------------
" {{{
" ----------------------------------------------------------------------------
let g:jekyll_post_extension = '.md'
command! Py :!python %
command! O :!open %
let g:ag_working_path_mode="r"
set exrc
set secure