aboutsummaryrefslogtreecommitdiff
path: root/vimrc
blob: 2e4ff51346fc522b23697dac12ed335a38cf69c4 (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
call plug#begin()

" Brilliant_Plugins_by_tpope: ========================.
Plug 'tpope/vim-sensible'                             | " a sane and modern default configuration
Plug 'tpope/vim-surround'                             | " plugin makes cs"' inside a line replace " with '
Plug 'tpope/vim-fugitive'                             | " the most complete GIT integration plugin
Plug 'godlygeek/tabular'                              | " align code on a sign, like :Tab/=
Plug 'mhinz/vim-signify'                              | " show changes in the clutter bar


" Colorschemes: ======================================.
Plug 'chriskempson/base16-vim'                        | "
map <leader>q :bp<bar>sp<bar>bn<bar>bd<CR>.


" NERDTree: ==========================================.
Plug 'scrooloose/nerdtree'                            | " replace NetRW, which is kind of buggy
let NERDTreeCascadeSingleChildDir                = 0  | " I don't get how one can use <m> to create files in that included directory
set winwidth=30                                         " keep NERDTreeWindow at least this size
set winminwidth=30                                      " (and all other windows, so TODO: watch out)

autocmd BufEnter * lcd %:p:h
" depending on if NERDTree has the focus:
nnoremap <expr>
      \ <leader><leader>
      \ bufwinnr("%")==g:NERDTree.GetWinNum() ? ':NERDTreeClose<CR>' : ':NERDTreeFind<CR>'
nnoremap <expr>
      \ <Tab>
      \ bufwinnr("%")==g:NERDTree.GetWinNum() ? '<C-W><C-W>' : ':bn<CR>'
nnoremap <expr>
      \ <S-Tab>
      \ bufwinnr("%")==g:NERDTree.GetWinNum() ? '<C-W><C-W>' : ':bp<CR>'
" close NERDTree if it is the last remaining window (taken from the official documentation)
" autocmd bufenter *
"       \ if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif


" AIRLINE: ===========================================.
Plug 'vim-airline/vim-airline'                        | " beautification of the mode line
set laststatus=2                                      | " required by AirLine, without status line does not appear until a window split
let g:airline_detect_modified                    = 0  |
let g:airline_detect_paste                       = 0  |
let g:airline_exclude_preview                    = 1  |
let g:airline_extensions                         = ['tabline', 'branch', 'syntastic', 'tagbar']
let g:airline#extensions#tabline#disable_refresh = 1  |
let g:airline#extensions#tabline#enabled         = 1  |
let g:airline#extensions#tabline#fnamemod        = ':t:.' | " let airline just show the filename without its path
let g:airline#extensions#tabline#show_buffers    = 1  |
let g:airline#extensions#tabline#show_tabs       = 0  |
let g:airline#extensions#tagbar#enabled          = 0  |
let g:airline#extensions#tagbar#flags            = 's'
let g:airline#extensions#whitespace#enabled      = 0  |
let g:airline#extensions#wordcount#enabled       = 0  |
let g:airline_inactive_collapse                  = 1  |
let g:airline_powerline_fonts                    = 1  |
let g:airline_section_c                          = '%F'


" AIRLINE_Theme: =====================================.
Plug 'vim-airline/vim-airline-themes'                 | " airline themes to match any light and dark terminal using :AirlineTheme
let g:airline_theme='base16'                          | " specifies which colorscheme should airline uses
" let g:airline_theme='badcat'                          | " specifies which colorscheme should airline uses
" let g:airline_theme='papercolor'                    | " specifies which colorscheme should airline uses


" Additional: ========================================.
Plug 'sheerun/vim-polyglot'                           " better syntax highlighting/indentation for multiple languages
Plug 'majutsushi/tagbar'                              " superseeds taglist-plus, which isn't maintained any more
let g:tagbar_autoclose   = 1
let g:tagbar_autofocus   = 1
let g:tagbar_autoshowtag = 1
let g:tagbar_compact     = 0
let g:tagbar_indent      = 0
let g:tagbar_foldlevel   = 99
nnoremap <leader>l :TagbarToggle<CR>|                 " bind TagBar to Hotkey Ctrl+L


" Autocompleter: =====================================.
Plug 'Valloric/MatchTagAlways'                        " highlights the closing tag/brace/...
Plug 'Valloric/YouCompleteMe'
let g:ycm_collect_identifiers_from_tags_files = 1     " Let YCM read tags from Ctags file
let g:ycm_complete_in_comments                = 1     " Completion in comments
let g:ycm_complete_in_strings                 = 1     " Completion in string
let g:ycm_error_symbol                        = '✖'   " insert this as an error symbol in the gutter bar
let g:ycm_min_num_of_chars_for_completion     = 1
let g:ycm_seed_identifiers_with_syntax        = 1     " Completion for programming language's keyword
let g:ycm_use_ultisnips_completer             = 1     " Default 1, just ensure
let g:ycm_warning_symbol                      = '➔'   " insert this as a warning symbol in the gutter bar
" disable <tab>-key for YCM so that it can be used with ultisnips
" let g:ycm_key_list_select_completion=[]
" let g:ycm_key_list_previous_completion=[]


Plug 'scrooloose/syntastic'
set statusline+=%#warningmsg#
set statusline+=%{SyntasticStatuslineFlag()}
set statusline+=%*
set signcolumn=yes                                    " always show the column
let g:LatexBox_latexmk_preview_continuously = 1
let g:LatexBox_viewer                       = "evince"
let g:syntastic_always_populate_loc_list    = 1
let g:syntastic_auto_loc_list               = 0
let g:syntastic_check_on_open               = 1
let g:syntastic_check_on_wq                 = 0
let g:syntastic_quiet_messages              = {"type":"style"} " filter ( = do not display) style/formatting errors and warnings
" Syntastic
let g:syntastic_error_symbol                = '✖'
let g:syntastic_style_error_symbol          = '✗'
let g:syntastic_warning_symbol              = '➔'
let g:syntastic_style_warning_symbol        = '≈'

Plug 'davidhalter/jedi-vim'                           " jedi gets used to display python function signatures
let g:jedi#completions_enabled        = 0     " we do not need completions, because we have YouCompleteMe
let g:jedi#show_call_signatures       = 1     " which sadly does not support signatures like jedi
let g:jedi#show_call_signatures_delay = 0
let g:jedi#auto_vim_configure         = 0
let g:pymode_rope                     = 0     " https://github.com/davidhalter/jedi-vim/issues/163
" autocmd FileType python jedi.preload_module('os', 'sys', 'math')
" let g:pymode_options_max_line_length          = 120
" let g:syntastic_python_flake8_args='--ignore=F821,E302,E501,E241,E301'

Plug 'honza/vim-snippets'                             " dependency of ultisnips (see below)
Plug 'SirVer/ultisnips'                               " replaces loremipsum (and many more)
"let g:UltiSnipsExpandTrigger       = '<C-j>'| " Trigger configuration. Do not use <tab> if you use https://github.com/Valloric/YouCompleteMe.
"let g:UltiSnipsJumpForwardTrigger  = '<C-j>'| " \
"let g:UltiSnipsJumpBackwardTrigger = '<C-k>'| " \
"let g:UltiSnipsListSnippets      = '<C-`>'| " YouCompleteMe includes those, so this isn't necessary
let g:UltiSnipsExpandTrigger       = '<leader><tab>'| " Trigger configuration. Do not use <tab> if you use https://github.com/Valloric/YouCompleteMe.
let g:UltiSnipsJumpForwardTrigger  = '<PageDown>'| " \
let g:UltiSnipsJumpBackwardTrigger = '<PageUp>'| " \
let g:UltiSnipsListSnippets        = '<leader><leader>'| " YouCompleteMe includes those, so this isn't necessary
" let g:UltiSnipsEditSplit         = 'vertical'


" Disabled ===========================================.
" Plug 'Shougo/neocomplete.vim'                       | " alternative to YouCompleteMe in some cases
" Plug 'tpope/vim-characterize'                       | " normal mode: make ga show character names of Unicode chars (ga shows hex and dec values)
" Plug 'tpope/vim-repeat'                             | " lets . (dot) repeat plugin macros as well, specifically vim-surround

call plug#end()                                       | " all plugins are getting loaded on this line, don't remove!

filetype on
filetype plugin on
filetype indent on
syntax on                     | " enable syntax highlighting
syntax sync minlines=60       | " how many preceding lines will be parsed? (has performance impact)
" set term=xtermc             | " required on solaris



" Shortcut mods =======================================.
inoremap <C-Space> <C-x><C-o>
"inoremap <C-@> <C-Space>
vnoremap < <gv|                   " allows deindenting a selected block and keeps selection
vnoremap > >gv|                   " allows indenting a selected block and keeps selection

" Bind CTRL+Backspace to vims version (CTRL+W) in " <CR> insert mode (only works with gvim)
inoremap
      \ <C-Backspace>
      \ <C-W>

noremap <silent> <F5> :make<CR>



" settings ============================================.
set shell=/bin/bash           | " many scripts rely on bash, but its path varies why it is commented out here
" set selectmode=mouse,key,cmd  | " enters vim's select mode when pressing shift-left or shift-END
" set keymodel=startsel,stopsel | " makes shift-left, shift-right available for selecting text
set breakindent               | " Every wrapped line will continue visually indented
set clipboard=unnamedplus     | " makes copy and paste work (autoselectplus might work as well)
set complete+=d               | " scan current and included files for defined name or macro
set complete+=i               | " scan current and included files for completions
set concealcursor=nc          | " limits the display of concealed text to normal and command mode
set conceallevel=2            | " replace escaped chars by their utf-8 representation (useful for LaTeX)
set confirm                   | " asks 'do you want to save?'
set encoding=utf-8            | " set up vim's cosole encoding (not file encoding, for which there is fileencoding=)
set hidden                    | " allows switiching buffers even if the current buffer contains changes (displays +)
set hlsearch                  | " highlights all search matches (not as performant!)
set ignorecase smartcase      | " search with ignorecase by default, but use case sensitive search when one captical char is contained
set lazyredraw                | " disables redraw during macro exectution (improves performance)
set linebreak                 | " wrap long lines at char 'breakat', not inside words
set mouse=n                   | " allow mouse in normal mode only, so one can use the terminals c&p feature in insert mode
set mousemodel=popup          | " only in gvim: right click opens a popup-menu
set nocursorcolumn            | " turn visual cursor column off (improves performance)
set nocursorline              | " turn visual cursor line off (improves performance)
set nofoldenable              | " disable code folding. I hate code folding
set relativenumber            | " relative line numbers can speed up navigation
set noshowmode                | " because we are using some powerline derivat
set nostartofline             | " when scrolling: do not move the cursor to column 1
set notimeout ttimeout        | " improves performance but is known to cause problems on slow terminals
set nowrap                    | " but do not (by default) wrap long lines around
set number                    | " turn line numbers on/off (performance decreases when they are shown)
set pumheight=8               | " Determines the maximum number of items to show in the popup menu for
set redrawtime=400            | " The time in milliseconds for redrawing the display.
set restorescreen             | " restores the console after exiting vim
set scrolljump=5              | " how many lines get scrolled into view when cursor reaches the screens edge
set spell spelllang=en,de     | " enable spell checker
set splitbelow                | " open new windows below the current one (i find that more intuitive)
" set t_Co=256                  | " required on some ssh sessions
set textwidth=100             | " line length (80 used to be default, but...)
set thesaurus+=/home/max/.vim/thesaurus/php.txt
set ts=2 sts=2 sw=2 expandtab | " indentation which i like (abbr: tabstop, softtabstop, shiftwidth)
set ttimeoutlen=10            | " set esc key timeout in ms-
set ttyfast                   | " improves speed for terminal vim
set updatetime=1000           | " updates the screen more often
set ttyscroll=100             | " improves speed for terminal vim
set writedelay=0
" set termguicolors             | " When on, uses highlight-guifg and highlight-guibg attributes in the terminal (=24bit color)

if has("multi_byte")
  scriptencoding utf-8        | " tell vim that we are using utf-8 here
  set encoding=utf-8          | " we need default utf-8 encoding to use cool chars as line break and so on (see below)
  set termencoding=&encoding  | " once we use special chars we assume everybody uses a terminal supporting those
  set listchars=eol:| " symbols used when using :set list (which displays non-printable chars)
  set listchars+=extends:»    | " symbols used when using :set list (which displays non-printable chars)
  set listchars+=precedes:«   | " symbols used when using :set list (which displays non-printable chars)
  set listchars+=tab:▸\       | " symbols used when using :set list (which displays non-printable chars)
  set listchars+=trail:·      | " symbols used when using :set list (which displays non-printable chars)
  set listchars+=space:·      | " symbols used when using :set list (which displays non-printable chars)
  set showbreak+=| " symbol used in the beginning of a wrapped line
end

if has("gui_running")
  set toolbar+=text
  set guioptions+=eig
  set guioptions-=T           | " toolbar
  set guioptions+=c           | " use console dialogs instead of popups
  set guioptions+=a           | " autoselect: copy&paste using middleclick
  set guioptions-=m           | " remove menu
  " set guifont=Droid\ Sans\ Mono\ for\ Powerline\ 12
  set guifont=Dejavu\ Sans\ Mono\ for\ Powerline\ 12
  set guioptions-=e           | " do not display tabs
  set winaltkeys=menu         | " behave like other windows: ALT-key can be used to open the menu (and cannot be :remaped)
endif

if bufname('%') == ''
  set bufhidden=wipe
endif

noautocmd

if has("autocmd")
  set modeline                | " set variables specific to a file, like indentation by adding a comment
  " set default completion function in case YouCompleteMe cannot help
  set omnifunc=syntaxcomplete#Complete

  " automatically reload this file when it gets edited
  augroup reload_vimrc " {
    autocmd!
    autocmd BufWritePost $MYVIMRC source $MYVIMRC
  augroup END " }

  augroup remove_whitespaces " {
    " automatically remove trailing white spaces on save..
    autocmd BufWritePre * %s/\s\+$//e
  augroup END " }

  augroup set_window_title " {
    " autocmd BufWinEnter quickfix setl statusline=%t
    " autocmd BufEnter * let &titlestring = hostname() . "[vim(" . expand("%:t") . ")]"
    autocmd CursorHold * let &titlestring = "%t|".$USER."@".hostname().":%{expand(\"%:~:.:h\")}%=%y"
    set title
    " autocmd CursorHold * let &titlestring = "Vim (".airline#extensions#tagbar#currenttag().")"

    " set window title for screen(3)
    if &term == "screen"
      set t_ts=k
      set t_fs=\
    endif
    if &term == "screen" || &term == "xterm"
      set titlelen=40
      set title
    endif
  augroup END

  augroup visual_mode_shows_unprintable " {
    " set cursorline              | " use setcursorline in order to highlight non printable chars in the current line
    autocmd ColorScheme * highlight normal ctermbg=NONE
    " set list                      | " shows unprinable characters in the current line
    autocmd ColorScheme * highlight NonText ctermbg=NONE ctermfg=0 gui=bold guifg=NONE
    autocmd ColorScheme * highlight SpecialKey ctermbg=NONE ctermfg=0 gui=bold guifg=NONE
    " autocmd ColorScheme * highlight CursorLineNr term=bold ctermbg=NONE ctermfg=0 gui=bold guifg=Yellow
    "
    "
    " highlight NonText guifg=#1d1f21 | " make non printable chars invisible. The active line is an exception.
    " highlight ColorColumn guibg=#005f87
    " highlight ColorColumn guibg=#F0F0E0
  augroup END " }


  " hitting K over a keyword shows a help in a buffer.
  " Here we define the commands used to look those keywords up
  " as per file type...
  augroup keyword_lookups
    autocmd FileType python setlocal keywordprg=pydoc
    autocmd FileType vim    setlocal keywordprg=:help |.
  augroup END


  augroup ChangeCursor
    autocmd VimEnter * let &t_EI .= "\<Esc>[0 q"
    autocmd VimEnter * let &t_SI = "\<Esc>]12;yellow\x7"
    autocmd VimLeave * silent !echo -ne "\033]112\007"
  augroup END

  "set omnifunc=syntaxcomplete#Complete
  " au BufNewFile,BufRead,BufEnter *.cpp,*.hpp set omnifunc=omni#cpp#complete#Main
  " Enable omni completion.
  " autocmd FileType css setlocal omnifunc=csscomplete#CompleteCSS
  " autocmd FileType html,markdown setlocal omnifunc=htmlcomplete#CompleteTags
  " auto complete closing tag name when entering </-[space]
  " autocmd Filetype html,markdown,xml iabbrev </ </<C-X><C-O>
  " autocmd FileType python setlocal omnifunc=jedi#completions
  " following autocommands are there to call neovim functions...
  " autocmd FileType python setlocal omnifunc=pythoncomplete#Complete
  " autocmd FileType javascript setlocal omnifunc=javascriptcomplete#CompleteJS
  " autocmd FileType xml setlocal omnifunc=xmlcomplete#CompleteTags
  " " Enable heavy omni completion.
  " if !exists('g:neocomplete#sources#omni#input_patterns')
  "   let g:neocomplete#sources#omni#input_patterns = {}
  " endif
endif


let base16colorspace=256
if filereadable(expand("~/.vimrc_background"))
  source ~/.vimrc_background
  set background=light
else
  colorscheme base16-phd
  set background=dark
endif
" colorscheme base16-embers
" colorscheme base16-flat
" colorscheme base16-summerfruit-dark
" colorscheme base16-tommorow
" colorscheme base16-default-dark


" colorscheme customizations =========================
" override colorscheme's background color in order to honor the terminals background transparency



" if filereadable(expand("~/.vimrc_background"))
"   let base16colorspace=256
"   source ~/.vimrc_background
" endif
" set colorcolumn=80            | " show an indicator (different background in column 80)
" set title
" set t_ts=^[k
" set t_fs=^[\
" auto BufEnter * :set title | let &titlestring = 'v:' . expand('%')
" auto VimLeave * :set t_ts=^[k^[\
"
" ALTERNATIVE:                                        |
" LightLine_and_MiniBufExplorer: =====================.
" Plug 'itchyny/lightline.vim'
" let g:lightline = {
"       \ 'colorscheme': 'PaperColor',
"       \ 'separator': { 'left': "\ue0b0", 'right': "\ue0b2" },
"       \ 'subseparator': { 'left': "\ue0b1", 'right': "\ue0b3" }
"       \ }
" Plug 'fholgado/minibufexpl.vim'
" let g:miniBufExplAutoStart = 1
" let g:miniBufExplBRSplit = 1
" let g:miniBufExplShowBufNumbers = 0
" let g:miniBufExplSplitToEdge = 1
" let g:miniBufExplVSplit = 20   " column width in chars
" NETRW: =============================================.
" Plug 'tpope/vim-vinegar'                              | " Improves :Explore
" let g:netrw_list_hide     = '^\..*'                   | " Explore mode: hide files starting with dot
" let g:netrw_hide          = 1                         | " show not-hidden files only
" let g:netrw_liststyle     = 3                         | " 3=tree
" let g:netrw_banner        = 0                         | " display help messages?
" let g:netrw_winsize       = 20                        | " window size in percent
" let g:netrw_fastbrowse    = 2                         | " manually refresh direcory list (avoids display errors)
" let g:netrw_keepdir       = 0
" let g:netrw_browse_split  = 4                         | " 4=open in previous window
" let g:netrw_preview       = 0                         | "
" let g:netrw_alto          = 0                         | " open files on the right
" let g:netrw_altv          = 1                         | " open files on the right
..