forked from mathiasbynens/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.vimrc
250 lines (191 loc) · 5.63 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
" To disable a plugin, add it's bundle name to the following list
let g:pathogen_disabled = []
if !has('gui_running')
call add(g:pathogen_disabled, 'ultisnips')
endif
" Pathogen settings to auto-load new plugins (http://www.vim.org/scripts/script.php?script_id=2332)
filetype off
call pathogen#runtime_append_all_bundles()
call pathogen#helptags()
filetype plugin indent on
" Make Vim more useful (turn off vi compatibility)
set nocompatible
" Set <leader> to ,
let mapleader = ","
" prevents security exploits dealing with modelines in files
set modelines=0
" expands tabs to 4 spaces, etc
set tabstop=4
set shiftwidth=4
set softtabstop=4
set expandtab
" allow toggling between local and default mode
function TabToggle()
if &expandtab
set shiftwidth=2
set softtabstop=2
set noexpandtab
else
set shiftwidth=4
set softtabstop=4
set expandtab
endif
endfunction
nmap <leader><tab> :call TabToggle()<cr>
" Indentation rules
set autoindent
set cindent
set foldmethod=indent
set foldcolumn=3
set foldlevel=8
" Show TextMate-like whitespace chars for tab and end of line
set list
set listchars=tab:▸\ ,eol:¬
" Line-wrapping options
set nowrap
set textwidth=119
set formatoptions=qrn1
set colorcolumn=120
" Enhance command-line completion
set wildmenu
" Allow backspace in insert mode
set backspace=indent,eol,start
" Optimize for fast terminal connections
set ttyfast
" Add the g flag to search/replace by default
set gdefault
" Highlight results as you search
set incsearch
set showmatch
set hlsearch
" Clear a search by typing ,<space>
nnoremap <leader><space> :noh<cr>
" Use UTF-8 without BOM
set encoding=utf-8 nobomb
" Don’t add empty newlines at the end of files
" set binary
set noeol
" Centralize backups, swapfiles and undo history
set backupdir=~/.vim/backups
set directory=~/.vim/swaps
if exists("&undodir")
set undodir=~/.vim/undo
endif
" Enable per-directory .vimrc files and disable unsafe commands in them
set exrc
set secure
" Enable line numbers
set number
" Enable syntax highlighting
syntax on
" Syntax coloring lines that are too long just slows down the world
set synmaxcol=156
" Highlight current line
set cursorline
" Show “invisible” characters
set lcs=tab:▸\ ,trail:·,eol:¬,nbsp:_
set list
" Highlight searches
set hlsearch
" If searching all lowercase, search case-insensitive.
" If any characters are uppercase, search case-sensitive.
set ignorecase
set smartcase
" Highlight dynamically as pattern is typed
set incsearch
" Always show status line
set laststatus=2
set statusline+=%=%10((%l,%c)%)
" Enable mouse in all modes
set mouse=a
" Don’t reset cursor to start of line when moving around.
set nostartofline
" Show the cursor position
set ruler
" Don’t show the intro message when starting Vim
set shortmess=atI
" Show the current mode
set showmode
" Show the filename in the window titlebar
set title
" Show the (partial) command as it’s being typed
set showcmd
" Remaps / search key to use standard regex instead of vim regex
nnoremap / /\v
vnoremap / /\v
" Remap F1 to Esc to avoid accidentally opening help docs
inoremap <F1> <ESC>
nnoremap <F1> <ESC>
vnoremap <F1> <ESC>
" Turn on line numbers by typing ,num
nnoremap <leader>num :set number<cr>
nnoremap <leader>rnum :set relativenumber<cr>
nnoremap <leader>nonum :set nonumber<cr>:set norelativenumber<cr>
" Remaps % to tab to navigate matching brackets
nnoremap <tab> %
vnoremap <tab> %
" Start scrolling three lines before the horizontal window border
set scrolloff=3
if has('gui_running')
" Set color scheme
colorscheme solarized
let hr = str2nr(strftime('%H'))
" Between 6:00 AM and 7:00 PM, use a light background
" Otherwise, use a dark background
if hr >= 6 && hr <= 19
set background=light
else
set background=dark
endif
endif
" Strip trailing whitespace (,ss)
function! StripWhitespace()
let save_cursor = getpos(".")
let old_query = getreg('/')
:%s/\s\+$//e
call setpos('.', save_cursor)
call setreg('/', old_query)
endfunction
noremap <leader>ss :call StripWhitespace()<CR>
" Save a file as root (,W)
noremap <leader>W :w !sudo tee % > /dev/null<CR>
" Enable file type detection
filetype on
" Treat .json files as .js
autocmd BufNewFile,BufRead *.json setfiletype json syntax=javascript
" Set proper indentation for .json, .yml, and .gql
autocmd FileType json setlocal shiftwidth=2 softtabstop=2
autocmd FileType yaml set shiftwidth=2 softtabstop=2
autocmd FileType graphql set shiftwidth=2 softtabstop=2
" Edit crontab in-place
autocmd filetype crontab setlocal nobackup nowritebackup
let NERDSpaceDelims=1
" Save on losing focus
au FocusLost * :wa
" Directory for custom snippets
let g:UltiSnipsSnippetDirectories=["custom_snippets"]
" Snippet insert with Cmd-J and Shift-Cmd-J
let g:UltiSnipsExpandTrigger="<D-j>"
let g:UltiSnipsJumpForwardTrigger = "<D-j>"
let g:UltiSnipsJumpBackwardTrigger = "<s-D-j>"
" move text and rehighlight -- vim tip_id=224
vnoremap > ><CR>gv
vnoremap < <<CR>gv
" Syntastic
set statusline+=%#warningmsg#
set statusline+=%{SyntasticStatuslineFlag()}
set statusline+=%*
let g:syntastic_python_checkers = ['flake8']
if filereadable('.flake8')
let g:syntastic_python_flake8_args = '--config .flake8'
else
let g:syntastic_python_flake8_args = '--config ~/.flake8'
endif
let g:syntastic_python_flake8_exe = "$(pyenv prefix)/bin/python -m flake8"
let g:syntastic_javascript_checkers = ["eslint"]
let g:syntastic_javascript_eslint_exe = "$(npm bin -g)/eslint -c ~/.eslintrc"
let g:syntastic_always_populate_loc_list = 0
let g:syntastic_auto_loc_list = 0
let g:syntastic_check_on_open = 1
let g:syntastic_check_on_wq = 0
let g:syntastic_enable_signs = 1