-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathvimrc
298 lines (234 loc) · 8.13 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
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
filetype off
filetype plugin indent on " required
" The following block sets up vim-plug. Check github for README.
call plug#begin('~/.vim/plugged')
" colors
Plug 'jacoborus/tender'
" statusline
Plug 'itchyny/lightline.vim'
" comments
Plug 'tpope/vim-commentary'
" better tabs (try ":Tab /=" in a config file)
Plug 'godlygeek/tabular'
" additional file types
"Plug 'fatih/vim-nginx'
Plug 'chr4/nginx.vim'
Plug 'yoheimuta/vim-protolint'
" Expand region - press v repeatedly
Plug 'terryma/vim-expand-region'
Plug 'w0rp/ale'
Plug 'ThePrimeagen/git-worktree.nvim'
" start screen plugin.
Plug 'https://github.com/mhinz/vim-startify'
" ansible packages
Plug 'pearofducks/ansible-vim', {'for': ['ansible']}
" dart support
Plug 'dart-lang/dart-vim-plugin'
"go packages", lazy loaded for better startup
Plug 'fatih/vim-go', {'for': ['go'], 'do': [':GoInstallBinaries', ':GoUpdateBinaries']}
" better go autocomplete
Plug 'nsf/gocode', { 'rtp': 'vim', 'do': '~/.vim/plugged/gocode/vim/symlink.sh' }
" general syntax
Plug 'https://github.com/sheerun/vim-polyglot'
Plug 'https://github.com/tpope/vim-sleuth' " proper tabstops
" git helpers
Plug 'https://github.com/jreybert/vimagit', {'branch': 'next', 'on': ['Magit', 'MagitOnly']}
Plug 'https://github.com/airblade/vim-gitgutter'
" basic system utils
Plug 'https://github.com/tpope/vim-eunuch'
" Awesome navigation
Plug 'https://github.com/justinmk/vim-sneak'
" Open files from grep results
Plug 'https://github.com/wsdjeg/vim-fetch'
" map jk/kj to escape
Plug 'zhou13/vim-easyescape'
" rainbow parens and brackets
Plug 'luochen1990/rainbow'
call plug#end()
"" Basics
syntax enable
set encoding=utf-8
set showcmd " display incomplete commands
set number " enable line numbers
set autoindent " set auto-indenting on for programming
set showmatch " automatically show matching brackets. works like it does in bbedit.
set visualbell " turn on the "visual bell" - which is much quieter than the "audio blink"
set ruler " show the cursor position all the time
set backspace=indent,eol,start " make that backspace key work the way it should
" set clipboard=unnamed " set clipboard to unnamed to access the system clipboard under windows
"" Leader
let g:mapleader="\<Space>"
"" leader shortcuts
" :W saves the file with sudo. must come before the <leader>w remap below
command W w !sudo tee % > /dev/null
" quickly save files
nnoremap <Leader>w :w<CR>
" write and quit
noremap <leader>q :q<cr>
" system clipboard
" set clipboard=unnamedplus
" map <leader>y "+y
"" Colors
colorscheme tender
"hi Visual guibg=#5f5f5f ctermbg=59 " manual override.
hi Visual term=reverse cterm=reverse guibg=#5f5f5f
"" Whitespace
set nowrap " don't wrap lines
set tabstop=4 shiftwidth=4 " a tab is four spaces
set expandtab " use spaces, not tabs
set backspace=indent,eol,start " backspace through everything in insert mode
command! KillWhitespace :normal :%s/ *$//g<cr><c-o><cr>
"" indentation and tabbing rules
autocmd Filetype yaml setlocal ts=2 sts=2 sw=2
autocmd Filetype sh setlocal ts=4 sts=4 sw=4
"" Splits
set splitright
set splitbelow
"" Searching
set hlsearch " highlight matches
set incsearch " incremental searching
set ignorecase " searches are case insensitive...
set smartcase " ... unless they contain at least one capital letter
""" faster loads for gitgutter
set updatetime=250
""" lightline settings """
" enable tender theme
let g:tender_lightline = 1
" set lightline theme
let g:lightline = {
\ 'colorscheme': 'tender',
\ 'component' : {
\ 'readonly': '%{&filetype=="help"?"":&readonly?"-":""}',
\ 'modified': '%{&filetype=="help"?"":&modified?"+":&modifiable?"":"-"}'
\ },
\ 'component_visible_condition': {
\ 'readonly': '(&filetype!="help"&& &readonly)',
\ 'modified': '(&filetype!="help"&&(&modified||!&modifiable))'
\ },
\ 'active' : {
\ 'right' : [ [ 'lineinfo' ], [ 'percent' ], [ 'filetype' ] ]
\ },
\ }
if !has('gui_running')
set t_Co=256
endif
set laststatus=2
set noshowmode
" http://www.blaenkdenum.com/posts/a-simpler-vim-statusline/
" mode aware cursors (NOTE: Gui Only)
set guicursor=a:block
set guicursor+=o:hor50-Cursor
set guicursor+=n:Cursor
set guicursor+=i-ci-sm:InsertCursor
set guicursor+=r-cr:ReplaceCursor-hor20
set guicursor+=c:CommandCursor
set guicursor+=v-ve:VisualCursor
set guicursor+=a:blinkon0
hi InsertCursor ctermfg=15 guifg=#fdf6e3 ctermbg=37 guibg=#2aa198
hi VisualCursor ctermfg=15 guifg=#fdf6e3 ctermbg=125 guibg=#d33682
hi ReplaceCursor ctermfg=15 guifg=#fdf6e3 ctermbg=65 guibg=#dc322f
hi CommandCursor ctermfg=15 guifg=#fdf6e3 ctermbg=166 guibg=#cb4b16
" line number colors.
"hi CursorLineNr term=bold ctermfg=Yellow gui=bold guifg=Yellow
highlight LineNr term=bold cterm=NONE ctermfg=DarkGrey ctermbg=NONE gui=NONE guifg=DarkGrey guibg=NONE
" Quickly edit vimrc
nnoremap <leader>ev :vsplit $MYVIMRC<cr>
nnoremap <leader>sv :source $MYVIMRC<cr>
" golang
let g:go_fmt_command = 'goimports'
augroup myGo
autocmd FileType go nmap <leader>b <Plug>(go-build)
augroup END
" sane defaults for Make files
autocmd FileType make setlocal noexpandtab "shiftwidth=4 softtabstop=0 tabstop=4
autocmd FileType make nmap <leader>t :%s/^<Space>\{4}/\t/<CR>
" expand regions (github.com/terryma/vim-expand-region)
vmap v <Plug>(expand_region_expand)
vmap <C-v> <Plug>(expand_region_shrink)
" vp 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()
" ansible config
let g:ansible_unindent_after_newline = 1
let g:ansible_extra_syntaxes = "sh.vim ruby.vim"
" Automatic paste detection.
" Credit: https://szunyog.github.io/vim/vim-automatically-set-paste-mode
function! WrapForTmux(s)
if !exists('$TMUX')
return a:s
endif
let tmux_start = "\<Esc>Ptmux;"
let tmux_end = "\<Esc>\\"
return tmux_start . substitute(a:s, "\<Esc>", "\<Esc>\<Esc>", 'g') . tmux_end
endfunction
let &t_SI .= WrapForTmux("\<Esc>[?2004h")
let &t_EI .= WrapForTmux("\<Esc>[?2004l")
" Fix copy-paste
function! XTermPasteBegin()
set pastetoggle=<Esc>[201~
set paste
return ""
endfunction
inoremap <special> <expr> <Esc>[200~ XTermPasteBegin()
" Return to last edit position when opening file
au BufReadPost * if line("'\"") > 1 && line("'\" ") <= line("$") | exe "normal! g'\"" | endif
" Persistent undo
try
set undodir=~/.vim/temp_dirs/undodir
set undofile
catch
endtry
" stop from automatically yanking on visual select (?)
set clipboard-=autoselect
" vim-sneak 's' repeats search
let g:sneak#s_next = 1
" case-insensitive vim-sneak
let g:sneak#use_ic_scs = 1
" AlE config
" errors on airline
let g:airline#extensions#ale#enabled = 1
" linters
let g:ale_linters = {
\ 'proto': ['protolint'],
\}
" fixers
let g:ale_fixers = {
\ '*': ['remove_trailing_lines', 'trim_whitespace'],
\ 'javascript': ['eslint'],
\ 'proto': ['ale#fixers#protolint#Fix'],
\}
" fix files when you save them.
let g:ale_fix_on_save = 1
" proto files
let g:ale_lint_on_text_changed = 'never'
map ^[OA <up>
map ^[OB <down>
map ^[OC <right>
map ^[OD <left>
" template files
if has("autocmd")
augroup templates
autocmd BufNewFile *.sh 0r ~/.vim/templates/skeleton.sh
autocmd BufNewFile *.zsh 0r ~/.vim/templates/skeleton.zsh
autocmd BufNewFile docker-compose.yml 0r ~/.vim/templates/skeleton-docker-compose.yml
autocmd BufNewFile README.md 0r ~/.vim/templates/skeleton-README.md
autocmd BufNewFile Makefile 0r ~/.vim/templates/skeleton.Makefile
autocmd BufNewFile *.py 0r ~/.vim/templates/skeleton.py
augroup END
endif
" Easy escape: https://github.com/zhou13/vim-easyescape/
if has("python3")
let g:easyescape_chars = { "j": 1, "k": 1 }
let g:easyescape_timeout = 100
cnoremap jk <ESC>
cnoremap kj <ESC>
endif
" rainbow parens ('luochen1990/rainbow')
let g:rainbow_active = 1 "set to 0 if you want to enable it later via :RainbowToggle