summaryrefslogtreecommitdiff
path: root/vimrc
blob: 700b23130a2d55ccae51de027deeef80c806dd1a (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

color red

"syntax clear
syntax on
"Allow special Vim improvements like multiple-undo
set nocompatible
"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 Auto-indentation
"set autoindent
"set cindent

" Make command line X lines high
set cmdheight=1

" Highlight search strings
set hlsearch
" Incremental search
set incsearch

" Hide mouse when typing
set mousehide

" highlighting strings inside C comments
let c_comment_strings=1

" Backup dir
set autowrite

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

" 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>

"Macros
map <F2>	:source ~/.vim/bépo

" folding
set foldmethod=indent
set foldignore=
autocmd BufRead *.[ch] setlocal foldmethod=syntax
autocmd BufRead /tmp/mutt-*[0-9] setlocal foldmethod=expr
autocmd BufRead /tmp/mutt-*[0-9] setlocal foldexpr=(strlen(substitute(matchstr(getline(v:lnum),\"^\ *[>\ ]*\"),\"\ *\",\"\",\"g\")))
set foldminlines=0
set foldcolumn=5
set foldlevel=999
map <F7>	:setlocal foldcolumn-=1<CR>:execute 'setlocal foldlevel='.(&foldcolumn - 2)<CR>
map <F8>	:setlocal foldcolumn+=1<CR>:execute 'setlocal foldlevel='.(&foldcolumn - 2)<CR>
map <F9>	za
map <F10>	:setlocal invfoldenable<CR>

"buffer moving
map <C-B>	:bN<CR>

" 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

" 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")
	if filereadable( expand("$PWD/cscope.out") )
		set cst
		" cscope macros
		map <C-]> :cs find g <C-R>=expand("<cword>")<CR><CR> " find global definition
		map <C-[> :cs find c <C-R>=expand("<cword>")<CR><CR> " find callers of function under cursor
		map <C-\> :cs find t <C-R>=expand("<cword>")<CR><CR> " find assignments to variable under cursor
		map <C-s> :cs find s <C-R>=expand("<cword>")<CR><CR> " find string under cursor
		map <C-f> :cs find f <C-R>=expand("<cword>")<CR><CR> " find file under cursor
		map <C-i> :cs find i <C-R>=expand("<cword>")<CR><CR> " find files including file under cursor
		map <C-i> :cs find I %<CR>							 " find files including current file
		cs add $PWD/cscope.out
	endif
endif

" F*cking trailing whitespaces
autocmd BufRead * highlight ExtraWhitespace ctermbg=red guibg=red
autocmd BufRead * match ExtraWhitespace /\s\+$\| \+\ze\t\| /

set title
set autoindent
set diffopt=iwhite,filler
set guifont=LucidaTypewriter\ 8

" 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 shiftwidth=4
set noexpandtab

map U		yyp:s/[^	]/-/g<CR>:noh<CR>
map Y		yyp:s/[^	]/=/g<CR>:noh<CR>

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

map <ESC>u	:noh<CR>

runtime! ftplugin/man.vim
map K		:Man <C-R>=expand("<cword>")<CR><CR>


" 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()
map <ESC>b :GitBlameCurrentLine<CR>

" <ESC>n 	goto next empty reply-to paragraph
" <ESC>m	opens an empty reply-paragraph at this line
" <ESC>d	deletes everything from there onto the signature
" <ESC>w	reformats entire mail but the signature
" <ESC>D	deletes all the quote above
autocmd BufRead /tmp/mutt-*[0-9a-f] map <ESC>n /^> $<CR>
autocmd BufRead /tmp/mutt-*[0-9a-f] map <ESC>D ^d?^\([^>]\\|$\)?+<CR>O<ESC>
autocmd BufRead /tmp/mutt-*[0-9a-f] map <ESC>d ^d/^-- $<CR>O<ESC>
autocmd BufRead /tmp/mutt-*[0-9a-f] map <ESC>w ggv/^-- $<CR><UP>:!par rTbgqRe 'B=.,?_A_a' 'Q=_s>\|'<CR>

autocmd BufRead /tmp/mutt-*[0-9a-f] setlocal spell spelllang=fr,en,de
autocmd BufRead /tmp/mutt-*[0-9a-f] setlocal textwidth=74
autocmd BufRead /tmp/mutt-*[0-9a-f] execute Erase_Sig_but_Your()
autocmd BufRead /tmp/mutt-*[0-9a-f] :normal ,n

map zc	z=1<CR><CR>

function! SetLocalTabs(tabsize)
	execute 'setlocal tabstop=' . a:tabsize
	execute 'setlocal softtabstop=' . a:tabsize
	execute 'setlocal shiftwidth=' . a:tabsize
	setlocal smarttab
	setlocal expandtab
endfunction
autocmd BufAdd *.py execute SetLocalTabs(4)

autocmd BufEnter * set cursorline
autocmd WinEnter * set cursorline
autocmd BufLeave * set nocursorline
autocmd WinLeave * set nocursorline


" footnotes
inoremap ,f <Esc>:call VimFootnotes()<CR>
inoremap ,r <Esc>:exe b:pos<CR>

function! VimFootnotes()
  if exists("b:vimfootnotenumber")
    let b:vimfootnotenumber = b:vimfootnotenumber + 1
    let cr = ""
  else
    let b:vimfootnotenumber = 0
    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