-
Notifications
You must be signed in to change notification settings - Fork 0
/
.vimrc
375 lines (296 loc) · 9.6 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
syntax on
let mapleader = "\<Space>"
set background=dark
colorscheme gruvbox
"""""""""""""""""""""""""""""""""""""""""
"""""""""""""""PLUGINS"""""""""""""""""""
"""""""""""""""""""""""""""""""""""""""""
call plug#begin('~/.vim/plugged')
" File Browser
Plug 'scrooloose/nerdtree'
" Commenter
Plug 'tpope/vim-commentary'
" Autocomplete
Plug 'Valloric/YouCompleteMe'
" run make async
Plug 'skywind3000/asyncrun.vim'
" Restore view after opening a file
Plug 'vim-scripts/restore_view.vim'
" Swap windows easily
Plug 'wesQ3/vim-windowswap'
" Open/Close pairs automatically
Plug 'jiangmiao/auto-pairs'
" t/T/f/F over multiple lines
Plug 'dahu/vim-fanfingtastic'
" Auto-formatting for python and everything else
" Plug 'rhysd/vim-clang-format', has('python') ? { 'on': [] } : {}
Plug 'Chiel92/vim-autoformat'
" Improve status line
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
" vim and tmux
Plug 'christoomey/vim-tmux-navigator'
Plug 'benmills/vimux'
" Syntax checking
" Plug 'vim-syntastic/syntastic'
" Plug 'w0rp/ale'
" Change background of hex colors to what they define
Plug 'chrisbra/Colorizer'
" Visualize git commits and status
Plug 'jreybert/vimagit'
call plug#end()
"""""""""""""""""""""""""""""""""""""""""
"""""""""""""PLUGIN SETTINGS"""""""""""""
"""""""""""""""""""""""""""""""""""""""""
"""""" NERDTREE
nnoremap <leader>d :NERDTreeToggle<CR>
autocmd BufEnter * lcd %:p:h
"close vim if the only window left is a NERDTree
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif
" close nerdtree when opening a new window
let g:NERDTreeQuitOnOpen=1
"""""" commentary
nmap <leader>c gc
vmap <leader>c gc
" copy line to above or below and comment the original one out
nmap <leader>cj Ygccp
nmap <leader>ck Ygcckp
autocmd FileType cpp setlocal commentstring=//\ %s
"""""" youcompleteme
let g:ycm_min_num_of_chars_for_completion = 2
set completeopt-=preview
""""" asyncRun
augroup vimrc
autocmd QuickFixCmdPost * botright copen 12
" autocmd QuickFixCmdPre * let g:mybufname=bufname('%')
" autocmd QuickFixCmdPost * botright copen 8 | exec bufwinnr(g:mybufname) . 'wincmd w'
augroup END
" nnoremap <leader>mm :AsyncRun -cwd=<root> make<CR>
" nnoremap <leader>mt :AsyncRun -cwd=<root> make test<CR>
" nnoremap <leader>mc :AsyncRun -cwd=<root> make clean<CR>
nnoremap <leader>mr :AsyncRun -cwd=<root> make run<CR>
" nnoremap <C-c> :AsyncStop<CR>
" Always use the next Makefile above the current program
let g:asyncrun_rootmarks = ['Makefile', '.svn', '.git', '.root', '.bzr', '_darcs', 'build.xml']
" let g:asyncrun_status = "stopped"
" Show status of make command in vim-airline
" let g:airline_section_error = airline#section#create_right(['%{g:asyncrun_status}'])
""""" vimux
nnoremap <leader>mm :VimuxRunCommand("make")<CR>
nnoremap <leader>mt :VimuxRunCommand("make test")<CR>
nnoremap <leader>mc :VimuxRunCommand("make clean")<CR>
nnoremap <leader>mn :VimuxRunCommand("make run FILE=" . expand("%:p"))<CR>
nnoremap <C-c> :VimuxInterruptRunner<CR>
" Orientation of the new window set h or v
let g:VimuxOrientation = "v"
" Select the pane vimux should use for output
map <Leader>v0 :call VimuxSetPane(0)<CR>
map <Leader>v1 :call VimuxSetPane(1)<CR>
map <Leader>v2 :call VimuxSetPane(2)<CR>
map <Leader>v3 :call VimuxSetPane(3)<CR>
map <Leader>v4 :call VimuxSetPane(4)<CR>
map <leader>vv :echo g:VimuxRunnerIndex<CR>
function VimuxSetPane(paneIndex)
let g:VimuxRunnerIndex = a:paneIndex
endfunction
"""""" vim-windowswap
let g:windowswap_map_keys = 0 "prevent default bindings
nnoremap <silent> <leader>yw :call WindowSwap#MarkWindowSwap()<CR>
nnoremap <silent> <leader>pw :call WindowSwap#DoWindowSwap()<CR>
nnoremap <silent> <leader>w :call WindowSwap#EasyWindowSwap()<CR>
""""" vim-autoformat
noremap <Leader>f :Autoformat<CR>
" Set a marker to jump back to position after formatting
" nmap <Leader>F mz:ClangFormatAutoToggle<CR>`z
""""" vim airline
let g:airline_powerline_fonts = 1
let g:airline_section_y = {} "shows the formatting, I don't care about that
let g:airline#extensions#ale#error_symbol="✗ "
let g:airline#extensions#ale#warning_symbol="⚠ "
let g:airline_theme='dark' " or light
let g:powerline_pycmd = "py3"
"""" ale
let g:ale_echo_msg_error_str = '✗'
let g:ale_echo_msg_warning_str = '⚠'
let g:ale_sign_error = '✗'
let g:ale_sign_warning = '⚠'
let g:ale_statusline_format = ['✗ %d', '⚠ %d', '⬥ ok']
let g:ale_open_list = 1
" Close vim if the only window left is a quickfix window
autocmd bufenter * if (&buftype == 'quickfix') | q | endif
" I make mistakes constantly. No need to remind me all the time
let g:ale_lint_on_text_changed = 'never'
" Change compiler options for c++
let ale_cpp_clang_options = '-std=c++14 -Wall -Wno-write-strings'
""""" syntasics
" set statusline+=%#warningmsg#
" set statusline+=%{SyntasticStatuslineFlag()}
" set statusline+=%*
" let g:syntastic_always_populate_loc_list = 1
" let g:syntastic_auto_loc_list = 1
" let g:syntastic_check_on_open = 1
" let g:syntastic_check_on_wq = 0
" let g:syntastic_error_symbol = "✗"
" let g:syntastic_cpp_compiler_options = "-std=c++11 -Wall -Wextra -Wpedantic"
""""" Colorizer
let g:colorizer_x11_names = 1
:let g:colorizer_auto_filetype='css,html'
noremap <leader>CC :ColorToggle<Cr>
"""""""""""""""""""""""""""""""""""""""""
"""""""""""""GENERAL SETTINGS""""""""""""
"""""""""""""""""""""""""""""""""""""""""
" Handle unkown filetypes
autocmd BufEnter,BufNewFile *.tpp :setlocal filetype=cpp
autocmd BufRead,BufNewFile *.njk set filetype=html
" Delete all empty lines in the end
autocmd BufWritePre * :%s/\s\+$//e
" Autosave if focus lost, only supported in terminal version
au BufLeave,FocusLost * :wa
" restore_view needs this
set viewoptions=cursor,folds,slash,unix
set timeoutlen=300
" For smooth scrolling
set so=5
" Show last command
set showcmd
" Show wildmenu TODO: do I want more settings for this?
set wildmenu
" Activate line numbers
set ruler
set nu
set relativenumber
" brace face
set showmatch
set matchtime=3
" More responsive split
set splitbelow
set splitright
" Resize splits when the window is resized
au VimResized * :wincmd =
" change directory when entering file
set autochdir
" Use spaces instead of tabs
set expandtab
" Better intendation
set autoindent
set smarttab
set tabstop=4
set shiftwidth=4
" Searching
set incsearch
set hlsearch
set ignorecase
set smartcase
" Replacing
set gdefault
" vi sucks
set nocompatible
" Improve undo tasks
set history=1000
set undofile
set undodir=~/.vim/undo
set undolevels=2000
set undoreload=10000
" Save swap and backup files neatly at one place
set backupdir=~/.vim/backup
set directory=~/.vim/swapfiles//
" Highlight the 80th column
"highlight ColorColumn guibg=gray15
"let &colorcolumn="80"
let &t_SI = "\<Esc>[6 q"
let &t_SR = "\<Esc>[4 q"
let &t_EI = "\<Esc>[2 q"
" Fix an error with the powerline font
let g:powerline_pycmd="py3"
""""""""""""""KEY MAPPINGS"""""""""""""""
"""""""""""""""""""""""""""""""""""""""""
" noremap <leader>T :! sh /home/jonas/scripts/ctags_with_dep.sh %:p:h/*.hpp %:p:h/*cpp<cr>
inoremap jk <esc>
" Jump easy to beginning/start of line
noremap H ^
noremap L $
" Save current file with enter key
nnoremap <cr> :w<cr>
" Give arrow keys a better purpose
noremap <down> ddp
noremap <up> ddkP
vnoremap <down> dp
vnoremap <down> dkP
" TODO: Folding
setlocal foldmethod=syntax
nnoremap < za
nnoremap > zA
nnoremap <leader>< zM
nnoremap <leader>> zR
autocmd FileType gitcommit setlocal nofoldenable
" more convenient way to use markers
noremap 'a `a
noremap `a 'a
noremap 'b `b
noremap ``b 'b
noremap '. `a
noremap `` ''
" Stop highlighting
nnoremap <esc> :noh<return><esc>
nnoremap <esc>^[ <esc>^[
" Toggle line and column highlighting
nnoremap <leader>hc :set cursorcolumn!<cr>
nnoremap <leader>hl :set cursorline!<cr>
" This will highlight the current line and keep it highlighted even when the cursor moves
" Bonus: 'l will jump to the highlighted line
nnoremap <silent> <leader>hL ml:execute 'match Search /\%'.line('.').'l/'<CR>
nnoremap <leader>hM :match<CR>
" Format json objects
nnoremap <leader>Fj :%!python -m json.tool<CR>
" For split selection
nnoremap <c-h> <c-w>h
nnoremap <c-j> <c-w>j
nnoremap <c-k> <c-w>k
nnoremap <c-l> <c-w>l
" go easily through the loclist
nnoremap <leader>K :lprevious<cr>
nnoremap <leader>J :lnext<cr>
" Double space opens last file again
noremap <leader><leader> :w<CR>:e#<CR>
" Close window
nnoremap <leader>q :q<cr>
" Close terminal mode
:tnoremap <Esc> <C-\><C-n>
" Copy&paste
nnoremap <leader>p "+p
vnoremap <leader>y "+y
" Replace a word witht the earlier yanked text
" Won't delete the yanked word from the buffer
xnoremap p "_dP
" Quickly change to global replace mode
nnoremap <leader>r :%s/
" Quick lines
nnoremap <leader>o o<esc>^Dk
nnoremap <leader>O O<esc>^Dj
" Jump easily between last edits
nnoremap <tab> g;
nnoremap <s-tab> g,
" mapping to make movements operate on 1 screen line in wrap mode
function! ScreenMovement(movement)
if &wrap
return "g" . a:movement
else
return a:movement
endif
endfunction
" Scrolling always fucks up my code
set mouse=a
" Use # as comment string in cmake files
autocmd FileType cmake setl cms=#%s
" Count number of occurences of word under cursor
map <leader>* *<C-O>:%s///n<CR>
onoremap <silent> <expr> j ScreenMovement("j")
onoremap <silent> <expr> k ScreenMovement("k")
onoremap <silent> <expr> 0 ScreenMovement("0")
onoremap <silent> <expr> ^ ScreenMovement("^")
onoremap <silent> <expr> $ ScreenMovement("$")
nnoremap <silent> <expr> j ScreenMovement("j")
nnoremap <silent> <expr> k ScreenMovement("k")
nnoremap <silent> <expr> 0 ScreenMovement("0")
nnoremap <silent> <expr> ^ ScreenMovement("^")
nnoremap <silent> <expr> $ ScreenMovement("$")