summaryrefslogtreecommitdiff
path: root/.vimrc
blob: 545b3d147cf6f82f6de43e94222cacdf881b66ec (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
" {{{ General settings
set nocompatible	" Forget about (N)VI
set noerrorbells	" No annoying bells
set vb t_vb=
set hidden		" allow buffer switching without saving

" Highlight search results
set hlsearch
" Type-ahead find
set incsearch

" Indent of 8, but no spaces
set shiftwidth=8
set tabstop=8

" Allow backspacing over indentation, end-of-line and start-of-line
set backspace=2

" smart autoindenting
set smartindent

" Paste toggle (a.k.a set paste/set nopaste)
set pastetoggle=<F11>

" Enable folding by fold markers
set foldmethod=marker

" Wrap line longer than the display
"set wrap
" Textwidth of 100
set textwidth=100

" Number of undo operations to store
set undolevels=50

set laststatus=2	" Always show the statusline
set ruler		" Display ruler with cursor positions

set cursorline		" Highlight the cursor line and column

" Buffer, filename, line, total lines, column, ASCII value
"set statusline=[%n]\ %f\ %m\ %l/%L,%c\ ASCII:\ %3b
"set statusline+=[%{strlen(&fenc)?&fenc:'none'}, " file encoding
"set statusline+=%{&ff}] 			" file format

" Always show at least one line above/below the cursor.
" See https://github.com/tpope/vim-sensible
if !&scrolloff
  set scrolloff=1
endif
if !&sidescrolloff
  set sidescrolloff=5
endif
set display+=lastline

" maximum number of tabs to open
set tabpagemax=20

set showmode
set modeline
set backupcopy=auto,breakhardlink

filetype on		" Enable filetype detection
filetype indent on	" Enable filetype specific indenting
filetype plugin on	" Enable filetype specific plugins

let g:git_diff_spawn_mode=2

" }}}
" {{{ Colors and fonts

set background=dark
let g:solarized_termtrans=1
colorscheme solarized

" Syntax highlighting
if &t_Co > 2 || has("gui_running")
	syntax on
endif

" Highlight trailing whitespaces
let c_space_errors=1
highlight WhitespaceEOL ctermbg=red guibg=red
match WhitespaceEOL /\s\+$/

" }}}
" {{{ Completion
autocmd FileType c set omnifunc=ccomplete#Complete
autocmd FileType ruby,eruby set omnifunc=rubycomplete#Complete
autocmd FileType python set omnifunc=pythoncomplete#Complete
autocmd FileType javascript set omnifunc=javascriptcomplete#CompleteJS
autocmd FileType html set omnifunc=htmlcomplete#CompleteTags
autocmd FileType css set omnifunc=csscomplete#CompleteCSS
autocmd FileType xml set omnifunc=xmlcomplete#CompleteTags
autocmd FileType php set omnifunc=phpcomplete#CompletePHP
" }}}
" {{{ Mappings
let mapleader=","

" Line numbering toggle
nmap <C-x>n :set invnumber<CR>
"highlight LineNr term=bold cterm=NONE ctermfg=DarkGrey ctermbg=NONE gui=NONE guifg=DarkGrey guibg=NONE

map <C-x>s ^iSigned-off-by: <C-r>=$GIT_AUTHOR_NAME<CR> <<C-r>=$GIT_AUTHOR_EMAIL<CR>><ESC>^
map! <C-x>s Signed-off-by: <C-r>=$GIT_AUTHOR_NAME<CR> <<C-r>=$GIT_AUTHOR_EMAIL<CR>><CR>

map <C-x>a ^iAcked-by: <C-r>=$GIT_AUTHOR_NAME<CR> <<C-r>=$GIT_AUTHOR_EMAIL<CR>><ESC>^
map! <C-x>a Acked-by: <C-r>=$GIT_AUTHOR_NAME<CR> <<C-r>=$GIT_AUTHOR_EMAIL<CR>><CR>

map <C-x>r ^iReviewed-by: <C-r>=$GIT_AUTHOR_NAME<CR> <<C-r>=$GIT_AUTHOR_EMAIL<CR>><ESC>^
map! <C-x>r Reviewed-by: <C-r>=$GIT_AUTHOR_NAME<CR> <<C-r>=$GIT_AUTHOR_EMAIL<CR>><CR>

map <C-x>y ^iCopyright (C) <C-R>=strftime("%Y")<CR> <C-r>=$GIT_AUTHOR_NAME<CR> <<C-r>=$GIT_AUTHOR_EMAIL<CR>><CR><ESC>^
map! <C-x>y Copyright (C) <C-R>=strftime("%Y")<CR> <C-r>=$GIT_AUTHOR_NAME<CR> <<C-r>=$GIT_AUTHOR_EMAIL<CR>><CR>

map <C-x>c i<C-R>=strftime("%F %R")<CR> Tobias Klauser <tklauser@distanz.ch><CR><TAB>* <ESC>
map! <C-x>c <C-R>=strftime("%F %R")<CR> Tobias Klauser <tklauser@distanz.ch><CR><TAB>* 
map <C-x>f ^iFrom: Tobias Klauser <tklauser@distanz.ch><CR><ESC>^
map! <C-x>f From: Tobias Klauser <tklauser@distanz.ch><CR>

map <F9> :let &background = ( &background == "dark" ? "light" : "dark" )<CR>
map <F10> <ESC>:! make<CR>

map! <C-x><SPACE> &nbsp;

map <C-p> :Files<CR>
map <C-f> :NERDTreeFind<CR>

map <Leader>tl :TlistToggle<CR>

" Remove all trailing whitespaces in file
map <leader>w :%s/\s\+$//<CR>^
map! <leader>w <ESC>:%s/\s\+$//<CR>

" Remove Mac/DOS line-breaks
map <leader>lb :%s/
//<CR>^
map! <leader>lb <ESC>:%s/
//<CR>

" Navigate non-breaking lines more easily
" from http://zinformatik.de/tipps-tricks/vim-tipps/einige-tipps-und-tricks-fur-vim/
noremap <C-J> gj
noremap <C-K> gk

" Thanks mikap! http://michael-prokop.at/computer/config/.vimrc
map !f !perl -MText::Autoformat -e'autoformat'
map ;0 <ESC>:'<,'>!boxes
map ;1 <ESC>:'<,'>!boxes -d boxquote
map ;2 <ESC>:'<,'>!boxes -d peek -a c -s 40x5
map ;3 <ESC>:'<,'>!boxes -d c-cmt
map ;4 <ESC>:'<,'>!boxes -d dog -a c
map ;5 <ESC>:'<,'>!boxes -d simple -a jr
map ;6 <ESC>:'<,'>!boxes -d headline

map <Leader>hon :%!xxd<CR>
map <Leader>hof :%!xxd -r<CR>

" delete the text until start of the mail signature with ,k
map <Leader>k d/^-- $<CR>

" line numbering
map <Leader>ln :%s/^/\=line('.')/<CR><ESC>

" add a comment
map <Leader>mkc i/*  */<Left><Left><Left>

" greet to the person you write a mail
map <Leader>a  G/^\* /e+1<CR>ye1G}oHallo <c-r>",<cr><ESC>

" }}}
" {{{ VIM LaTeX
let g:Imap_UsePlaceHolders = 0
" }}}
" {{{ Always use tabs in Makefiles
autocmd BufEnter ?akefile* set noet ts=8 sw=8 nocindent
" }}}
" {{{ NERDTree
autocmd vimenter * if !argc() | NERDTree | endif
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif

let NERDTreeShowHidden=1

map <Leader>nt :NERDTreeToggle<CR>
" }}}
" {{{ airline
let g:airline_theme='solarized'
let g:airline_solarized_bg='dark'
" }}}
" {{{ vim-plug (https://github.com/junegunn/vim-plug)
call plug#begin('~/.vim/plugged')

Plug 'vim-airline/vim-airline'          		" status line
Plug 'vim-airline/vim-airline-themes'
Plug 'scrooloose/nerdtree'              		" NERDTree file browser
Plug 'fatih/vim-go', { 'do': ':GoUpdateBinaries' }	" Go support
Plug 'rust-lang/rust.vim'				" Rust support
Plug 'airblade/vim-gitgutter'           		" git status gutter
Plug 'tpope/vim-fugitive'				" git commands
Plug 'tpope/vim-rhubarb'				" GitHub integration
Plug 'tpope/vim-commentary'				" comment out stuff
Plug 'yegappan/taglist'					" code browser using ctags/cscope
Plug 'joestringer/cscope_maps'				" cscope maps

" fzf (https://github.com/junegunn/fzf.vim)
Plug 'junegunn/fzf', { 'do': './install --bin' }
Plug 'junegunn/fzf.vim'

call plug#end()
" }}}