-
Notifications
You must be signed in to change notification settings - Fork 3
/
.vimrc
356 lines (301 loc) · 10.2 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
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
" LOAD_VIM_PLUGINS
filetype plugin on
filetype plugin indent on
" Load plugins
if filereadable(expand("~/.vimrc.bundles"))
source ~/.vimrc.bundles
endif
"===============================================================================
" BASE_SETTINGS
au BufWritePost * :silent! :syntax sync fromstart<cr>:redraw!<cr>
" Map leader to space
let mapleader = " "
" Don't wrap lines
set linebreak
" Display extra whitespace
set list listchars=tab:»·,trail:·
" Make it obvious where 120 characters is
set textwidth=120
set colorcolumn=+1
" Turn off the auto-newline
set fo-=t
" GitGutter Config
set updatetime=300
" Make it so clipboard copy/paste works with Mac OSX
set clipboard=unnamedplus
" ignorecase when searching
set ignorecase " @n
" If any capitals are used search by case
set smartcase " @n
" Infer the case
set infercase " @n
" Make sure cursor stays centered on the screen
set scrolloff=999
" Put filename in statusline
set statusline+=%{fugitive#statusline()}
set statusline+=%{LinterStatus()}
" Paste Toggle
set pastetoggle=<F2>
set showmode
" It's useful to show the buffer number in the status line.
set laststatus=2 statusline=%02n:%<%f\ %h%m%r%=%-14.(%l,%c%V%)\ %P
" Proper splits
set splitbelow
set splitright
" Wildmenu
set wildmode=longest:full
set backupcopy=yes
" Go up the tree until we find a tags file"{{{
"set tags=./tags;/
" Sane level for syntax highlight"}}}
set synmaxcol=300 "@n
" Lazy Redraw
set lazyredraw "@n
" Automatically read the file if it changed outside vim @n
set modeline
set modelines=1
" Flash matching braces for 200ms @n
set showmatch
set matchtime=2
" When joining lines, delete comment characters if appropriate"{{{
"set formatoptions+=j"}}}
set nojoinspaces
set shell=/usr/local/bin/zsh
if !has('nvim')
set nocompatible
set backspace=indent,eol,start
set incsearch
set laststatus=2 " always show status line
set wildmenu
set smarttab
end
" Automatically strip whitespace on save.
autocmd BufWritePre * StripWhitespace
" Resize splits when vim itself is resized @n
augroup ResizeSplits
au!
au VimResized * :wincmd =
augroup END
" Only display the cursorline on windows that are in focus
augroup highlight_follows_focus
autocmd!
au WinEnter * set cursorline
au WinLeave * set nocursorline
au FocusGained * set cursorline
au FocusLost * set nocursorline
augroup END
" Don't open gutentags with gitcommits or rebases https://github.com/ludovicchabant/vim-gutentags/issues/168
au FileType gitcommit,gitrebase let g:gutentags_enabled=0
let g:gutentags_project_root = ['.root']
"===============================================================================
" REMAPS"{{{
" Scratch file"}}}
nn <F1> :Scratch<CR>
" Paste
nn <F2> :set invpaste paste?<CR>
" Copy filename to clipboard (with path)
nn <F4><silent> :let @+=expand("%:p")<CR>
" Spellcheck
nn <F7> :setlocal spell! spell?<CR>
" Tagbar
nn <F8> :TagbarToggle<CR>
map <leader>b :Buffers<CR>
map f <Plug>Sneak_s
"These are to cancel the default behavior of d, D, c, C"{{{
" to put the text they delete in the default register.
" Note that this means e.g. "ad won't copy the text into
" register a anymore. You have to explicitly yank it."}}}
nnoremap d "_d
vnoremap d "_d
nnoremap D "_D
vnoremap D "_D
nnoremap c "_c
vnoremap c "_c
nnoremap C "_C
vnoremap C "_C
" Remap H and L to start and end of the line
nnoremap H ^
nnoremap L $
xnoremap H ^
xnoremap L $
" Shift-X repeats the x macro
nnoremap X @x
xnoremap X :normal! @x<CR>
" Ranger
" On escape go back to last opened buffer
"tnoremap <Esc> <C-\><C-n>:b#<CR>
" Make sure we can still navigate panes alright
"tnoremap <C-w> <C-\><C-n><C-w>
"===============================================================================
" LEADER_MAPS"{{{
" Faster tab movement
nmap <silent> <Leader>h :tabprev<CR>
nmap <silent> <Leader>l :tabnext<CR>
nmap <silent> <Leader>c :tabnew<CR>
nmap <silent> <Leader>x :tabclose<CR>
nmap <Leader>u :UndotreeToggle<CR>
" <leader>a selects the whole buffer
nnoremap <leader>a ggVG
" <leader>e clears previous search highlighting
nnoremap <silent> <leader>e :noh<CR>
" <leader>w cds to the current directory in netrw
nnoremap <silent> <leader>w :cd %<CR>
" Restore previous session
nnoremap <silent> <leader>r :call RestoreSess()<CR>
" Remap Esc to Ctrl+l in interactive mode
imap <C-l> <Esc>
"===============================================================================
" SYNTAX_COLORS"{{{
" Switch syntax highlighting on, when the terminal has colors"}}}
if (&t_Co > 2 || has("gui_running")) && !exists("syntax_on")
syntax on
endif
" Color overrides"{{{
"set background=dark"}}}
syntax enable
"colorscheme gruvbox
if filereadable(expand("~/.vimrc_background"))
let base16colorspace=256
"if !exists('g:colors_name') || g:colors_name != 'base16-gruvbox-dark-hard'
" colorscheme base16-gruvbox-dark-hard
"endif
endif
set termguicolors
hi Pmenu guibg=#b16286
" twig highlighting
au BufRead,BufNewFile *.twig set filetype=htmljinja
au BufRead,BufNewFile *.rabl set filetype=ruby
hi Folded guibg=#333333 guifg=#333333
hi CursorLine guibg=#333333
hi Comment guifg=#555555
hi Search ctermfg=108 ctermbg=235 guifg=#a89984 guibg=#444444
"===============================================================================
" Lion alignment
let g:lion_squeeze_spaces = 1
let b:lion_squeeze_spaces = 1
"==============================================================================="{{{
" SAVE_PERSISTENT_UNDOS
" Make sure undos are persistent even after exit"}}}
set nobackup
set nowritebackup
set noswapfile
if !&diff
if !has('nvim')
set undodir=~/.vim/undodir
end
set undofile
endif
"==============================================================================="{{{
" CODE_INDENTATION
" Softtabs, 4 spaces by defaults"}}}
set tabstop=2 softtabstop=0 shiftwidth=2 expandtab
" Switch to a 2 space tab on these files
"autocmd FileType sass,scss,ruby,erb,yml,yaml,json,js,html setlocal shiftwidth=2 tabstop=2
set shiftround
set expandtab
set smartindent
"==============================================================================="{{{
" AIRLINE
" Set airline top tab and colors"}}}
let g:airline#extensions#tabline#enabled = 1
let g:airline#extensions#tabline#buffer_nr_show = 1
let g:airline_powerline_fonts = 1
let g:airline#extensions#tabline#show_tab_type = 0
let g:airline#extensions#tabline#fnamemod = ':t'
let g:airline#extensions#ale#enabled = 1
"==============================================================================="{{{
"FZF_AND_RIPGREP (Fuzzy finding)
" C-P calls FZF on all files"}}}
nnoremap <C-P> :Files<CR>
" bind C-f to grep word under cursor
nnoremap <C-f> :Findi <C-R><C-W><CR>
" bind Shift-k to find word under cursor while respecting gitignore
"nnoremap K :Find <C-R><C-W><CR>
" -g '!tags': always ignore the tags file"{{{
" --column: Show column number
" --line-number: Show line number
" --no-heading: Do not show file headings in results
" --fixed-strings: Search term as a literal string
" --ignore-case: Case insensitive search
" --no-ignore: Do not respect .gitignore, etc...
" --hidden: Search hidden files and folders
" --follow: Follow symlinks
" --glob: Additional conditions for search (in this case ignore everything in the .git/ folder)
" --color: Search color options"}}}
command! -bang -nargs=* Find call fzf#vim#grep('rg -g "!tags" --column --line-number --no-heading --fixed-strings --ignore-case --no-ignore --hidden --follow --glob "!.git/*" --color "always" '.shellescape(<q-args>).'| tr -d "\017"', 1, <bang>0)
" Same as above, just respect gitignore
command! -bang -nargs=* Findi call fzf#vim#grep('rg --column --line-number --no-heading --fixed-strings --ignore-case --hidden --follow --glob "!.git/*" --color "always" '.shellescape(<q-args>).'| tr -d "\017"', 1, <bang>0)
let g:fzf_colors =
\ { 'fg': ['fg', 'GruvboxOrange'],
\ 'bg': ['bg', 'CursorLineNr'] }
"===============================================================================
" EXPLORER"{{{
" set default list style for Explore"}}}
let g:netrw_liststyle=4
let g:netrw_bufsettings = 'noma nomod nu nowrap ro nobl'
"===============================================================================
" VIM_REST_CONSOLE"{{{
" Allow request body on get requests"}}}
let g:vrc_allow_get_request_body = 1
let g:vrc_connect_timeout = 600
"==============================================================================="{{{
" VIM SKELETONS"}}}
let skeletons#autoRegister = 1
let skeletons#skeletonsDir = "~/.vim/skeletons"
"==============================================================================="{{{
" ROOTER"}}}
let g:rooter_silent_chdir = 1
let g:rooter_patterns = ['.root', '.git/']
"==============================================================================="{{{
" LINE_NUMBERS"}}}
set number
set relativenumber
set numberwidth=5
set cursorline
function! NumberToggle()
:exec &nu==1 ? "se rnu!" : "se rnu"
endfunction
function! NumberOffToggle()
:exec &nu==1 ? "se nu!" : "se nu"
endfunction
"C-n swap relative number
nnoremap <silent> <Leader>n :call NumberToggle()<CR>
nnoremap <silent> <Leader>N :call NumberOffToggle()<CR>
"==============================================================================="{{{
" CODE_FOLDEING"}}}
nn <silent> <Leader>] za
set foldmethod=syntax
set foldlevel=99
set foldlevelstart=99
autocmd FileType ruby,eruby
\ set foldmethod=expr |
\ set foldexpr=getline(v:lnum)=~'^\\s*#'
"==============================================================================="{{{
" SESSIONS"}}}
if has('nvim')
fu! SaveSess()
execute 'mksession! ' . getcwd() . '/.session.nvim'
endfunction
fu! RestoreSess()
if filereadable(getcwd() . '/.session.nvim')
execute 'so ' . getcwd() . '/.session.nvim'
if bufexists(1)
for l in range(1, bufnr('$'))
if bufwinnr(l) == -1
exec 'sbuffer ' . l
endif
endfor
endif
endif
endfunction
autocmd VimLeave * call SaveSess()
"autocmd VimEnter * nested call RestoreSess()
end
"let g:ranger_replace_netrw = 1
"==============================================================================="{{{
" RSPEC"}}}
map <Leader>rsf :call RunCurrentSpecFile()<CR>
map <Leader>rs :call RunNearestSpec()<CR>
map <Leader>rsl :call RunLastSpec()<CR>
map <Leader>rsa :call RunAllSpecs()<CR>
set guicursor=