summaryrefslogtreecommitdiff
path: root/vimrc
blob: 79300c5c297b7566c9148fba08c202447413e114 (plain)
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
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539

execute pathogen#infect()

call plug#begin('~/.vim/plugged')
Plug 'junegunn/vim-easy-align'
call plug#end()

" Start interactive EasyAlign in visual mode (e.g. vipga)
xmap ga <Plug>(EasyAlign)
" Start interactive EasyAlign for a motion/text object (e.g. gaip)
nmap ga <Plug>(EasyAlign

filetype plugin indent on
" To ignore plugin indent changes, instead use:
"filetype plugin on

color default

"syntax clear
syntax on
"Seems to fuck up symlinks when set to no... [Debian bug #158657]
set backupcopy=yes

"Set improve Backspace
set backspace=2
"Show the current edition mode on last line, number of column and line
set showmode
set ruler
"Show line numbers
set number
set laststatus=2
"set rnu "use relative line numbers to cursor

function! MyTabLine()
	let s = ''
	for i in range(tabpagenr('$'))
	" select the highlighting
	if i + 1 == tabpagenr()
		let s .= '%#TabLineSel#'
	else
		let s .= '%#TabLine#'
	endif
	" set the tab page number (for mouse clicks)
	let s .= '%' . (i + 1) . 'T'
	" the label is made by MyTabLabel()
	let s .= ' %{MyTabLabel(' . (i + 1) . ')} '
	endfor
	" after the last tab fill with TabLineFill and reset tab page nr
	let s .= '%#TabLineFill#%T'
	" right-align the label to close the current tab page
	"if tabpagenr('$') > 1
	"  let s .= '%=%#TabLine#%999Xclose'
	"endif
	return s
endfunction

function! MyTabLabel(n)
  let buflist = tabpagebuflist(a:n)
  let winnr = tabpagewinnr(a:n)
  return bufname(buflist[winnr - 1])
endfunction

" Show current C function name
fun! ShowFuncName()
	let lnum = line(".")
	let col = col(".")
	echohl ModeMsg
	echo getline(search("^[^ \t#/]\\{2}.*[^:]\s*$", 'bWn'))
	echohl None
	call search("\\%" . lnum . "l" . "\\%" . col . "c")
endfun

"set statusline=%y─┤\ %*%1*%<%f%*\ %2*%M%3*%r%*├%=┤%4*%c%V%*├─┤%4*%l/%L%*├──┤%4*%P%*├─
set statusline=┤\ %*%1*%<%f%*\ %2*%M%3*%r%*│%Y├%=┤%c%1*%V%*│%l%*%1*/%L%*│%1*%p%%%*├

set tabline=%!MyTabLine()

set wildmode=longest,list,full

" Set Auto-indentation
"set autoindent
"set cindent

" Make command line X lines high
set cmdheight=1

" Highlight search strings
set hlsearch
" Incremental search
set incsearch
" No wrap search
set nowrapscan

" Hide mouse when typing
set mousehide

" highlighting strings inside C comments
let c_comment_strings=1

" Backup dir
set autowrite

set splitright
set splitbelow

" default error format
"set efm=\"%f\"\\,\ line\ %l:\ error\ %m,\"%f\"\\,\ line\ %l:\ warning\ %m

" Dim inactive windows using 'colorcolumn' setting
" This tends to slow down redrawing, but is very useful.
" Based on https://groups.google.com/d/msg/vim_use/IJU-Vk-QLJE/xz4hjPjCRBUJ
" XXX: this will only work with lines containing text (i.e. not '~')
"if v:version > 703
"function! s:DimInactiveWindows()
"  for i in range(1, tabpagewinnr(tabpagenr(), '$'))
"    let l:range = ""
"    if i != winnr()
"      if &wrap
"        " HACK: when wrapping lines is enabled, we use the maximum number
"        " of columns getting highlighted. This might get calculated by
"        " looking for the longest visible line and using a multiple of
"        " winwidth().
"        let l:width=256 " max
"      else
"        let l:width=winwidth(i)
"      endif
"      let l:range = join(range(1, l:width), ',')
"    endif
"    call setwinvar(i, '&colorcolumn', l:range)
"  endfor
"endfunction
"augroup DimInactiveWindows
"  au!
"  au WinEnter * call s:DimInactiveWindows()
"augroup END
"endif
"
" remaps C-j & C-k to C-y and C-e (buffer up/down line-by-line)
noremap <C-k> <C-y>
noremap <C-j> <C-e>

set nowrap
noremap <C-l> z2l
noremap <C-h> z2h
noremap j gj
noremap k gk
noremap gj j
noremap gk k

"Macros
"nmap <F2>	mc:%s/[\t ]\+$//<CR>'c
nmap <F2>	:make<CR>
" folding
set foldmethod=indent
set foldignore=
augroup Folding
	au!
	autocmd FileType c\|cpp		setlocal foldmethod=syntax
	autocmd FileType mail		setlocal foldmethod=expr
	autocmd FileType mail		setlocal foldexpr=(strlen(substitute(matchstr(getline(v:lnum),\"^\ *[>\ ]*\"),\"\ *\",\"\",\"g\")))
augroup END

set foldminlines=0
set foldcolumn=0
set foldlevel=999

augroup Lilo
	au!
	autocmd BufEnter */etc/lilo*		set syntax=lilo
augroup END

" Quick search for merges
nmap <F1>   /^\(<\{7\}\\|>\{7\}\\|=\{7\}\)<CR>

nmap <F4>   :windo set invrelativenumber<CR>

"nmap <F6>	:setlocal foldcolumn-=1<CR>:execute 'setlocal foldlevel='.(&foldcolumn - 2)<CR>
"nmap <F7>	:setlocal foldcolumn+=1<CR>:execute 'setlocal foldlevel='.(&foldcolumn - 2)<CR>
"nmap <F6>	:windo set foldcolumn-=1<CR>
"nmap <F7>	:windo set foldcolumn+=1<CR>
nmap <F6>	:set textwidth-=1<CR>
nmap <F7>	:set textwidth+=1<CR>
" open all
"nmap <F6>	zR
" close all
"nmap <F7>	zM
" open/close under cursor
nmap ;		za
" open/close recursive under cursor
"nmap <F7>	zA
"nmap <F5>	:windo set invfoldenable<CR>
nmap <F5>	:set invet<CR>

"buffer moving
nmap <ESC>h	:tabN<CR>
nmap <ESC>j	:bn<CR>
nmap <ESC>k	:bN<CR>
nmap <ESC>l	:tabn<CR>

augroup Skeleton
  au!
  " read in skeleton files
  autocmd BufNewFile *.* silent! 0r ~/.vim/skel/%:e
  autocmd BufNewFile *   silent! %substitute#<+\(.\{-\}\)+>#\=eval(submatch(1))#ge
  " get to cursor position
  autocmd BufNewFile *   silent! %substitute#<=CURSOR=>##g
augroup END

augroup Load
	au!
	" When editing a file, always jump to the last known cursor position.
	" Don't do it when the position is invalid or when inside an event handler
	" (happens when dropping a file on gvim).
	autocmd BufReadPost *
		\ if line("'\"") > 0 && line("'\"") <= line("$") |
		\   exe "normal g`\"" |
		\   exe "normal zz" |
		\ endif
augroup END

function! CscopeSearch(csearch)

	let @/=a:csearch
	set hls

	let l:prompt =  "Rechercher '".a:csearch."' avec cscope [acdefgist] : "

	echo l:prompt
	let l:ctype=nr2char(getchar())
	redraw
	echo l:prompt.l:ctype." "

	return 'set hls | cscope find '.l:ctype.' '.a:csearch
endfunction

function! LoadTags()
	" Load local cscope db if exists
	if filereadable( expand("$PWD/tags") )
		set tags=tags
	elseif filereadable( expand("$PWD/ctags.out") )
		set tags=$pwd/ctags.out
	elseif has("cscope")
        set cst
		if filereadable( expand("$PWD/cscope.out") )
			cscope add $PWD/cscope.out
		endif
        let l:git  = system("dirname $(git rev-parse --git-dir) | tr -d '\n'")
        if filereadable ( l:git . '/cscope.out' ) && l:git != expand("$PWD")
            exe 'cscope add ' . l:git . ' ' . l:git
        endif

		" cscope macros
		nmap <ESC>C :!cscope -bqu<CR>:cs reset<CR>
		nmap <ESC>c :execute CscopeSearch(expand("<cword>"))<CR>

		" search definitions of word under cursor
		nmap <ESC>g :cs find g <cword><CR>
		nmap <ESC>S :cs find s <cword><CR>

		" search file under cursor
		"nmap <ESC>f :execute CscopeSearch(expand("<cfile>"))<CR>
		nmap <ESC>F :execute CscopeSearch(expand("<cfile>"))<CR>
		nmap <ESC>f :cs find f <cfile><CR>

		" search current file
		nmap <ESC>% :execute CscopeSearch(expand("%:t"))<CR>
		"nmap <ESC>% :cs find i %:t<CR>

		nmap <ESC>r :execute CscopeSearch(input("Rechercher : "))<CR>
	endif
endfunction
call LoadTags()

augroup WhiteSpaces
	" F*cking whitespaces
	function! HighLightExtraSpacesAndColumns()
		highlight ExtraWhitespace ctermbg=160 ctermfg=none guibg=red
        match ExtraWhitespace /\s\+$\| \+\ze\t/
		if &textwidth != 0
			execute 'match ExtraWhitespace /\s\+$\| \+\ze\t\|\%>'.&textwidth.'v.\+/'
		endif
	endfunction
	autocmd BufRead   *         call HighLightExtraSpacesAndColumns()
	autocmd OptionSet textwidth call HighLightExtraSpacesAndColumns()
augroup END

set colorcolumn=+1
hi colorcolumn ctermbg=none ctermfg=238 cterm=bold,underline

set list listchars=tab:│ ,precedes:‥,extends:‥,nbsp:␣
set fillchars=vert:│,stl:─,stlnc:─,fold:-,diff:x
nmap <F3>	:set invlist<CR>

set title
set autoindent
set diffopt=iwhite,filler,vertical

" mouse
"	v -> enabled in visual mode
"	i -> enabled in insert mode
"	c -> enabled in command mode
"	a -> enabled in all modes

set mouse=a
set mousem=extend

set tabstop=4
set softtabstop=0
set shiftwidth=4
set noexpandtab
set copyindent
set nopreserveindent
set smarttab

let g:detectindent_preferred_expandtab = 0
let g:detectindent_preferred_indent = 4
let g:detectindent_preferred_when_mixed = 1
augroup DetectIndentation
	autocmd BufRead * DetectIndent
augroup END

" Draws underline (waits for char input)
noremap U		yyp0<C-v>$r

set ttimeoutlen=0
set timeoutlen=250

" Code comment/uncomment
 noremap <silent> //    m"I// <ESC>g`"3l
 noremap <silent> /*    m"I/* <ESC>A */<ESC>jg`"3l
"    xmap <silent> //    /*
xnoremap <silent> //    <ESC>`>o#endif<ESC>`<O#if 0<ESC>
xnoremap <silent> /*    <ESC>`>a */<ESC>`<i/* <ESC>
 noremap <silent> \*    m"e?/\* <CR>xxx/ \*\/<CR>xxx:nohl<CR>jg`"3h
 noremap <silent> \\    m"0:s:// *::\|:nohl<CR>g`"3h
 noremap <silent> /<CR> :NERDTreeToggle<CR>

" You can use other keymappings like <C-l> instead of <CR> if you want to
" use these mappings as default search and somtimes want to move cursor with
" EasyMotion.
function! s:incsearch_config(...) abort
	return incsearch#util#deepextend(deepcopy({
		\   'modules': [incsearch#config#easymotion#module({'overwin': 1})],
		\   'keymap': {
			\   "\<C-l>": '<Over>(easymotion)'
		\   },
		\   'is_expr': 0
	\ }), get(a:, 1, {}))
endfunction

noremap <silent><expr> /  incsearch#go(<SID>incsearch_config())
noremap <silent><expr> ?  incsearch#go(<SID>incsearch_config({'command': '?'}))
noremap <silent><expr> g/ incsearch#go(<SID>incsearch_config({'is_stay': 1}))

" FuzzyFinder
map ff <ESC>:FufFile<CR>
map fd <ESC>:FufDir<CR>
map fb <ESC>:FufBuffer<CR>

map ft <ESC>:FufTagWithCursorWord!<CR>

let g:EasyMotion_do_mapping = 0 " Disable default mappings

let mapleader=" "
" Jump to anywhere you want with minimal keystrokes, with just one key binding.
" `s{char}{label}`
nmap <Leader><Leader> <Plug>(easymotion-overwin-f)
" or
" `s{char}{char}{label}`
" Need one more keystroke, but on average, it may be more comfortable.
nmap <Leader><Leader> <Plug>(easymotion-overwin-f2)

" Turn off case insensitive feature
let g:EasyMotion_smartcase = 0

" JK motions: Line motions
map <Leader>j <Plug>(easymotion-j)
map <Leader>k <Plug>(easymotion-k)



" Reformatting is done using 'gq<motion>'
noremap <ESC>Q	:s/^/> /<CR>
noremap <ESC>q	:s/^[ ]*>[ ]*//<CR>

noremap <silent> <ESC>u	:noh<CR>

runtime! ftplugin/man.vim
noremap K		:Man <C-R>=expand("<cword>")<CR><CR>
let g:ft_man_open_mode = 'vert'


" Function
"	Erase_Sig_but_Your()
"
" Author
"	Yann Kerhervé <yk@cyberion.net>
"	Based on Luc Hermitte <hermitte@free.fr> work
"
" Purpose
"	Deletes signatures at the end of e-mail replies. But keep
"	your sig intact (mutt-added).
"	Also deletes the empty lines (even those beginning by '>')
"	preceding the signature.
"
function! Erase_Sig_but_Your()
	" Search for the signature pattern : "^> -- $"
	let lastline = line ('$')
	let i = lastline
	" (1)
	while i >= 1
		if getline(i) =~ '^> *-- $'
			break
		endif
		let i = i - 1
	endwhile
	" let find the beginning of our sig
	let j = i
	while j < lastline
		let j = j + 1
		if getline(j) =~ '^-- $'
			let j = j - 1
			break
		endif
	endwhile
	" If (1) found, then
	if i != 0
		" First, search for the last non empty (non sig) line
		while i >= 1
			let i = i - 1
			" rem : i can't value 1
			if getline(i) !~ '^(>s*)*$'
				break
			endif
		endwhile
		" Second, delete these lines plus the signature
		let i = i + 1
		exe 'normal '.i.'Gd'.j.'G'
	endif
endfunction

function! GitBlameCurrentLine()
	let l:line  = line('.')
	let l:file  = expand("%:t")
	let l:wd	= expand("%:p:h")
	let content = system("cd " . l:wd . ";git blame -L ". l:line . "," . l:line . " " . l:file . " | sed 's/).*/)/'")
	let line = split(content, '\n')[0]
	echohl WarningMsg | echo line | echohl None
endfunction
command! GitBlameCurrentLine :call GitBlameCurrentLine()
noremap <ESC>b :GitBlameCurrentLine<CR>

augroup MailEditor
	au!

	" Highlights columns 77-80 and 81+
	autocmd BufRead /tmp/mutt-*[0-9]	let w:m1=matchadd('Search', '\%>77v,\+', -1)
	autocmd BufRead /tmp/mutt-*[0-9]	let w:m2=matchadd('ErrorMsg', '\%>81v,\+', -1)

	" <ESC>n	goto next empty reply-to paragraph
	" <ESC>m	opens an empty reply-paragraph at this line
	" <ESC>d	deletes everything until but the signature
	" <ESC>w	reformats entire mail but the signature
	" <ESC>D	deletes everything until but the previous reply-to §
	autocmd FileType mail noremap <ESC>n /^> $<CR>
	autocmd FileType mail noremap <ESC>D ^d?^\([^>]\\|$\)?+<CR>O<ESC>
	autocmd FileType mail noremap <ESC>d ^d/^-- $<CR>O<ESC>
	autocmd FileType mail noremap <ESC>w ggv/^-- $<CR><UP>:!par rTbgqRe 'B=.,?_A_a' 'Q=_s>\|'<CR>

	set spelllang=fr,en,de
	autocmd FileType mail setlocal spell
	autocmd FileType mail setlocal textwidth=74
	autocmd FileType mail execute Erase_Sig_but_Your()

	autocmd FileType mail :normal ,n
augroup END

noremap zc	z=1<CR><CR>

"function! SetPythonTabs(tabsize)
"	execute 'setlocal tabstop=' . a:tabsize
"	execute 'setlocal softtabstop=' . a:tabsize
"	execute 'setlocal shiftwidth=' . a:tabsize
"	setlocal smarttab
"	setlocal expandtab
"endfunction

""
"" DafUq ?
""--------
"augroup Tabs
"	au!
"	autocmd FileType python execute SetPythonTabs(4)
"augroup END
"

augroup CursorLine
	au!

	" when switching between buffers
	autocmd BufEnter * set cursorline
	autocmd BufLeave * set nocursorline

	" when switching between windows
	autocmd WinEnter * set cursorline
	autocmd WinLeave * set nocursorline

	" doesn’t seem to work on urxvt :(
	autocmd FocusLost * set nocursorline
	autocmd FocusGained * set cursorline
augroup END

" footnotes
noremap ,, <Esc>:call VimFootnotes()<CR>
noremap ,. <Esc>:exe b:pos<CR>

function! VimFootnotes()
	if exists("b:vimfootnotenumber")
		let b:vimfootnotenumber = b:vimfootnotenumber + 1
		let cr = ""
	else
		let b:vimfootnotenumber = 1
		let cr = "\<CR>"
	endif
	let b:pos = line('.').' | normal! '.virtcol('.').'|'.'4l'
	exe "normal a[".b:vimfootnotenumber."]\<Esc>G"
	if search("-- $", "b")
		exe "normal O".cr."[".b:vimfootnotenumber."] "
	else
		exe "normal o".cr."[".b:vimfootnotenumber."] "
	endif
	startinsert!
endfunction

augroup Todo
	au!
	autocmd FileType vimwiki set syn=todo
augroup END