summaryrefslogtreecommitdiff
path: root/.vimrc
blob: c834476fbb60dc01575dcc793e5f8d2f5748bc2b (plain) (blame)
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
" dotfiles -- .vimrc
" author: johannst

set nocompatible     " make vim less vi 

"{{{ Vundle

   " to install plugins open vim and run :PluginInstall from within vim OR
   " vim +PluginInstall +qall from cmd line

   filetype off         " necessary for vundle!!!
   set rtp+=~/.vim/bundle/Vundle.vim

   call vundle#begin()
   Plugin 'VundleVim/Vundle.vim'
   Plugin 'jlanzarotta/bufexplorer'
   Plugin 'ap/vim-buftabline'
"   Plugin 'vim-airline/vim-airline'
"   Plugin 'vim-airline/vim-airline-themes'
   Plugin 'majutsushi/tagbar'
   Plugin 'kien/ctrlp.vim'
   " c++ modifief headers: http://www.vim.org/scripts/script.php?script_id=2358
   "Plugin 'vim-scripts/OmniCppComplete'
   call vundle#end()         

"}}}
"{{{ Plugin Config

   " powerline
   let g:airline#extensions#tabline#enabled = 1
   let g:airline#extensions#tabline#fnamemod = ':t'
   let g:airline_powerline_fonts = 1
   if !exists('g:airline_symbols')
        let g:airline_symbols = {}
   endif

   " tagbar
   let g:tagbar_ctags_bin='~/.vim/bin/ctags'

   " CtrlP
    let g:ctrlp_buftag_ctags_bin='~/.vim/bin/ctags'
    let g:ctrlp_extensions = ['buffertag', 'line', 'changes', 'mixed']

   " buftabline
   let g:buftabline_indicators = 1

   " omni complete
   " add tags
   " set tags+=~/.vim/tags/cpp_tags
   "let OmniCpp_NamespaceSearch = 1
   "let OmniCpp_GlobalScopeSearch = 1
   "let OmniCpp_ShowAccess = 1
   "let OmniCpp_ShowPrototypeInAbbr = 1 " show function parameters
   "let OmniCpp_MayCompleteDot = 1 " autocomplete after .
   "let OmniCpp_MayCompleteArrow = 1 " autocomplete after ->
   "let OmniCpp_MayCompleteScope = 1 " autocomplete after ::
   "let OmniCpp_DefaultNamespaces = ["std", "_GLIBCXX_STD"]
   "" automatically open and close the popup menu / preview window
   "au CursorMovedI,InsertLeave * if pumvisible() == 0|silent! pclose|endif
   "set completeopt=menuone,menu,longest,preview

"}}}

augroup aug:AutoSaveResore
   autocmd!
   "autocmd VimEnter * silent! source .vim_last_session
   autocmd QuitPre * mksession! .vim_last_session
augroup end


function! TriggerSCons(arg_string)
   let base_cmd = "scons -u "
   let &makeprg=base_cmd.a:arg_string
   make
endfunction
" use like :SCons -j20 ...
command! -nargs=1 SCons call TriggerSCons(<f-args>)

" +----------------------------+
" | Color Settings             |
" +----------------------------+
syntax on
set background=dark
colorscheme buddy

" +----------------------------+
" | Basic Settings             |
" +----------------------------+
set timeoutlen=1000           " time in ms until keymap interpreted
set ttimeoutlen=100           " time in ms for key code delay, NEVER USE 0 again!!! if random numbers/letters occur, maybe change this value

filetype plugin indent on     " enable loading indent file for filetype
set ffs=unix,dos,mac          " try recognizing dos, unix, and mac line endings.
set encoding=utf-8            " set default encoding to UTF-8.

" Basic settings
set title                     " show title in console title bar
set confirm                   " prompt if closing with unsaved changes.
set laststatus=2              " always show status line
set shortmess+=a              " Use [+]/[RO]/[w] for modified/readonly/written.
set showcmd                   " show command in status line.
set mouse=a                   " enable mouse usage (all modes)
set history=1000              " sets how many lines of history VIM has to remember
set tabpagemax=100            " sets how many tabs will be opened
set scrolloff=3               " set vertical scroll distance to 7 lines
set backspace=2               " had some issues with BS on empty line didn't deleted line
set noautowrite               " never write a file unless I request it.
set noautowriteall            " NEVER.
set noautoread                " don't automatically re-read changed files.
set nowrap

" Line/Column settings
set number                    " Display line numbers
set relativenumber            " Display relative line numbers
set ruler                     " display cursor position
set cursorline                " cursor line highlighting
set cursorcolumn              " cursor column highlighting 

" buffer settings
set hidden                    " do not unload abandoned buffers

" Tab settings 
set expandtab                 " expand tabs to spaces
set tabstop=8                 " number of columns a tab counts
set shiftwidth=3              " number of columns text is indented 
set softtabstop=3             " number of columns tab counts in insert mode
set shiftround                " rounds indent to a multiple of shiftwidth
"set smarttab                  " Handle tabs more intelligently 

" Fold settings
set foldmethod=marker         " set fold method

" Indentation settings
set autoindent                " copy indent from current line when starting a new line
set smartindent               " use smart indent if there is no indent file

augroup aug:CLangStyle
   autocmd!
   autocmd BufRead,BufNewFile *.h,*.hh,*.hpp,*.c,*.cc,*.cpp set cinoptions=:1,=2,g1,h2  " switch-case/class-lable indentation
   autocmd BufRead,BufNewFile * setlocal formatoptions-=cro   " disable auto-comment
augroup end

" Invisible character settings
"set list                     " show invisible character
set listchars=tab:>-,eol:$,trail:-,precedes:<,extends:>

" Search settings
set ignorecase                " case insensitive matching
set incsearch                 " incremental search
set hlsearch                  " highlight search results
set smartcase                 " overwrite ignorecase if pattern contains capital letters
set showmatch                 " show matching brackets.
set matchtime=2               " how many tenths of a second to blink when matching brackets
set matchpairs+=<:>           " show matching <> as well
set magic                     " for regular expressions turn magic on

" Vim command completion settings
set wildmenu                  " turn on the wild menu
set wildmode=longest:full     " <Tab> cycles between all matching choices.
set wildignore+=*.o,*.obj,.git,*.pyc,*~ " Ignore these files when completing

" No annoying sound on errors
set noerrorbells
set novisualbell

" automatically open Quickfix
augroup aug:QuickFixConfig
   autocmd!
   autocmd QuickFixCmdPost [^l]* nested botright cwindow
   autocmd QuickFixCmdPost    l* nested botright lwindow
augroup end

"{{{ Keymaps

   " unset .
"   noremap . <nop>
   " set leader key
   "execute "set <M-s>=\es"
   let mapleader=";"

   " re-source .vimrc
   nnoremap <leader>v :source ~/.vimrc<CR>

   "remap esc button
"   inoremap <Esc> <nop>
   inoremap jj <Esc>

   " quit buffer
   noremap <leader>q :bd

   " re-adjust indentation
   nnoremap <leader>f mzgg=G`z

   " navigate between different splits 
   nnoremap <C-Down>  <C-w>j
   nnoremap <C-Up>    <C-w>k
   nnoremap <C-Right> <C-w>l
   nnoremap <C-Left>  <C-w>h
   nnoremap <C-j>     <C-w>j
   nnoremap <C-k>     <C-w>k
   nnoremap <C-l>     <C-w>l
   nnoremap <C-h>     <C-w>h

   " resize splits
   "map <C-j>     <C-w>5-
   "map <C-k>     <C-w>5+
   "map <C-l>     <C-w>5<
   "map <C-h>     <C-w>5>

   " navigate between different buffers 
   nnoremap <S-Left>  :bprevious<CR>
   nnoremap <S-Right> :bnext<CR>
   nnoremap <S-h>  :bprevious<CR>
   nnoremap <S-l>  :bnext<CR>

   " ctrl-ae jump to line start/end 
   nnoremap <C-a> 0
   nnoremap <C-e> $
   inoremap <C-a> <C-o>0
   inoremap <C-e> <C-o>$
   vnoremap <C-a> 0
   vnoremap <C-e> $
   cnoremap <C-a> <Home>
   cnoremap <C-e> <End>

   " Shortcut to toggle relative numbering mode
   nnoremap <C-n> :call ToggleRelativeNumber()<CR>

   " add a marker fold snippet (for C/C++)
   nnoremap <C-f> o//{{{ <Esc>o//}}}<Esc><Up>A
   inoremap <C-f> <ESC>o//{{{ <Esc>o//}}}<Esc><Up>A
   " only works with v-block (not v-line)
   vnoremap <C-f> VV'<O//{{{<Esc>'>o//}}}<Esc>'<<ESC><Up>A 

   " substitute selection
   vnoremap <C-r> "hy:%s/<C-r>h/<C-r>h/gc<left><left><left>

   " yank/paste into/from register
   vnoremap <C-c> "ay
   inoremap <C-v> <C-r>a
   cnoremap <C-v> <C-r>a

   " +-----------------+
   " | Plugin specific |
   " +-----------------+
   " Open BufferExplorer
   nnoremap <C-b> :call BufExplorer()<CR>

   " Toggle Tagbar 
   nnoremap <leader>t :TagbarToggle<CR>

   " build tags of your own project with Ctrl-F12
   map <C-t> :!ctags -R --sort=yes --c++-kinds=+pl --fields=+iaS --extra=+q --language-force=C++ .<CR>

"}}}
"{{{ Global Highlighting

   " hi clear CursorLine
   " augroup aug:CLClear
   "     autocmd! ColorScheme * hi clear CursorLine
   " augroup end

   "hi LineNr ctermfg=208

   " Highlight color of current line 
   hi CursorLineNR cterm=bold ctermfg=255 ctermbg=208
   "hi CursorLineNR cterm=bold ctermfg=226 
   augroup aug:CLNRSet
      autocmd! ColorScheme * hi CursorLineNR cterm=bold ctermfg=255 ctermbg=208
      "autocmd! ColorScheme * hi CursorLineNR cterm=bold ctermfg=226
   augroup end

   " matching brackets
   "hi MatchParen cterm=underline ctermbg=141 ctermfg=yellow
   hi MatchParen cterm=underline ctermbg=89 ctermfg=208
   "hi MatchParen cterm=underline ctermbg=DarkMagenta ctermfg=12

"}}}
"{{{ Functions
   " Split Window and scroll down
   function! SplitScroll()
       :wincmd v
       :wincmd w
       execute "normal! \<C-d>"
       :set scrollbind
       :wincmd w
       :set scrollbind
   endfunc

   " toggle relative line number mode
   function! ToggleRelativeNumber()           
       if(&relativenumber == 1)
           set norelativenumber
       else
           set relativenumber
       endif
   endfunc  
"}}}

" +----------------------------+
" | Tmux specific settings     |
" +----------------------------+
" tmux will send xterm-style keys when its xterm-keys option is on
if &term =~ '^screen'
   execute "set <xUp>=\e[1;*A"
   execute "set <xDown>=\e[1;*B"
   execute "set <xRight>=\e[1;*C"
   execute "set <xLeft>=\e[1;*D"
endif