-
Notifications
You must be signed in to change notification settings - Fork 1
/
.vimrc
214 lines (177 loc) · 5.62 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
" disable vi-compatibility mode (allows real vim configuration):
set nocompatible
" currently modeline is susceptible to remote code execution
" (https://github.com/numirias/security/blob/master/doc/2019-06-04_ace-vim-neovim.md):
set nomodeline
" inject pathogen plugins (from ~/.vim/bundle):
call pathogen#infect()
function! ConfigureUI()
"enable syntax highlighting:
syntax enable
" load plugins and indents for filetypes:
filetype plugin indent on
"use solarized and which flavor (light/dark to use):
colorscheme solarized
set background=dark
highlight clear SignColumn
" always show ruler:
set ruler
" always show line numbers
set number
" make vim look for UI updates more frequently:
set updatetime=100
" airline stuff:
let g:airline#extensions#tabline#enabled = 1
let g:airline_powerline_fonts = 1
let g:airline_theme='solarized'
set laststatus=2
" in the rare case that we're in a gui vim (e.g. MacVim),
" set an appropriate font. this allows powerline/airline
" to render special characters:
if has("gui_running")
set guifont=Inconsolata-g\ for\ Powerline
endif
"allow mouse support for stuff like resizing panes (neovim):
set mouse=a
" default to filetype-specific plugins and indentations:
filetype plugin indent on
" ignore case on search:
set ignorecase
" auto-indent files:
set autoindent
" show non-printing characters
set list
" configure tabs and trailing spaces:
set listchars=tab:→\ ,trail:•
" tabs take up the same space as 2 spaces:
set tabstop=2
" treat 2 spaces as a tab:
set shiftwidth=2
" use spaces, not tabs:
set expandtab
" display when a contextualizing symbol has a match
set showmatch
" wildcard matching:
set wildmode=longest,list,full
set wildmenu
" hide abandoned buffers (e.g. unsaved changes in buffers)
" without forcing the user to save:
set hidden
" allow backspacing over indents, linebreaks,
" and start position of insert mode:
set backspace=indent,eol,start
" autocompletion doesn't insert stuff, just shows it:
set completeopt+=noinsert
let g:goyo_width = '100%'
inoremap <silent><expr> <c-space> coc#refresh()
endfunction
call ConfigureUI()
function! ConfigureKeys()
" manually change to working directory with <leader>cd:
map <leader>cd :cd %:p:h<CR>:pwd<CR>
" handle `:W` as `:w` and `:E` as `:e`
" (i.e. set up fatfinger aliases):
cnoreabbrev W w
cnoreabbrev E e
cnoreabbrev Q q
cnoreabbrev Qa qa
cnoreabbrev explore Explore
cnoreabbrev Redraw redraw
" use system clipboard:
set clipboard^=unnamed,unnamedplus
" when joining selected text (<C-j>), collapse spaces:
set nojoinspaces
endfunction
call ConfigureKeys()
function! ConfigureUndoRedo()
set noswapfile
set hidden
set undofile
set undodir=~/.vim/undodir
endfunction
call ConfigureUndoRedo()
function! ConfigureFileTypes()
autocmd BufNewFile,BufRead *.pp set filetype=ruby
autocmd BufNewFile,BufRead *.cshtml set filetype=html
endfunction
call ConfigureFileTypes()
function! ConfigureSearch()
" highlight search results immediately as matches appear
set incsearch
" highlight all search matches, not just the current match:
set hlsearch
" turn off search highlighting after user submits carriage return:
nnoremap <CR> :noh<CR><CR>
endfunction
call ConfigureSearch()
function! ConfigureIgnoreDirectories()
" never display, e.g., any node_modules directory:
set wildignore+=*/**/node_modules
set wildignore+=*.class
set wildignore+=*/target/*
set wildignore+=*.ico,*.jpg,*.gif,*.png
endfunction
call ConfigureIgnoreDirectories()
function! ConfigureTmux()
" alter cursor shape for different modes in terminal vim (may not work in
" Terminal.app)
if exists('$TMUX')
" also make this work for tmux:
let &t_SI = "\<Esc>Ptmux;\<Esc>\<Esc>]50;CursorShape=1\x7\<Esc>\\"
let &t_EI = "\<Esc>Ptmux;\<Esc>\<Esc>]50;CursorShape=0\x7\<Esc>\\"
else
let &t_SI = "\<Esc>]50;CursorShape=1\x7"
let &t_EI = "\<Esc>]50;CursorShape=0\x7"
endif
endfunction
call ConfigureTmux()
function! ConfigureFZF()
" fuzzy finder:
set rtp+=/usr/local/opt/fzf
" open fzf with ctrl+p
map <C-p> :FZF<CR>
" open fzf buffers with ctrl+alt+p:
map <C-M-p> :Buffers<CR>
endfunction
call ConfigureFZF()
function! ConfigureAle()
let g:ale_sign_column_always = 1
let g:airline#extensions#ale#enabled = 1
" configure JS to fix files with prettier and eslint:
let g:ale_fixers = {'javascript': ['prettier', 'eslint']}
let g:ale_fixers['typescript'] = ['prettier', 'eslint']
let g:ale_fixers['typescriptreact'] = ['prettier', 'eslint']
let g:ale_fixers['flow'] = ['prettier', 'eslint']
let g:ale_fixers['json'] = ['fixjson']
let g:ale_fixers['swift'] = ['swiftformat']
let g:ale_lint_delay = 100
" fix files when they're saved:
let g:ale_fix_on_save = 1
" show 5 lines in that loclist:
let g:ale_list_window_size = 5
" enable autocomplete:
" let g:ale_completion_enabled = 1
" wait 500ms for autocomplete:
"let g:ale_completion_delay = 200
" <C-]> goes to definition:
nnoremap <C-]> :ALEGoToDefinition<CR>
" <C-[> finds usages:
" nnoremap <C-[> :ALEFindReferences<CR>
endfunction
call ConfigureAle()
function! ConfigureExtensibility()
" enable per-directory .vimrc files
set exrc
if filereadable(glob('./.vimrc.local'))
source ./.vimrc.local
endif
endfunction
call ConfigureExtensibility()
function! PostConfigGenerateHelpTags()
" add plugins to runtime path; necessary to generate helptags for plugins:
packloadall
" silently load helptags (ignore messages and errors. we just want the
" helptags gen'd:
silent! helptags ALL
endfunction
call PostConfigGenerateHelpTags()