.vimrc 4.55 KB
Newer Older
James Lee's avatar
James Lee committed
1
2
" Behave less like vi
set nocompatible
James Lee's avatar
James Lee committed
3

4
5
6
" Allow unsaved buffers
set hidden

James Lee's avatar
James Lee committed
7
8
9
" Set terminal title
set title

10
11
12
" Highlight current line
set cursorline

James T. Lee's avatar
James T. Lee committed
13
14
15
" Enable mouse (primarily so mouse selections use visual mode)
set mouse=a

16
17
18
19
" SGR mouse mode is supported by virtually every modern terminal, including my
" patched version of rxvt-unicode.  It is needed to support events beyond column
" 223.  Vim's SGR mode is backwards compatible with the older xterm2 protocol.
set ttymouse=sgr
20

James T. Lee's avatar
James T. Lee committed
21
22
23
24
25
26
27
" Automatically copy visual selection to selection clipboard
set clipboard=autoselect

" Enable more natural window splits
set splitbelow
set splitright

28
29
30
" Show line numbers for jumping around
set relativenumber

James T. Lee's avatar
James T. Lee committed
31
32
" Disable wrapping, show indicators on overflow, scroll smoothly
set nowrap list sidescroll=1
James T. Lee's avatar
James T. Lee committed
33

34
35
36
" Use more bash-like file completion (don't cycle through options)
set wildmode=longest,list

37
38
39
40
41
42
" Show command as it's being typed
set showcmd

" Use space as leader in a way that it still appears in the showcmd
map <Space> <Leader>

James T. Lee's avatar
James T. Lee committed
43
44
45
" Make switching between buffers easier
nnoremap <Leader>n :bn<CR>
nnoremap <Leader>p :bp<CR>
46
47
nnoremap <Leader>a <C-^>
nnoremap <Leader>b :CtrlPBuffer<CR>
48
nnoremap <Leader>w :w<CR>
James T. Lee's avatar
James T. Lee committed
49
50
51
52
53
54
55
56

" Create shortcuts to switch between indenting styles:
" indent with spaces:
nnoremap <Leader>2 :setlocal shiftwidth=2 tabstop=8 expandtab<CR>
nnoremap <Leader>4 :setlocal shiftwidth=4 tabstop=8 expandtab<CR>
nnoremap <Leader>8 :setlocal shiftwidth=8 tabstop=8 expandtab<CR>

" indent with tabs:
57
58
59
nnoremap <Leader>2 :setlocal shiftwidth=2 tabstop=2 noexpandtab<CR>
nnoremap <Leader>4 :setlocal shiftwidth=4 tabstop=4 noexpandtab<CR>
nnoremap <Leader>8 :setlocal shiftwidth=8 tabstop=8 noexpandtab<CR>
James T. Lee's avatar
James T. Lee committed
60
61
62
63
64

" sturdiva mode
" (maintain existing shiftwidth, but also enable hard tabs)
nnoremap <Leader>s :setlocal tabstop=8 noexpandtab<CR>

James T. Lee's avatar
James T. Lee committed
65
66
67
68
" Default to four spaces for tabs
set shiftwidth=4
set expandtab

69
70
augroup indentation
    autocmd!
James T. Lee's avatar
James T. Lee committed
71

72
73
74
75
76
77
    " New-style source code uses two spaces for tabs
    autocmd FileType javascript,json,puppet,ruby,yaml setlocal shiftwidth=2

    " Makefiles must use hard tabs, but let them appear as four spaces
    autocmd FileType make setlocal tabstop=4 noexpandtab
augroup end
James T. Lee's avatar
James T. Lee committed
78

James Lee's avatar
James Lee committed
79
80
81
" Let airline show the mode
set noshowmode

82
83
84
" Hide empty airline sections
let g:airline_skip_empty_sections = 1

85
86
87
88
89
" Show fancy tabline when more than one tab exists
let g:airline#extensions#tabline#enabled = 1
let g:airline#extensions#tabline#show_buffers = 0
let g:airline#extensions#tabline#tab_min_count = 2

90
91
92
93
94
95
96
" Don't fall back to weird unicode symbols; just use ascii
let g:airline_symbols_ascii = 1

" Tweak appearance
if !exists('g:airline_symbols')
    let g:airline_symbols = {}
endif
97
let g:airline_symbols.maxlinenr = '≡'
98

James T. Lee's avatar
James T. Lee committed
99
if &term =~# 'powerline'
100
    " Enable powerline characters on supported terminals
James T. Lee's avatar
James T. Lee committed
101
    let g:airline_powerline_fonts = 1
102
103
104
105

    " Use more common, single-width glyphs for line count and whitespace
    " problem indicator (utf8proc incorrectly reports the airline defaults as
    " two spaces wide)
James T. Lee's avatar
James T. Lee committed
106
    let g:airline_symbols.linenr = ''
107
    let g:airline_symbols.whitespace = '!'
James T. Lee's avatar
James T. Lee committed
108
endif
James T. Lee's avatar
James T. Lee committed
109

James T. Lee's avatar
James T. Lee committed
110
111
" Enable true-color on supported terminals
if &term =~# 'truecolor'
112
113
114
    set termguicolors
endif

115
" Tell vim how to use true colors in tmux
116
117
118
119
120
121
" See: help xterm-true-color
if &term =~# 'tmux'
    let &t_8f = "\<Esc>[38;2;%lu;%lu;%lum"
    let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum"
endif

James T. Lee's avatar
James T. Lee committed
122
" Set color scheme
123
colorscheme mine
James T. Lee's avatar
James T. Lee committed
124

125
" The base16 airline theme pulls colors from the main color scheme
James T. Lee's avatar
James T. Lee committed
126
127
let g:airline_theme='base16'

128
129
130
" But it's not perfect, so we modify it as follows
function! AirlineThemePatch(palette)
    if &t_Co <= 16
James T. Lee's avatar
James T. Lee committed
131
        " On low color terminals bold can change color, so disable bold
132
133
134
135
136
137
138
139
140
141
142
143
144
        let a:palette.accents.bold[4] = 'none'
        let a:palette.normal.airline_a[4] = 'none'
        let a:palette.insert.airline_a[4] = 'none'
        let a:palette.visual.airline_a[4] = 'none'

        " And just use plain reverse color for inactive status bars
        let s:inactive = ['', '', '', '', 'reverse']
        let a:palette.inactive = airline#themes#generate_color_map(s:inactive, s:inactive, s:inactive, s:inactive, s:inactive, s:inactive)
        let a:palette.inactive_modified = a:palette.inactive
    endif
endfunction
let g:airline_theme_patch_func = 'AirlineThemePatch'

145
" Configure fuzzy finder
146
let g:ctrlp_map = '<C-p>'
James T. Lee's avatar
James T. Lee committed
147
let g:ctrlp_cmd = 'CtrlP'
148
let g:ctrlp_show_hidden = 1
149

150
151
152
153
augroup special_filetypes
    autocmd!

    " http://vim.wikia.com/wiki/Always_start_on_first_line_of_git_commit_message
154
    autocmd FileType gitcommit autocmd! BufEnter COMMIT_EDITMSG call setpos('.', [0, 1, 1, 0])
155
augroup end