summary refs log tree commit diff
path: root/.vimrc
blob: fb302857ec06699090e8f4c8585e3403bd06590e (plain) (blame)
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
" Do not try to behave like vi.
set nocompatible

" Allow backspace in insert mode to delete past the beginning of the line.
set backspace=indent,eol,start

" Keep buffers loaded even when they aren't shown. Allows switching buffers
" without saving first.
set hidden

" Keep 50 lines of : command history and search patterns.
set history=50

" Show the cursor position in the bottom right.
set ruler

" Show partial command in the bottom right (i.e. if a command is started but
" needs a motion, it will be shown).
set showcmd

" Jump to search results while typing. Pressing enter actually jumps to the
" result, pressing escape goes back to the cursor.
set incsearch

" Perform case-insensitive searching when the search pattern contains only
" lowercase letters.
set ignorecase
set smartcase

" Copy the indent from the previous line when starting a new line.
" Automatically indent between curly braces and indent keywords.
set autoindent
set smartindent

" Show line numbers.
set number

" Perform spell-checking on strings and comments.
set spell

" Highlight the 80th column.
set colorcolumn=80

" Set the window title with the current file name, status and directory.
set title

" Make file messages shorter:
"  - a: Shorten all file description messages
"  - t: Truncate file messages if they are too long
"  - I: Do not show the intro message when Vim starts
set shortmess=atI

" Disable beeping and visual bell (flashing the terminal window).
set visualbell t_vb=

" Highlight the current line.
set cursorline

" Insert `shiftwidth` spaces at the beginning of a line when tab is pressed,
" delete `shiftwidth` spaces when backspace is pressed.
set smarttab

" Highlight all search matches.
set hlsearch

" Show hard tabs and trailing whitespace.
set list
set listchars=tab:»·,trail:·


" Fold by syntax, start with all folds open.
set foldmethod=syntax
set foldlevelstart=99

" Always show the status line.
set laststatus=2

" Always show one line above or below the cursor.
set scrolloff=1

" Ctrl-A and Ctrl-X work on hex and single letters
set nrformats=alpha,hex

" Enable syntax highlighting.
syntax on

" Enable mouse in terminals
if has('mouse')
  set mouse=a
endif

" Disable spell-checking in terminal Vim.
if !has('gui_running')
  set nospell
endif

" GUI options:
"  * -m: Disable menu bar
"  * -r: Disable right scroll bar
"  * -L: Disable left scroll bar
"  * -T: Disable toolbar
"  * +c: Use console dialogs
set guioptions-=m
set guioptions-=r
set guioptions-=L
set guioptions-=T
set guioptions+=c

" Use a font.
set guifont=ProFont:h11

" Jump to the last cursor position when opening a file.
au BufReadPost * if &filetype !~ '^git\c' && line("'\"") > 0 && line("'\"") <= line("$")
    \| exe "normal! g`\"" | endif

" Use two-space indents.
set expandtab
set shiftwidth=2

" Round to the nearest multiple of `shiftwidth` when indenting.
set shiftround

" Show hard tabs as 4 characters wide.
set tabstop=4


" Load filetype plugins and indentation rules.
filetype plugin indent on

" Use 4-space indents in C, C++ and Lua.
autocmd FileType c,cpp,lua setlocal sw=4

" Hard-wrap text at 72 characters in Markdown.
autocmd FileType markdown setlocal tw=72

" C/C++ indentation options:
"  * :0 Align `case` with `switch`
"  * l1 Indent case bodies with braces to case
"  * g0 Align `public:` and friends to class
set cinoptions=:0,l1,g0

" Show tab-complete suggestions when typing in the command-line. List all
" matches and complete to the longest common string. Ignore output files and
" backups.
set wildmenu
set wildmode=list:longest
set wildignore=*.o,*.d,*~

" Smarter % matching on HTML tags, if/endif etc.
runtime macros/matchit.vim

" Do not show whitespace in insert mode.
autocmd InsertEnter * setlocal nolist
autocmd InsertLeave * setlocal list

" Set leader to , and remap , to \.
noremap \ ,
let mapleader = ","

" Swap ' and ` (' is now character-wise and ` is line-wise).
nnoremap ' `
nnoremap ` '

" Clear search result highlighting.
nmap <leader>n :nohlsearch<CR>

" Toggle visible whitespace.
nmap <leader>s :set list!<CR>

" Toggle spell checking.
nmap <leader>z :set spell!<CR>

" Cut/copy/paste to system clipboard.
nmap <leader>p "+p
nmap <leader>P "+P
nmap <leader>y "+y
nmap <leader>Y "+Y
nmap <leader>d "+d
nmap <leader>D "+D

" Yank to end of line.
nmap Y y$

" Insert hard tab.
imap <S-tab> <C-v><tab>

" Toggle relative/absolute line numbers.
function! NumberToggle()
  if(&relativenumber == 1)
    set norelativenumber
  else
    set relativenumber
  endif
endfunc
nmap <C-n> :call NumberToggle()<CR>

" Common typos.
command! W :w
command! Q :q

" Plugins

call plug#begin('~/.vim/plugged')

" Fancy statusline.
Plug 'bling/vim-airline'
" Don't show mode in last line.
set noshowmode
" Disable silly > separators.
let g:airline_left_sep = ''
let g:airline_right_sep = ''
" Only show diff stats if there are some.
let g:airline#extensions#hunks#non_zero_only = 1
" Don't complain about whitespace constantly.
let g:airline#extensions#whitespace#enabled = 0

" Syntax checking.
Plug 'scrooloose/syntastic'
let g:syntastic_check_on_open=1
let g:syntastic_enable_signs=0

" Git diff signs in margins.
Plug 'mhinz/vim-signify'
let g:signify_vcs_list = ['git']
let g:signify_sign_overwrite = 1
let g:signify_sign_change = '~'

" Fuzzy matching files/buffers.
Plug 'kien/ctrlp.vim'
nmap <leader>b :CtrlPBuffer<CR>
nmap <leader>e :CtrlP<CR>
nmap <leader>t :CtrlPBufTag<CR>
nmap <leader>l :CtrlPLine<CR>

" Git commands.
Plug 'tpope/vim-fugitive'
nmap <leader>gs :Gstatus<CR>
nmap <leader>gc :Gcommit<CR>
nmap <leader>gp :Git push<CR>

" Alignment of = : , etc.
Plug 'junegunn/vim-easy-align'
vnoremap <silent> <Enter> :EasyAlign<Enter>

" Auto-close braces, parens, quotes, etc.
Plug 'Raimondi/delimitMate'
let delimitMate_expand_cr = 1
let delimitMate_expand_space = 1
let delimitMate_jump_expansion = 1

" Indent guides by alternating background colour. (<leader>ig)
Plug 'nathanaelkane/vim-indent-guides'
let g:indent_guides_start_level = 2

" Colorschemes.
Plug 'programble/jellybeans.vim'
Plug 'programble/vim-hybrid'
" Show nearest tag in statusline.
Plug 'majutsushi/tagbar'
" Scratch buffers.
Plug 'programble/itchy.vim'
" Better paste indentation.
Plug 'sickill/vim-pasta'
" Commenting.
Plug 'tpope/vim-commentary'
" Surround text objects.
Plug 'tpope/vim-surround'
" Sublime-style multiple cursors. (C-n)
Plug 'terryma/vim-multiple-cursors'
" Increment, decrement dates and roman numerals with C-a, C-x.
Plug 'tpope/vim-speeddating'
" File-related commands.
Plug 'tpope/vim-eunuch'
" Highlight color values with their color in CSS.
Plug 'ap/vim-css-color'
" Swap two selections.
Plug 'tommcdo/vim-exchange'

" Language support.
Plug 'digitaltoad/vim-jade'
Plug 'groenewege/vim-less'
Plug 'kchmck/vim-coffee-script'
Plug 'pangloss/vim-javascript'
Plug 'tpope/vim-markdown'
Plug 'tpope/vim-ragtag'

call plug#end()

colorscheme hybrid
let g:airline_theme = 'tomorrow'