/
.vimrc
325 lines (285 loc) · 12 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
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
" Init / Vundle {{{
set nocompatible
filetype off
set rtp+=~/.vim/bundle/Vundle.vim
set rtp+=/usr/local/opt/fzf
call vundle#begin()
Plugin 'VundleVim/Vundle.vim' " let vundle manage itself
Plugin 'w0rp/ale' " async linting of files
Plugin 'sheerun/vim-polyglot' " lots of language packs in one plugin
Plugin 'christoomey/vim-tmux-navigator' " seamless pane switching between tmux and vim using vim binds
Plugin 'AndrewRadev/splitjoin.vim' " toggle single line to multiline stuff
Plugin 'chriskempson/base16-vim' " color scheme
Plugin 'itchyny/lightline.vim' " bottom line displaying mode / file / time etc...
Plugin 'mgee/lightline-bufferline' " show open buffers at top of window
Plugin 'jreybert/vimagit' " interactive git staging
Plugin 'benmills/vimux' " Run commands from vim
Plugin 'tpope/vim-abolish' " smart case replace and much more
Plugin 'tpope/vim-commentary' " code commenting
Plugin 'tpope/vim-endwise' " auto insert 'end'-like keywords
Plugin 'tpope/vim-fugitive' " vim git wrapper, also used by vimagit
Plugin 'tpope/vim-repeat' " better repeat, extensible by plugins
Plugin 'tpope/vim-vinegar' " enhance netrw
Plugin 'tpope/vim-surround' " change/add/remove surrounding brackets
Plugin 'haya14busa/incsearch.vim' " auto nohlsearch and some extra search goodies
Plugin 'junegunn/vim-easy-align' " align code easier
Plugin 'junegunn/fzf.vim' " fzf as vim plugin
Plugin 'fmoralesc/vim-pad' " notes
" only emable to update tmux statusline look
" Plugin 'edkolev/tmuxline.vim'
call vundle#end()
" }}}
" General {{{
let mapleader = " " " remap leader
filetype plugin indent on
colorscheme base16-default-dark " apply color scheme
syntax enable " cuz white text is going to be awesome to edit :D
set path+=** " add cwd and 1 level of nesting to path
set hidden " debatable, allow switching from unsaved buffer without '!'
set ignorecase " ignore case in search
set smartcase " use case-sensitive if a capital letter is included
set noshowmode " statusline makes -- INSERT -- info irrelevant
set number " show lines
set relativenumber " show relative number
set cursorline " highlight cursor line
set splitbelow " split below instead of above
set splitright " split after instead of before
set termguicolors " enable termguicolors for better highlighting
set background=dark " set bg dark
set nobackup " do not keep backups
set noswapfile " no more swapfiles
set clipboard=unnamed " copy into osx clipboard by default
set encoding=utf-8 " utf-8 files
set fileencoding=utf-8 " utf-8 files
set fileformat=unix " use unix line endings
set fileformats=unix,dos " try unix line endings before dos, use unix
set laststatus=2 " always show statusline
set expandtab " softtabs, always (e.g. convert tabs to spaces)
set shiftwidth=2 " tabsize 2 spaces (by default)
set softtabstop=2 " tabsize 2 spaces (by default)
set tabstop=2 " tabsize 2 spaces (by default)
set showtabline=2 " always show statusline
set backspace=2 " restore backspace
set nowrap " do not wrap text at `textwidth`
set noerrorbells " do not show error bells
set visualbell " do not use visual bell
set t_vb= " do not flash screen with visualbell
set timeoutlen=500 " mapping delay
set ttimeoutlen=10 " keycode delay
set wildignore+=.git,.DS_Store " ignore files (netrw)
set scrolloff=10 " show 10 lines of context around cursor
" remap bad habits to do nothing
imap <Up> <Nop>
imap <Down> <Nop>
imap <Left> <Nop>
imap <Right> <Nop>
nmap <Up> <Nop>
nmap <Down> <Nop>
nmap <Left> <Nop>
nmap <Right> <Nop>
nmap >> <Nop>
nmap << <Nop>
vmap >> <Nop>
vmap << <Nop>
map $ <Nop>
map ^ <Nop>
map { <Nop>
map } <Nop>
" easier navigation in normal / visual / operator pending mode
noremap K {
noremap J }
noremap H ^
noremap L $
noremap <C-x> :bp<Bar>bd #<Cr>
" easier navigation in insert mode
inoremap <C-k> <Up>
inoremap <C-j> <Down>
inoremap <C-h> <Left>
inoremap <C-l> <Right>
" make Y consistent with C and D
nnoremap Y y$
" use qq to record, q to stop, Q to play a macro
nnoremap Q @q
" use tab and shift tab to indent and de-indent code
nnoremap <Tab> >>
nnoremap <S-Tab> <<
vnoremap <Tab> >><Esc>gv
vnoremap <S-Tab> <<<Esc>gv
" use shift tab to exit insert and operator-pending mode
inoremap <S-Tab> <Esc>
onoremap <S-Tab> <Esc>
" when pairing some braces or quotes, put cursor between them
inoremap <> <><Left>
inoremap () ()<Left>
inoremap {} {}<Left>
inoremap [] []<Left>
inoremap "" ""<Left>
inoremap '' ''<Left>
inoremap `` ``<Left>
if &diff
" use familiar C-n and C-p binds to move between hunks
nnoremap <C-n> ]c
nnoremap <C-p> [c
" unbind indent and de-indent keys in diff mode
nunmap <S-tab>
nunmap <Tab>
" instead use tab to inject local change and shift tab for remote change
nnoremap <Tab> :diffg LO<Cr>
nnoremap <S-Tab> :diffg RE<Cr>
endif
" fix jsx highlighting of end xml tags
hi link xmlEndTag xmlTag
" convenience function for setting filetype specific spacing
if !exists('*s:IndentSize')
function s:IndentSize(amount)
exe "setlocal expandtab ts=" . a:amount . " sts=" . a:amount . " sw=" . a:amount
endfunction
endif
" use ripgrep as grepprg
if executable('rg')
set grepprg=rg\ --color=never\ --vimgrep\ --no-ignore-vcs\ --follow\ --hidden\ --glob\ ''
endif
" }}}
" Netrw {{{
let g:netrw_banner = 0
let g:netrw_winsize = 20
let g:netrw_liststyle = 3
let g:netrw_altv = 1
" }}}
" Vim-pad {{{
let g:pad#dir = '~/notes'
let g:pad#window_height = 20
let g:pad#set_mappings = 0
let g:pad#open_in_split = 0
noremap <Leader>n :Pad ls<Cr>
noremap <Leader>N :Pad new<Cr>
" }}}
" Tmuxline {{{
" tmux statusline custom format
let g:tmuxline_preset = {
\ 'a': '⬤',
\ 'win': '#I #W',
\ 'cwin': '#I #W',
\ 'y': '%d·%m·%Y',
\ 'z': '%R',
\ 'options': { 'status-justify': 'left' }
\ }
" }}}
" Ale {{{
let g:ale_echo_msg_error_str = 'E' " error sign
let g:ale_echo_msg_format = '[%linter%] %s [%severity%]' " status line format
let g:ale_echo_msg_warning_str = 'W' " warning sign
let g:ale_statusline_format = ['⨉ %d', '⚠ %d', '⬥ ok'] " error status format
let g:ale_lint_delay = 1000 " relint max once per second
let g:ale_set_loclist = 0 " do not use location list
let g:ale_set_quickfix = 1 " but do use quickfix list
let g:ale_linters = {
\ 'ruby': ['rubocop'],
\ 'javascript': ['eslint']
\ }
" }}}
" Incsearch {{{
let g:incsearch#auto_nohlsearch = 1 " auto unhighlight after searching
let g:incsearch#magic = '\v' " sheer awesomeness
let g:incsearch#do_not_save_error_message_history = 1 " do not store incsearch errors in history
let g:incsearch#consistent_n_direction = 1 " when searching backward, do not invert meaning of n and N
map / <Plug>(incsearch-forward)
map ? <Plug>(incsearch-backward)
" }}}
" Lightline {{{
let g:lightline#bufferline#show_number = 2 " show buf number in bufferline
let g:lightline#bufferline#shorten_path = 1 " do not show full path
let g:lightline#bufferline#modified = '[+]' " modifier buffer label
let g:lightline#bufferline#read_only = '[!]' " readonly buffer label
let g:lightline#bufferline#unnamed = '[*]' " unnamed buffer label
let g:lightline = {
\ 'colorscheme': 'wombat',
\ 'tabline': { 'left': [[ 'buffers' ]] },
\ 'component_expand': { 'buffers': 'lightline#bufferline#buffers' },
\ 'component_type': { 'buffers': 'tabsel' },
\ 'separator': { 'left': "\ue0b0", 'right': "\ue0b2" },
\ 'subseparator': { 'left': "\ue0b1", 'right': "\ue0b3" },
\ 'component_function': {
\ 'bufferbefore': 'lightline#buffer#bufferbefore',
\ 'bufferafter': 'lightline#buffer#bufferafter',
\ 'bufferinfo': 'lightline#buffer#bufferinfo',
\ },
\ 'active': {
\ 'left': [ [ 'mode', 'paste' ],
\ [ 'modified', 'fugitive', 'filename' ] ],
\ 'right': [ [ 'lineinfo'],
\ [ 'fileformat', 'fileencoding', 'filetype' ] ]
\ },
\ 'component': {
\ 'mode': '%{lightline#mode()[0]}',
\ 'readonly': '%{&filetype=="help"?"":&readonly?"[!]":""}',
\ 'modified': '%{&filetype=="help"?"":&modified?"[+]":&modifiable?"":"[-]"}',
\ 'fugitive': '%{exists("*fugitive#head")?fugitive#head():""}'
\ },
\ 'component_visible_condition': {
\ 'readonly': '(&filetype!="help"&& &readonly)',
\ 'modified': '(&filetype!="help"&&(&modified||!&modifiable))',
\ 'fugitive': '(exists("*fugitive#head") && ""!=fugitive#head())'
\ }
\ }
nmap <Leader>1 <Plug>lightline#bufferline#go(1)
nmap <Leader>2 <Plug>lightline#bufferline#go(2)
nmap <Leader>3 <Plug>lightline#bufferline#go(3)
nmap <Leader>4 <Plug>lightline#bufferline#go(4)
nmap <Leader>5 <Plug>lightline#bufferline#go(5)
nmap <Leader>6 <Plug>lightline#bufferline#go(6)
nmap <Leader>7 <Plug>lightline#bufferline#go(7)
nmap <Leader>8 <Plug>lightline#bufferline#go(8)
nmap <Leader>9 <Plug>lightline#bufferline#go(9)
nmap <Leader>0 <Plug>lightline#bufferline#go(10)
" }}}
" Vimux {{{
let g:VimuxPromptString = '% ' " change default vim prompt string
let g:VimuxResetSequence = 'q C-u C-l' " clear output before running a command
noremap <Leader>p :VimuxRunCommand("git pull")<Cr>
noremap <Leader>P :VimuxRunCommand("git push")<Cr>
noremap <Leader>rt :VimuxRunCommand("clear;" . &ft . " " . bufname("%"))<Cr>
noremap <Leader>rr :VimuxPromptCommand<Cr>
noremap <Leader>rl :VimuxRunLastCommand<Cr>
noremap <Leader>re :VimuxCloseRunner<Cr>
" }}}
" Splitjoin {{{
let g:splitjoin_split_mapping = '' " reset splitjoin mappings
let g:splitjoin_join_mapping = '' " reset splitjoin mappings
noremap <Leader>j :SplitjoinJoin<Cr>
noremap <Leader>J :SplitjoinSplit<Cr>
" }}}
" Fzf {{{
" use bottom positioned 20% height bottom split
let g:fzf_layout = { 'down': '~20%' }
" only use FZF shortcuts in non diff-mode
if !&diff
nnoremap <C-p> :Files<Cr>
nnoremap <C-g> :Ag<Cr>
endif
" }}}
" Vimagit {{{
noremap <Leader>m :MagitO<Cr>
" }}}
" Easyalign {{{
" some additional easyalign patterns to use with `ga` mapping
let g:easy_align_delimiters = {
\ '?': {'pattern': '?'},
\ '>': {'pattern': '>>\|=>\|>'}
\ }
xmap ga <Plug>(EasyAlign)
nmap ga <Plug>(EasyAlign)
" }}}
" Autocommands {{{
augroup Global
au!
au BufEnter,WinEnter,WinNew,VimResized *,*.*
\ let &scrolloff=getwininfo(win_getid())[0]['height']/2 " keep cursor centered
au VimResized * wincmd = " auto resize splits on resize
augroup END
augroup Files
au!
au BufWritePre * %s/\s\+$//e " remove trailing whitespace
au FileType javascript,jsx,json call s:IndentSize(4) " 4 space indent languages
augroup END
" }}}