forked from keith/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vimrc
407 lines (333 loc) · 12.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
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
"
" Keith Smiley's (http://keith.so) vimrc, do with what you will
"
"
" This must be first, because it changes other options
if &compatible
set nocompatible
endif
" Source files before plugins
source ~/.vim/before/*.vim
" Plugin setup
filetype off
execute pathogen#infect()
filetype plugin indent on " Re-enable after setup
syntax enable " Enable vim syntax highlighting as is (enable != on)
" Use space as leader!
let g:mapleader="\<Space>"
" I - Disable the startup message
" a - Avoid pressing enter after saves
set shortmess=Ia
set shell=$SHELL " Set the default shell
set termencoding=utf-8 " Set the default encodings just in case $LANG isn't set
set encoding=utf-8 " Set the default encodings just in case $LANG isn't set
set autoindent " Indent the next line matching the previous line
set smartindent " Smart auto-indent when creating a new line
set tabstop=2 " Number of spaces each tab counts for
set shiftwidth=2 " The space << and >> moves the lines
set softtabstop=2 " Number of spaces for some tab operations
set shiftround " Round << and >> to multiples of shiftwidth
set expandtab " Insert spaces instead of actual tabs
set smarttab " Delete entire shiftwidth of tabs when they're inserted
set history=1000 " The number of history items to remember
set backspace=indent,eol,start " Backspace settings
set nostartofline " Keep cursor in the same place after saves
set showcmd " Show command information on the right side of the command line
set isfname-== " Remove characters from filenames for gf
" Create a directory if it doesn't exist yet
function! s:EnsureDirectory(directory)
if !isdirectory(expand(a:directory))
call mkdir(expand(a:directory), 'p')
endif
endfunction
" Save backup files, storage is cheap, losing changes is sad
set backup
set backupdir=$HOME/.tmp/vim/backup
call s:EnsureDirectory(&backupdir)
" Write undo tree to a file to resume from next time the file is opened
if has('persistent_undo')
set undolevels=2000 " The number of undo items to remember
set undofile " Save undo history to files locally
set undodir=$HOME/.vimundo " Set the directory of the undofile
call s:EnsureDirectory(&undodir)
endif
set directory=$HOME/.tmp/vim/swap
call s:EnsureDirectory(&directory)
set viewdir=$HOME/.tmp/vim/view
call s:EnsureDirectory(&viewdir)
" On quit reset title
let &titleold=getcwd()
let output=system("get-appearance")
exec 'set background=' . output
silent! colorscheme solarized
set ttyfast " Set that we have a fast terminal
set t_Co=256 " Explicitly tell Vim that the terminal supports 256 colors
set lazyredraw " Don't redraw vim in all situations
set synmaxcol=500 " The max number of columns to try and highlight
set noerrorbells " Don't make noise
set autoread " Watch for file changes and auto update
set showmatch " Set show matching parenthesis
set matchtime=2 " The amount of time matches flash
set display=lastline " Display super long wrapped lines
set number " Shows line numbers
set nrformats-=octal " Never use octal notation
set nojoinspaces " Don't add 2 spaces when using J
set mouse=a " Enable using the mouse if terminal emulator
set mousehide " Hide the mouse on typing
set hlsearch " Highlight search terms
set incsearch " Show searches as you type
set wrap " Softwrap text
set linebreak " Don't wrap in the middle of words
set ignorecase " Ignore case when searching
set smartcase " Ignore case if search is lowercase, otherwise case-sensitive
set title " Change the terminal's title
set updatetime=2000 " Set the time before plugins assume you're not typing
set scrolloff=5 " Lines the cursor is to the edge before scrolling
set sidescrolloff=5 " Same as scrolloff but horizontal
set gdefault " Adds g at the end of substitutions by default
set virtualedit=block " Allow the cursor to move off the side in visual block
set foldlevelstart=99 " Set the default level of open folds
set foldmethod=indent " Decide where to fold based
set foldnestmax=5 " Set deepest fold to x levels
set exrc " Source local .vimrc files
set secure " Don't load autocmds from local .vimrc files
set tags^=.tags,.git/tags " Add local .tags file
set signcolumn=yes
" https://kinbiko.com/vim/my-shiniest-vim-gems/
" Remove comments when joining lines with J
set formatoptions+=j
" Make |:find| discover recursive paths
set path+=**
" Completion options
set complete=.,w,b,u,t,kspell
set completeopt=menu
set wildmenu " Better completion in the CLI
set wildmode=longest:full,full " Completion settings
" Ignore these folders for completions
set wildignore+=.hg,.git,.svn " Version control
set wildignore+=*.jpg,*.bmp,*.gif,*.png,*.jpeg " binary images
set wildignore+=*.o,*.obj,*.exe,*.dll,*.manifest,*.pyc " compiled object files
set wildignore+=*.resolved " package manager lock files
set wildignore+=tags,.tags
" Dictionary for custom words
set dictionary+=/usr/share/dict/words
set spellfile=$HOME/.vim/custom-words.utf-8.add
" Set mapping and key timeouts
set timeout
set timeoutlen=1000
set ttimeoutlen=100
" Setting to indent wrapped lines
if exists('+breakindent')
set breakindent
set breakindentopt=shift:2
endif
" Check for file specific vim settings in the last 3 lines of the file
set modeline
set modelines=2
" Functions for status line config since these functions aren't loaded
" when the vimrc is sourced
function! CurrentTag(...)
if exists('g:tagbar_iconchars')
return call('tagbar#currenttag', a:000)
else
return ''
endif
endfunction
function! SyntasticStatuslineFlag()
return ''
endfunction
" Status line setup (without plugins)
set laststatus=2 " Always show the statusline
" Left Side
set statusline=
set statusline+=%#IncSearch#%{&paste?'\ \ PASTE\ ':''}%*
set statusline+=\ %.50f
set statusline+=\ %m
set statusline+=\ %r
set statusline+=%=
" Right Side
set statusline+=%{CurrentTag('%s\ <\ ','','')}
set statusline+=%y
set statusline+=\ \ %P
set statusline+=-%l
set statusline+=-%c
set statusline+=\ %#ErrorMsg#%{SyntasticStatuslineFlag()}%*
if has('clipboard') " If the feature is available
set clipboard=unnamed " copy to the system clipboard
if has('unnamedplus')
set clipboard+=unnamedplus
endif
endif
" Fuck you, help key.
noremap <F1> <Nop>
" Paging keys
inoremap <PageDown> <Nop>
inoremap <PageUp> <Nop>
nnoremap Q :quit<CR>
" Easier save mapping
nnoremap W :write<CR>
" Disable K
vnoremap K <Nop>
" Reselect visual blocks after movement
vnoremap < <gv
vnoremap > >gv
" Move as expected on wrapped lines
noremap j gj
noremap gj j
noremap <Down> gj
inoremap <Down> <C-o>gj
noremap k gk
noremap gk k
noremap <Up> gk
inoremap <Up> <C-o>gk
" Computers are dumb
" scroll gets reset every time the window is resized
nnoremap <C-u> 10<C-u>
nnoremap <C-d> 10<C-d>
" Netrw unfucking, custom gx because fugitive:// breaks the default gx
" The key here is that the second argument is a 0 which means !remote
nnoremap gx :call netrw#BrowseX(expand('<cfile>'), 0)<CR>
" https://www.reddit.com/r/vim/comments/4jy1mh/slightly_more_subltle_n_and_n_behavior/
" Keep search matches in the middle of the window unless the next match is in
" the same viewport
function! s:NextAndCenter(cmd)
let l:view = winsaveview()
try
execute 'normal! ' . a:cmd
catch /^Vim\%((\a\+)\)\=:E486/
" Fake a 'rethrow' of an exception without causing a 3 line error message
echohl ErrorMsg
echo 'E486: Pattern not found: ' . @/
echohl None
endtry
if l:view.topline != winsaveview().topline
normal! zzzv
endif
endfunction
nnoremap <silent> n :set hlsearch \| call <SID>NextAndCenter('n')<CR>
nnoremap <silent> N :set hlsearch \| call <SID>NextAndCenter('N')<CR>
" Remap capital y to act more like other capital letters
nnoremap Y y$
" Force root permission saves
cnoremap w!! w !sudo tee % >/dev/null
command! -bang Q q<bang>
command! -bang -nargs=* -complete=file W w<bang> <args>
" Change the way splits open by default
set splitbelow
set splitright
" Better movement
nnoremap H ^
vnoremap H ^
" Switch to the last file
nnoremap <leader><leader> <C-^>
" Move to last edit location and put it in the center of the screen
nnoremap <C-o> <C-o>zz
" Remove the last search thus clearing the highlight
" This clears the search register denoted by @/
nnoremap <silent> <leader>4 :let @/=""<CR>
" Don't automatically jump on search
nnoremap * :keepjumps normal! mi*`i<CR>
nnoremap # :keepjumps normal! mi#`i<CR>
" Highlight VCS conflict markers
match ErrorMsg '^\(<\|=\|>\)\{7\}\([^=].\+\)\?$'
augroup trailing_highlight
autocmd!
autocmd BufWinEnter * match ErrorMsg /\s\+$/
autocmd InsertEnter * match ErrorMsg /\s\+\%#\@<!$/
autocmd InsertLeave * match ErrorMsg /\s\+$/
augroup END
" Close all the lists
nnoremap <silent> <leader>q :call <SID>CloseLists()<CR>
function! s:CloseLists()
lclose
cclose
pclose
silent! TagbarClose
endfunction
command! ClearWhitespace call s:ClearWhitespace()
function! s:ClearWhitespace()
let l:line = line('.')
let l:column = col('.')
keepjumps silent! %s/\s\+$//e
call cursor(l:line, l:column)
call histdel('search', -1)
endfunction
command! FormatShellCommand call s:FormatShellCommand()
function! s:FormatShellCommand()
let l:line = line('.')
let l:column = col('.')
keepjumps silent! %s/ -/ \\\r -/e
call cursor(l:line, l:column)
call histdel('search', -1)
endfunction
" Unfuck my screen
nnoremap U :syntax sync fromstart<CR>:redraw!<CR>
" Running as diff
if &diff
set modifiable
set noreadonly
if tabpagenr('$') == 1
nnoremap ZZ :wqall<CR>
endif
else
" Jump to next/previous merge conflict marker
nnoremap <silent> ]c /\v^(\<\|\=\|\>){7}([^=].+)?$<CR>
nnoremap <silent> [c ?\v^(\<\|\=\|\>){7}([^=].+)\?$<CR>
endif
" Position resume
function! s:PositionRecall()
if &filetype =~? 'gitcommit\|gitrebase'
return
endif
if line("'\"") > 0 && line("'\"") <= line('$')
execute "normal g`\"zz"
endif
endfunction
function! s:SetColorColumn()
if &textwidth == 0
" Set colorcolumn specifically to 80 unless textwidth is set
set colorcolumn=80
else
" Show a line past the text width
set colorcolumn=+1
endif
endfunction
" Window sizes
augroup window_sizes
autocmd!
" Set the minimum window width for vertical splits
autocmd VimEnter * silent! set winwidth=80
autocmd VimEnter * silent! set winminwidth=20
augroup END
" Various filetype settings
augroup ft_settings
autocmd!
" Comment string settings
if empty(&commentstring) | setlocal commentstring=#\ %s | endif
autocmd FileType c,cpp,go,objc,php setlocal commentstring=//\ %s
" Treat more extensions as .zip files
autocmd BufReadCmd *.ipa call zip#Browse(expand("<amatch>"))
autocmd BufReadCmd *.apk call zip#Browse(expand("<amatch>"))
autocmd BufReadCmd *.aar call zip#Browse(expand("<amatch>"))
" Save files on some focus lost events, like switching splits
autocmd BufLeave,FocusLost * silent! wall
" Don't auto insert a comment when using O/o for a newline
autocmd VimEnter,BufRead,FileType * set formatoptions-=o
" Break lines based on 'textwidth' even if the line was longer before
" starting insert mode. This is useful for pasting long lines, and
" then continuing at the end of them.
autocmd VimEnter,BufRead,FileType * set formatoptions-=l
" Set color column based on textwidth setting
autocmd FileType * call s:SetColorColumn()
" Return to the same position you left the file in
autocmd BufRead * call s:PositionRecall()
autocmd FocusGained,BufEnter,CursorHold <buffer> checktime
" Create the binary spell file when opening vim
autocmd VimEnter * execute 'silent mkspell! ' . &spellfile
" Close location list when closing the window it belongs to
autocmd QuitPre * nested if &filetype != 'qf' | silent! lclose | endif
augroup END
" ObjC curly brace error fix
let g:c_no_curly_error = 1
" https://github.com/thoughtbot/dotfiles/pull/471
let g:is_posix = 1