-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.vimrc
439 lines (344 loc) · 12.9 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
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
" 88
" ''
" 8b d8 88 88,dPYba,,adPYba, 8b,dPPYba, ,adPPYba,
" `8b d8' 88 88P' '88' '8a 88P' 'Y8 a8' ''
" `8b d8' 88 88 88 88 88 8b
" 888 `8b,d8' 88 88 88 88 88 '8a, ,aa
" 888 '8' 88 88 88 88 88 `'Ybbd8''
" ================================= PLUGINS ================================== "
set nocompatible
filetype off
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" --------------------------------- General ---------------------------------- "
Plugin 'VundleVim/Vundle.vim'
Plugin 'tpope/vim-sensible'
Plugin 'tpope/vim-commentary'
Plugin 'tpope/vim-fugitive'
Plugin 'tpope/vim-surround'
Plugin 'tpope/vim-repeat'
Plugin 'airblade/vim-gitgutter'
Plugin 'scrooloose/nerdtree'
Plugin 'Xuyuanp/nerdtree-git-plugin'
Plugin 'tiagofumo/vim-nerdtree-syntax-highlight'
Plugin 'ctrlpvim/ctrlp.vim'
Plugin 'vim-syntastic/syntastic'
Plugin 'christoomey/vim-tmux-navigator'
Plugin 'wincent/terminus'
Plugin 'junegunn/goyo.vim'
Plugin 'ryanoasis/vim-devicons'
" Plugin 'editorconfig/editorconfig-vim'
" Plugin 'Valloric/YouCompleteMe'
" Plugin 'easymotion/vim-easymotion'
" Plugin 'chriskempson/base16-vim'
" Plugin 'lifepillar/vim-solarized8'
" Plugin 'morhetz/gruvbox'
" --------------------------------- Specific --------------------------------- "
Plugin 'ap/vim-css-color'
Plugin 'pangloss/vim-javascript'
Plugin 'leafgarland/typescript-vim'
Plugin 'mxw/vim-jsx'
Plugin 'posva/vim-vue'
Plugin 'wavded/vim-stylus'
Plugin 'lervag/vimtex' " Install MacTex to get everything you need (latexmk, etc.)
" Plugin 'tpope/vim-fireplace'
" Plugin 'guns/vim-clojure-static'
call vundle#end()
filetype plugin indent on
" ================================= SETTINGS ================================= "
" ---------------------------------- Basics ---------------------------------- "
set encoding=utf8
syntax on
" Relative line numbering
set number
set rnu
" Tab settings
set shiftwidth=4
set tabstop=4
set expandtab
" Only case sensitive search if query contains uppercase characters
" (NOTE: Also affects substitutions)
set ignorecase
set smartcase
" Split below and to the right
set splitbelow
set splitright
" Show tab indentations and trailing spaces
set list
set listchars=tab:\|\ ,trail:•
" Show ruler (see rulerformat)
set ruler
" Show statusbar when more than one window (vim-sensible overrides this though)
set laststatus=1
" Hide buffers
set hidden
" Auto-read file when changed from outside
set autoread
" Show current command
set showcmd
" Highlight current line
set nocursorline
" Highlight column 80
" set colorcolumn=80
" Centralize swapfiles and backups (Make sure the directories exist!)
set directory=~/.vim/swaps//
set backupdir=~/.vim/backups//
" CtrlP
set runtimepath^=~/.vim/bundle/ctrlp.vim
" Enable mouse for focusing, selecting and scrolling
" (hold alt/option in iTerm2 to disable temporarily)
set mouse=a
" " Only show cursorline in current window
" augroup cursorline
" autocmd!
" autocmd VimEnter,WinEnter,BufWinEnter * setlocal cursorline
" autocmd WinLeave * setlocal nocursorline
" augroup END
" ---------------------------------- Colors ---------------------------------- "
" Enable true colors
set t_Co=256
if (has("termguicolors"))
set termguicolors
endif
let &t_8f = "[38;2;%lu;%lu;%lum"
let &t_8b = "[48;2;%lu;%lu;%lum"
" Colorscheme
set background=light
colorscheme kallgren
" -------------------------------- Cursorline -------------------------------- "
" Change color based on mode
function! CursorLineColor(mode)
if a:mode == 'i'
return g:base16_gui0Dt
elseif a:mode == 'r'
return g:base16_gui08t
else
return g:base16_gui01
endif
endfunction
au! InsertEnter
au! InsertLeave
au InsertEnter * execute 'hi CursorLine guibg=#' . CursorLineColor(v:insertmode)
au InsertLeave * execute 'hi CursorLine guibg=#' . g:base16_gui01
" -------------------------------- Statusline -------------------------------- "
" " Change color based on file status (modified, read-only, etc.)
" " TODO: Update at better intervals and make local to the current buffer
" function! StatusLineColor()
" if &mod
" execute 'hi StatusLine guibg=#' . g:base16_gui08t
" else
" execute 'hi StatusLine guibg=#' . g:base16_gui01
" endif
" return ""
" endfun
" au CursorHold,CursorHoldI * call StatusLineColor()
" Returns current git branch (if the active file is in a git repository)
function! GetGitBranch()
if exists('*fugitive#head')
let head = fugitive#head()
if empty(head) && exists('*fugitive#detect') && !exists('b:git_dir')
call fugitive#detect(getcwd()) " TODO: Fix detect call which has been removed
let head = fugitive#head()
endif
if !empty(head)
return ' ' . head
endif
endif
return ''
endfunction
" ------------- EXPERIMENTS ------------- "
" if &bufmodified
" set statusline +=\ %<%#error#%f%* " Relative file path
" else
" set statusline +=\ %<%f " Relative file path
" endif
" let &statusline=' %<%{&mod?"%#error#%f%*":"%f"}%r%{&fenc !~ "^$\\|utf-8" || &bomb ? "[".&fenc.(&bomb?"-bom":"")."]" : ""}%=%15.(%l,%c%V %P%)'
" --------------------------------------- "
" Left
set statusline=%<%f\ %{WebDevIconsGetFileTypeSymbol()}\ " Relative file path
set statusline +=%h " Help buffer flag
set statusline +=%w " Preview window flag
set statusline +=%m " Modified flag
set statusline +=%r " Readonly flag
set statusline +=\ " Space
" Syntastic statusline (TODO: Fix background color)
set statusline+=%#warningmsg#
set statusline+=%{SyntasticStatuslineFlag()}
set statusline+=%*\
" Space
set statusline +=%=
" Right
set statusline +=%{GetGitBranch()}\ " Git branch
set statusline +=%9.(%l,%c%) " Line and column number (9 char width)
" Ruler (for when statusline is hidden)
set rulerformat=%= " Align right
set rulerformat +=%{GetGitBranch()}\ " Git branch
set rulerformat +=%l,%c " Line and column number
" --------------------------------- Plugins ---------------------------------- "
" ctrlp/ctrlp.vim
let g:ctrlp_map = '<c-p>'
let g:ctrlp_cmd = 'CtrlPBuffer'
let g:ctrlp_show_hidden = 1
" scrooloose/nerdtree
let g:NERDTreeShowHidden = 1
" tiagofumo/vim-nerdtree-syntax-highlight
let g:NERDTreeFileExtensionHighlightFullName = 1
let g:NERDTreeExactMatchHighlightFullName = 1
let g:NERDTreePatternMatchHighlightFullName = 1
let g:NERDTreeLimitedSyntax = 1
" ryanoasis/vim-devicons
let g:WebDevIconsNerdTreeAfterGlyphPadding = '' " Better alignment
let g:WebDevIconsNerdTreeBeforeGlyphPadding = ''
let g:WebDevIconsUnicodeDecorateFolderNodes = 1
" let g:DevIconsEnableFoldersOpenClose = 1 " Causes padding issues
" vim-syntastic/syntastic
let g:syntastic_always_populate_loc_list = 1
let g:syntastic_auto_loc_list = 1
let g:syntastic_loc_list_height = 3
let g:syntastic_check_on_open = 1
let g:syntastic_check_on_wq = 0
let g:syntastic_javascript_checkers = ['eslint']
let g:syntastic_javascript_eslint_exe = 'yarn lint --'
" mxw/vim-jsx
let g:jsx_ext_required = 0
" lervag/vimtex
let g:tex_flavor = 'latex'
let g:vimtex_fold_enabled = 1
" ============================= CUSTOM COMMANDS ============================= "
" Toggles between laststatus 1 and 2
let s:show_statusline = 0 " TODO: Visst fixar detta synk-problemet, eller overridar vim-senssible fortfarande? Undersök
function! ToggleStatusLineFuction()
if s:show_statusline == 0
let s:show_statusline = 1
set laststatus=2
else
let s:show_statusline = 0
set laststatus=1
endif
endfunction
" Toggles between dark and light color theme in vim, iterm2 and tmux
" TODO:
" Get the right colors on startup depending on iterm profile:
" Make iterm create/delete the files ~/.dark_colors and ~/.light_colors when switching profile
" Read if file ~/.dark_colors or ~/.light_colors exists and set background accordingly
" Do the same in tmux
" Trigger tmux color change from vim too?
" Optimal: Trigger both vim and tmux reload from apple script executed by iterm?
function! ToggleTerminalColorsFunction()
if &background ==? 'dark'
set background=light
silent !osascript -e 'tell app "System Events" to keystroke "l" using {control down, command down}'
silent !osascript -e 'tell app "System Events" to keystroke space using control down'
silent !osascript -e 'tell app "System Events" to keystroke "l" using control down'
" Faster, but requires knowledge of tmux config location:
" execute "silent !tmux source-file " . shellescape(expand('~/dotfiles/tmuxcolors-light.conf'))
else
set background=dark
silent !osascript -e 'tell app "System Events" to keystroke "k" using {control down, command down}'
silent !osascript -e 'tell app "System Events" to keystroke space using control down'
silent !osascript -e 'tell app "System Events" to keystroke "k" using control down'
" Faster, but requires knowledge of tmux config location:
" execute "silent !tmux source-file " . shellescape(expand('~/dotfiles/tmuxcolors-dark.conf'))
endif
endfunction
command! ToggleStatusLine call ToggleStatusLineFuction()
command! ToggleTerminalColors call ToggleTerminalColorsFunction()
" ================================= BINDINGS ================================= "
" ---------------------------------- Basics ---------------------------------- "
" NERDTree
map <silent> <C-n> :NERDTreeFocus<cr>
" Quick fix / location list window
map <silent> <C-c> :cwindow<cr>
map <silent> <C-x> :lwindow<cr>
nnoremap <silent> <Up> :cprevious<cr>
nnoremap <silent> <Down> :cnext<cr>
nnoremap <silent> <Left> :cpfile<cr>
nnoremap <silent> <Right> :cnfile<cr>
nnoremap <silent> <leader>lp :lprevious<cr>
nnoremap <silent> <leader>ln :lnext<cr>
" Window navigation
let g:tmux_navigator_no_mappings = 1
nnoremap <silent> <C-h> :TmuxNavigateLeft<cr>
nnoremap <silent> <C-j> :TmuxNavigateDown<cr>
nnoremap <silent> <C-k> :TmuxNavigateUp<cr>
nnoremap <silent> <C-l> :TmuxNavigateRight<cr>
nnoremap <silent> <C-ö> :TmuxNavigatePrevious<cr>
" ---------------------------------- Leader ---------------------------------- "
let mapleader=","
nmap <leader>q :q<cr>
nmap <leader>d :bd<cr>
nmap <leader>t :tabnew<cr>
" nmap <leader>s :let &laststatus = ( &laststatus == 1 ? 2 : 1 )<cr>
nmap <leader>s :ToggleStatusLine<cr>
nmap <leader>bg :ToggleTerminalColors<cr>
nmap <leader>bl :set background=light<cr>:colorscheme kallgren<cr>
nmap <leader>bk :set background=dark<cr>:colorscheme kallgren<cr>
" Check/uncheck todo-list items
nmap <leader>x mm_f-rx`m
nmap <leader>- mm_fxr-`m
" Open .vimrc (Bypass symlink to make fugitive work properly)
nmap <leader>ev :execute 'tabedit ' . resolve(expand($MYVIMRC))<cr>
" Open .tmux.conf
nmap <leader>et :tabedit ~/.tmux.conf<cr>
" Open .zshrc
nmap <leader>ez :tabedit ~/.zshrc<cr>
" Find in files (type search term, change **, run the command and then :lw)
" nmap <leader>f :lvimgrep //gj **<Left><Left><Left><Left><Left><Left>
" Find in files in git repository (type search term, run the command, and then
" navigate through the quickfix list (:copen, :cn, etc.))
nmap <leader>f :Ggrep
" Spell checking & latex related
nmap <leader>w ]s
nmap <leader>W [s
nmap <leader>r 1z=
nmap <leader>l :setlocal spell spelllang=en_gb<cr>
xnoremap <leader>m <ESC>`>a}<ESC>`<i{\color{red} <ESC>
" tpope/vim-fugitive
nnoremap <leader>gs :Gstatus<cr>
nnoremap <leader>gd :Gvdiff<cr>
nnoremap <leader>gb :Gblame<cr>
nnoremap <leader>gw :Gbrowse<cr>
nmap <leader>hn <Plug>(GitGutterNextHunk)
nmap <leader>hp <Plug>(GitGutterPrevHunk)
nmap <leader>hs <Plug>(GitGutterStageHunk)
nmap <leader>hu <Plug>(GitGutterUndoHunk)
nmap <leader>hv <Plug>(GitGutterPreviewHunk)
" scrooloose/nerdtree
map <leader>n :NERDTreeFind<cr>
" junegunn/goyo.vim
nnoremap <leader>z :Goyo<cr>
" ------------------------------- Insert mode -------------------------------- "
" Autocomplete closing tag
imap <C-c> </<C-X><C-O><Esc>F<i
" ------------------------------- Text objects ------------------------------- "
omap ih <Plug>GitGutterTextObjectInnerPending
omap ah <Plug>GitGutterTextObjectOuterPending
xmap ih <Plug>GitGutterTextObjectInnerVisual
xmap ah <Plug>GitGutterTextObjectOuterVisual
" ============================ SESSION MANAGEMENT ============================ "
" function! MakeSession()
" let b:sessiondir = $HOME . "/.vim/sessions" . getcwd()
" if (filewritable(b:sessiondir) != 2)
" exe 'silent !mkdir -p ' b:sessiondir
" redraw!
" endif
" let b:filename = b:sessiondir . '/session.vim'
" exe "mksession! " . b:filename
" endfunction
" function! LoadSession()
" let b:sessiondir = $HOME . "/.vim/sessions" . getcwd()
" let b:sessionfile = b:sessiondir . "/session.vim"
" if (filereadable(b:sessionfile))
" exe 'source ' b:sessionfile
" else
" echo "No session loaded."
" endif
" endfunction
" au VimEnter * nested :call LoadSession()
" au VimLeave * :call MakeSession()
" ======================== AUTO-SOURCE .VIMRC ON SAVE ======================== "
augroup autosourcing
autocmd!
autocmd BufWritePost *vimrc source $MYVIMRC
autocmd BufWritePost *vimrc execute webdevicons#hardRefresh()
augroup END