/
vimrc.vim
314 lines (239 loc) · 7.87 KB
/
vimrc.vim
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
" vimrc.vim - Extension of vim-sensible plugin with less sensible defaults.
" Maintainer: Adam Stankiewicz <sheerun@sher.pl>
" Version: 2.0
if exists("g:loaded_vimrc") || &cp
finish
else
let g:loaded_vimrc = 1
end
"" Basics
" Disable strange Vi defaults.
set nocompatible
" Turn on filetype plugins (:help filetype-plugin).
if has('autocmd')
filetype plugin indent on
endif
" Enable syntax highlighting.
if has('syntax')
syntax enable
endif
" Autoindent when starting new line, or using `o` or `O`.
set autoindent
" Allow backspace in insert mode.
set backspace=indent,eol,start
" Don't scan included files. The .tags file is more performant.
set complete-=i
" Use 'shiftwidth' when using `<Tab>` in front of a line.
" By default it's used only for shift commands (`<`, `>`).
set smarttab
" Disable octal format for number processing.
set nrformats-=octal
" Allow for mappings including `Esc`, while preserving
" zero timeout after pressing it manually.
set ttimeout
set ttimeoutlen=100
" Enable highlighted case-insensitive incremential search.
set incsearch
" Indent using two spaces.
set tabstop=2
set shiftwidth=2
set expandtab
" Use `Ctrl-L` to clear the highlighting of :set hlsearch.
nnoremap <silent> <C-L> :nohlsearch<CR><C-L>
" Always show window statuses, even if there's only one.
set laststatus=2
" Show the line and column number of the cursor position.
set ruler
" Show the size of block one selected in visual mode.
set showcmd
" Autocomplete commands using nice menu in place of window status.
" Enable `Ctrl-N` and `Ctrl-P` to scroll through matches.
set wildmenu
" When 'wrap' is on, display last line even if it doesn't fit.
set display+=lastline
" Force utf-8 encoding in GVim
if &encoding ==# 'latin1' && has('gui_running')
set encoding=utf-8
endif
" Set default whitespace characters when using `:set list`
set listchars=tab:>\ ,trail:-,extends:>,precedes:<,nbsp:+
" Delete comment character when joining commented lines
if v:version > 703 || v:version == 703 && has("patch541")
set formatoptions+=j
endif
" Search upwards for tags file instead only locally
if has('path_extra')
setglobal tags-=./tags tags^=./tags;
endif
" Reload unchanged files automatically.
set autoread
" Support all kind of EOLs by default.
set fileformats+=mac
" Increase history size to 1000 items.
set history=1000
" Allow for up to 50 opened tabs on Vim start.
set tabpagemax=50
" Always save upper case variables to viminfo file.
set viminfo^=!
" Enable backup and undo files by default.
let s:dir = has('win32') ? '$APPDATA/Vim' : isdirectory($HOME.'/Library') ? '~/Library/Vim' : empty($XDG_DATA_HOME) ? '~/.local/share/vim' : '$XDG_DATA_HOME/vim'
let &backupdir = expand(s:dir) . '/backup//'
let &undodir = expand(s:dir) . '/undo//'
set undofile
" Allow color schemes to do bright colors without forcing bold.
if &t_Co == 8 && $TERM !~# '^linux'
set t_Co=16
endif
" Load matchit.vim, but only if the user hasn't installed a newer version.
if !exists('g:loaded_matchit') && findfile('plugin/matchit.vim', &rtp) ==# ''
runtime! macros/matchit.vim
endif
" `Ctrl-U` in insert mode deletes a lot. Use `Ctrl-G` u to first break undo,
" so that you can undo `Ctrl-U` without undoing what you typed before it.
inoremap <C-U> <C-G>u<C-U>
" Avoid problems with fish shell
" ([issue](https://github.com/tpope/vim-sensible/issues/50)).
if &shell =~# 'fish$'
set shell=/bin/bash
endif
"" Extras
" Set monako font if using macvim
if has("gui_macvim")
set guifont=Monaco:h13
endif
" Keep flags when repeating last substitute command.
nnoremap & :&&<CR>
xnoremap & :&&<CR>
" Y yanks from the cursor to the end of line as expected. See :help Y.
nnoremap Y y$
" Automatically create directories for backup and undo files.
if !isdirectory(expand(s:dir))
call system("mkdir -p " . expand(s:dir) . "/{backup,undo}")
end
" Highlight line under cursor. It helps with navigation.
set cursorline
" Keep 8 lines above or below the cursor when scrolling.
set scrolloff=8
" Keep 15 columns next to the cursor when scrolling horizontally.
set sidescroll=1
set sidescrolloff=15
" Set minimum window size to 79x5.
set winwidth=79
set winheight=5
set winminheight=5
" If opening buffer, search first in opened windows.
set switchbuf=usetab
" Hide buffers instead of asking if to save them.
set hidden
" Wrap lines by default
set wrap linebreak
set showbreak=" "
" Allow easy navigation between wrapped lines.
vmap j gj
vmap k gk
nmap j gj
nmap k gk
" For autocompletion, complete as much as you can.
set wildmode=longest,full
" Show line numbers on the sidebar.
set number
" Disable any annoying beeps on errors.
set noerrorbells
set visualbell
" Don't parse modelines (google "vim modeline vulnerability").
set nomodeline
" Do not fold by default. But if, do it up to 3 levels.
set foldmethod=indent
set foldnestmax=3
set nofoldenable
" Enable mouse for scrolling and window resizing.
set mouse=a
" Disable swap to prevent annoying messages.
set noswapfile
" Save up to 100 marks, enable capital marks.
set viminfo='100,f1
" Enable search highlighting.
set hlsearch
" Ignore case when searching.
set ignorecase
" Show mode in statusbar, not separately.
set noshowmode
" Don't ignore case when search has capital letter
" (although also don't ignore case by default).
set smartcase
" Use dash as word separator.
set iskeyword+=-
" Add gems.tags to files searched for tags.
set tags+=gems.tags
" Disable output, vcs, archive, rails, temp and backup files.
set wildignore+=*.o,*.out,*.obj,.git,*.rbc,*.rbo,*.class,.svn,*.gem
set wildignore+=*.zip,*.tar.gz,*.tar.bz2,*.rar,*.tar.xz
set wildignore+=*/vendor/gems/*,*/vendor/cache/*,*/.bundle/*,*/.sass-cache/*
set wildignore+=*.swp,*~,._*
" Auto center on matched string.
noremap n nzz
noremap N Nzz
" Visually select the text that was last edited/pasted (Vimcast#26).
noremap gV `[v`]
" Expand %% to path of current buffer in command mode.
cnoremap <expr> %% getcmdtype() == ':' ? expand('%:h').'/' : '%%'
" Enable saving by `Ctrl-s`
nnoremap <C-s> :w<CR>
inoremap <C-s> <ESC>:w<CR>
" Use Q to intelligently close a window
" (if there are multiple windows into the same buffer)
" or kill the buffer entirely if it's the last window looking into that buffer.
function! CloseWindowOrKillBuffer()
let number_of_windows_to_this_buffer = len(filter(range(1, winnr('$')), "winbufnr(v:val) == bufnr('%')"))
if matchstr(expand("%"), 'NERD') == 'NERD'
wincmd c
return
endif
if number_of_windows_to_this_buffer > 1
wincmd c
else
bdelete
endif
endfunction
nnoremap <silent> Q :call CloseWindowOrKillBuffer()<CR>
" Set window title by default.
set title
" Always focus on splited window.
set splitright
set splitbelow
" Don't display the intro message on starting Vim.
set shortmess+=I
" Use Silver Searcher for CtrlP plugin (if available)
" Fallback to git ls-files for fast listing.
" Because we use fast strategies, disable caching.
let g:ctrlp_use_caching = 0
if executable('ag')
set grepprg=ag\ --nogroup\ --nocolor
let g:ctrlp_user_command = 'cd %s && ag -l --nocolor -g ""'
else
let g:ctrlp_user_command = ['.git',
\ 'cd %s && git ls-files . -co --exclude-standard',
\ 'find %s -type f' ]
endif
" Accept CtrlP selections also with <Space>
let g:ctrlp_prompt_mappings = {
\ 'AcceptSelection("e")': ['<Space>', '<CR>', '<2-LeftMouse>'],
\ }
" Make sure pasting in visual mode doesn't replace paste buffer
function! RestoreRegister()
let @" = s:restore_reg
return ''
endfunction
function! s:Repl()
let s:restore_reg = @"
return "p@=RestoreRegister()\<cr>"
endfunction
vmap <silent> <expr> p <sid>Repl()
" Prevent common mistake of pressing q: instead :q
map q: :q
" Make a simple "search" text object.
" http://vim.wikia.com/wiki/Copy_or_change_search_hit
" It allows for replacing search matches with cs and then /././.
vnoremap <silent> s //e<C-r>=&selection=='exclusive'?'+1':''<CR><CR>
\:<C-u>call histdel('search',-1)<Bar>let @/=histget('search',-1)<CR>gv
omap s :normal vs<CR>