summaryrefslogtreecommitdiffstats
path: root/vimrc
blob: dc5e2648eed15d7d64de46aa639149242279947b (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
" vim configuration of Sebastian Reichel <sre@ring0.de>

set nocompatible					" vim native mode
syntax on							" enable syntax highlighting
let c_comment_strings=1
colorscheme elektranox              " cool colors
set clipboard=unnamedplus           " use X11 clipboard for copy/paste
set hlsearch						" highlight searched word
set number							" numberize lines
set ruler							" lower file
set nowrap							" do not wrap lines
set incsearch						" search while typing
set foldmethod=syntax				" automatic code-folding
set autoindent						" automatic indention
set noerrorbells visualbell t_vb=	" no audible bell
set mouse=a							" set mouse to auto
set ruler							" show cursor position all the time
set wildmode=longest,list			" setup wildmode
set showmatch						" show matching brackets
set encoding=utf-8					" UTF-8
"set iskeyword-=_					" _ is a word delimiter
set autoread
set noexpandtab
set t_Co=256
set tabpagemax=32

autocmd Filetype gitcommit set textwidth=72
autocmd Filetype gitcommit set spell

" spellcheck setup (disabled by default)
set spellfile=~/.vim/spell/en.add,~/.vim/spell/de.add,~/.vim/spell/names.add
set spelllang=en,de

let g:netrw_dirhistmax=0			" disable anoying ~/.vim/.netrwhist

" Configure the status line show something useful.
"set statusline=%F%m%r%h%w\ %y\ [%{&ff}]%=[%l,%v][%p%%]\ [%L]
"set laststatus=2    " Ensure status line is visible.

" Sane handling of whitespace.
set tabstop=4
set shiftwidth=4
set softtabstop=4

" The h and l keystrokes can be made to wrap over lines (so that trying to
" move left past the beginning of a line puts the cursor at the end of the
" line above). This command does that, and also allows ~ (convert case) to
" wrap over lines, and the cursor keys to wrap when in insert mode:
set whichwrap=h,l,~,[,]

" Get useful auto-completion in command mode.
set wildmenu
set wildmode=list:longest,full

" save as root with w!!
cmap w!! w !/usr/bin/sudo /usr/bin/tee > /dev/null %

" copy&paste via <F4>
nnoremap \tp :set invpaste paste?<CR>
nmap <F4> \tp
imap <F4> <C-O>\tp
set pastetoggle=<F4>

" clear search via <F5>
nnoremap \clearsearch :let @/ = ""<CR>
nmap <F5> \clearsearch
imap <F5> <C-O>\clearsearch

" compile latex/code via <F6>
nnoremap \make :!make<CR>
nmap <F6> \make
imap <F6> <C-O>\make

" insert newline without editing mode
map <CR> o<Esc>

nmap <F9> :ConqueTerm zsh<CR>
nmap <F12> :TagbarToggle<CR>

" add vala support
autocmd BufRead *.vala   set efm=%f:%l.%c-%[%^:]%#:\ %t%[%^:]%#:\ %m
autocmd BufRead *.vapi   set efm=%f:%l.%c-%[%^:]%#:\ %t%[%^:]%#:\ %m
autocmd BufRead *.gtkaml set efm=%f:%l.%c-%[%^:]%#:\ %t%[%^:]%#:\ %m
au BufRead,BufNewFile *.vala            setfiletype vala
au BufRead,BufNewFile *.vapi            setfiletype vala
au BufRead,BufNewFile *.gtkaml          setfiletype vala
let vala_comment_strings = 1
let vala_space_errors = 1				" highlight space errors in vala code

" G-Code
au BufRead,BufNewFile *.nc            setfiletype nc

" add support for subtitle files
au BufNewFile,BufRead *.ssa setf ssa
au BufNewFile,BufRead *.ass setf ssa
au BufNewFile,BufRead *.proto setf proto

" configure printing stuff
set pdev=Default											" printer device
set printoptions=paper:A4,syntax:n,wrap:y,duplex:long		" print options
set penc=utf-8												" print encoding
"set pfn=courier:h10										" print font
"set pheader=...											" print header

" set terminal title
if &term == "screen"
  set t_ts=k
  set t_fs=\
endif
if &term == "screen" || &term == "xterm"
  set title
endif

" Set a nicer foldtext function
set foldtext=MyFoldText()
function! MyFoldText()
	let line = getline(v:foldstart)
	if match( line, '^[ \t]*\(\/\*\|\/\/\)[*/\\]*[ \t]*$' ) == 0
		let initial = substitute( line, '^\([ \t]\)*\(\/\*\|\/\/\)\(.*\)', '\1\2', '' )
		let linenum = v:foldstart + 1
		while linenum < v:foldend
			let line = getline( linenum )
			let comment_content = substitute( line, '^\([ \t\/\*]*\)\(.*\)$', '\2', 'g' )
			if comment_content != ''
				break
			endif
			let linenum = linenum + 1
		endwhile
		let sub = initial . ' ' . comment_content
	else
		let sub = line
		let startbrace = substitute( line, '^.*{[ \t]*$', '{', 'g')
		if startbrace == '{'
			let line = getline(v:foldend)
			let endbrace = substitute( line, '^[ \t]*}\(.*\)$', '}', 'g')
			if endbrace == '}'
				let sub = sub.substitute( line, '^[ \t]*}\(.*\)$', '...}\1', 'g')
			endif
		endif
	endif
	let n = v:foldend - v:foldstart + 1
	let info = " " . n . " lines"
	let sub = sub . "                                                                                                                  "
	let num_w = getwinvar( 0, '&number' ) * getwinvar( 0, '&numberwidth' )
	let fold_w = getwinvar( 0, '&foldcolumn' )
	let sub = strpart( sub, 0, winwidth(0) - strlen( info ) - num_w - fold_w - 1 )
	return sub . info
endfunction

" open epub files as zip
au BufReadCmd   *.epub      call zip#Browse(expand("<amatch>"))

" enable plugins depending on filetype
filetype plugin on

" git branch in ruler
if has('nvim')
	" no fugitive in nvim for now
else
	set rulerformat=%33(%{fugitive#statusline()}%=%10(%l,%c%V%=%5(%p%%%)%)%)
endif

" tex = latex
let g:tex_flavor='latex'

" debian/control indents must be spaces
autocmd FileType debcontrol set expandtab

autocmd BufNewFile,BufRead /home/sre/src/u-boot/* set tabstop=8 shiftwidth=8 softtabstop=8
autocmd BufNewFile,BufRead /home/sre/src/linux/* set tabstop=8 shiftwidth=8 softtabstop=8
autocmd BufNewFile,BufRead /home/sre/src/linux-*/* set tabstop=8 shiftwidth=8 softtabstop=8

if has('nvim')
	" no pathogen in nvim for now
else
	execute pathogen#infect()
endif

inoremap <silent> <Bar>   <Bar><Esc>:call <SID>align()<CR>a

" automatic alignment of ascii-art tables
function! s:align()
  let p = '^\s*|\s.*\s|\s*$'
  if exists(':Tabularize') && getline('.') =~# '^\s*|' && (getline(line('.')-1) =~# p || getline(line('.')+1) =~# p)
    let column = strlen(substitute(getline('.')[0:col('.')],'[^|]','','g'))
    let position = strlen(matchstr(getline('.')[0:col('.')],'.*|\s*\zs.*'))
    Tabularize/|/l1
    normal! 0
    call search(repeat('[^|]*|',column).'\s\{-\}'.repeat('.',position),'ce',line('.'))
  endif
endfunction

" Rename tabs to show tab number
" https://superuser.com/questions/331272/vim-show-the-index-of-tabs-in-the-tabline
if exists("+showtabline")
    function! MyTabLine()
        let s = ''
        let wn = ''
        let t = tabpagenr()
        let i = 1
        while i <= tabpagenr('$')
            let buflist = tabpagebuflist(i)
            let winnr = tabpagewinnr(i)
            let s .= '%' . i . 'T'
            let s .= (i == t ? '%1*' : '%2*')
            let s .= ' '
            let wn = tabpagewinnr(i,'$')

            let s .= '%#TabNum#'
            let s .= i
            " let s .= '%*'
            let s .= (i == t ? '%#TabLineSel#' : '%#TabLine#')
            let bufnr = buflist[winnr - 1]
            let file = bufname(bufnr)
            let buftype = getbufvar(bufnr, 'buftype')
            if buftype == 'nofile'
                if file =~ '\/.'
                    let file = substitute(file, '.*\/\ze.', '', '')
                endif
            else
                let file = fnamemodify(file, ':p:t')
            endif
            if file == ''
                let file = '[No Name]'
            endif
            let s .= ' ' . file . ' '
            let i = i + 1
        endwhile
        let s .= '%T%#TabLineFill#%='
        let s .= (tabpagenr('$') > 1 ? '%999XX' : 'X')
        return s
    endfunction
    set stal=2
    set tabline=%!MyTabLine()
    set showtabline=1
    highlight link TabNum Special
endif


let g:syntastic_mode_map = { 'mode': 'passive', 'active_filetypes':   [],'passive_filetypes': [] }
noremap <C-w>e :SyntasticCheck<CR>
noremap <C-w>f :SyntasticToggleMode<CR>