9817a3d79d61357cfc2d59a30af46c7bc6981c29
[vimconf.git] / init.vim
1 " My personal vim, nvim, gvim configuration
2 " Author: Stefan Huber <shuber@sthu.org>
3
4
5 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""
6 " Some global settings
7
8 set nocompatible
9 " Breaks colors for some versions of mosh, but not if tmux is used on top of
10 " mosh. See https://github.com/mobile-shell/mosh/issues/928
11 set termguicolors
12 set number
13 set cursorline
14 set scrolloff=5
15
16 set encoding=utf-8
17
18 set fillchars=vert:│,fold:\
19 set listchars=tab:»­,trail:·,eol:$
20 set virtualedit=block
21
22 filetype plugin indent on
23
24 set tabstop=4
25 set shiftwidth=4
26 set expandtab
27 set smarttab
28
29 set autoindent
30 set smartindent
31
32 set incsearch
33 set hlsearch
34
35 set foldcolumn=4
36 set foldlevelstart=20
37
38 set colorcolumn=+1
39 set mouse=a
40 set wildmenu
41 set wildmode=longest,list:full
42
43 set tabpagemax=100
44
45 syntax on
46
47 " Load some macros
48 runtime macros.vim
49
50 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""
51 " Some global plugin settings
52
53 " Disable devicons on linux terminal
54 if $TERM == 'linux'
55 let g:enable_plugin_devicons=0
56 " Enable loading of devicons on all others
57 else
58 let g:enable_plugin_devicons=1
59 endif
60
61 runtime plugsetup.vim
62
63 let g:EditorConfig_exclude_patterns = ['fugitive://.*', 'scp://.*']
64
65 " Some preferences for indent detection
66 let g:detectindent_min_indent = 2
67 let g:detectindent_max_indent = 4
68 let g:detectindent_preferred_indent = 4
69
70 " Attention: Must be run after plugsetup.vim
71 " Trailing whitespace
72 highlight default link BadWhitespace SpellCap
73
74 " Setup BadWhitespace syntax match expressions.
75 function SetBadWhitespaceSyntax()
76 " Do not expose bad whitespace in help buffers or for man pages. Or, more
77 " generally, if we open the file readonly.
78 "if &ft != "help" && &ft != "man"
79 if !&readonly
80 " Make trailing whitespace be flagged as bad.
81 syn match BadWhitespace /\s\+$/ containedin=ALL
82 " Make space before tab be flagged as bad and vice versa
83 syn match BadWhitespace / \+\t/ containedin=ALL
84 syn match BadWhitespace /\t \+/ containedin=ALL
85 endif
86 endfunction
87
88 " Make trailing whitespace be flagged as bad.
89 au BufRead,BufNewFile * call SetBadWhitespaceSyntax()
90
91 let g:airline_powerline_fonts=1
92 let g:airline#extensions#tabline#enabled=1
93 let g:airline#extensions#branch#enabled=1
94
95 let g:gruvbox_contrast_light='hard'
96 let g:gruvbox_contrast_dark='hard'
97 let g:gruvbox_italic = 1
98 set bg=dark
99 colorscheme gruvbox
100
101 " let NERDTreeWinPos="right"
102 let NERDTreeHijackNetrw=0
103 let NERDTreeWinSize=22
104 let NERDTreeQuitOnOpen=1
105 "au VimEnter * if !argc() | Startify | NERDTree | wincmd w
106
107 let g:neomake_c_enabled_makers = ['clangtidy', 'clangcheck']
108 let g:neomake_cpp_enabled_makers = ['clangtidy', 'clangcheck']
109
110 " Taken from neomake
111 if OnBattery()
112 call neomake#configure#automake('w')
113 else
114 call neomake#configure#automake('nw', 1000)
115 endif
116
117 let g:clang_compilation_database = '.'
118
119 " Speedup deoplete startup time, see deoplete FAQ
120 let g:python3_host_prog = '/usr/bin/python3'
121 " deoplete requires huge startuptime. Delay loading upon first InsertEnter.
122 let g:deoplete#enable_at_startup = 0
123 call deoplete#custom#option({
124 \ 'smart_case' : v:true,
125 \ 'auto_refresh_delay' : 100,
126 \ })
127 au InsertEnter * call deoplete#enable()
128
129 "augroup pencil
130 "au!
131 "au FileType markdown,mkd call pencil#init()
132 "au FileType text call pencil#init()
133 "au FileType mail call pencil#init()
134 "au FileType tex call pencil#init()
135 "augroup END
136
137 let g:vim_markdown_frontmatter=1
138 let g:vim_markdown_math=1
139
140
141 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""
142 " Some filetype-specific settings
143
144 au FileType text,markdown,asciidoc,mail,gitcommit,mediawiki,vimwiki,tex setlocal spell
145 au FileType text,markdown,asciidoc,mail,gitcommit,mediawiki,vimwiki setlocal formatoptions+=n
146 au Filetype mail setlocal formatoptions+=o
147 " Add | for block quotation, such that gq respects it
148 au Filetype mail setlocal comments+=n:\|,
149
150 au Filetype go setlocal shiftwidth=8 tabstop=8 noexpandtab
151 au Filetype tex setlocal shiftwidth=2 tabstop=2
152
153 au FileType mediawiki setlocal wrap linebreak textwidth=0
154
155 "git scissor line
156 au Filetype mail syn match Statement /^\s*-*\s*>8\s*-*\s*$/
157 au Filetype mail syn match Statement /^\s*-*\s*8<\s*-*\s*$/
158
159 " Line wrap crippled with numbers shown
160 au Filetype man setlocal nonumber
161
162 " Minimum indenting for source code
163 au FileType java,cpp,c,cs let g:detectindent_min_indent = 4
164 " Consider using localvimrc config file or editorconfig instead
165 "au BufReadPost *.java :DetectIndent
166
167 au BufEnter *.c* let b:fswitchlocs='reg:/lib/include/,rel:.'
168 au BufEnter *.h* let b:fswitchlocs='reg:/include/lib/,rel:.'
169
170 au BufEnter *.cpp,*.cc,*.cxx let b:fswitchdst='h,hxx,hpp,hh'
171 au BufEnter *.h,*.hh,*.hxx let b:fswitchdst='cc,c,cxx,cpp'
172 au BufNewFile *.{h,hpp,hxx} call AddIncludeGuards()
173
174 augroup autofoldcolumn
175 au!
176 au CursorHold,BufWinEnter * AutoOrigamiFoldColumn
177 augroup END
178
179 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""
180 " Some plugin-specific settings
181
182 let g:localvimrc_persistent = 1
183
184 let g:fastfold_minlines = 0
185
186 au FileType markdown call RagtagInit()
187
188 let g:detectspelllang_langs = {}
189 let g:detectspelllang_langs.aspell =[ 'en_US', 'de_AT']
190 au FileType mail let g:VimMailSpellLangs=['de', 'en']
191
192 :let g:org_todo_keywords = [['TODO(t)', 'WAITING(w)', '|', 'DONE(d)'],
193 \ ['|', 'OBSOLETE(o)', 'WONT(n)'],
194 \ ['CANCELED(c)']]
195
196 let g:vimwiki_list = [{'path': '~/.vimwiki/',
197 \ 'template_path': '~/.vim/vimwiki/templates',
198 \ 'template_default': 'default',
199 \ 'template_ext': '.html'}]
200 let g:vimwiki_global_ext = 0
201
202 " Java completion
203 au FileType java setlocal omnifunc=javacomplete#Complete
204 au FileType java JCEnable
205
206 let g:VimMailContactsProvider=['khard']
207 let g:VimMailContactsCommands={
208 \'khard':
209 \{ 'query' : "khard email --parsable --search-in-source-files",
210 \'sync': "/bin/true"}
211 \}
212
213 let g:vimtex_fold_enabled = 1
214 let g:vimtex_fold_levelmarker = '➜'
215
216 " The denite settings are largely stolen from spacevim
217 let s:denite_options = {
218 \ 'default' : {
219 \ 'winheight' : 15,
220 \ 'mode' : 'insert',
221 \ 'start_filter' : 1,
222 \ 'quit' : 1,
223 \ 'highlight_matched_char' : 'MoreMsg',
224 \ 'highlight_matched_range' : 'MoreMsg',
225 \ 'direction': 'rightbelow',
226 \ }}
227
228 augroup spacevim_layer_denite
229 autocmd!
230 autocmd FileType denite call s:denite_my_settings()
231 augroup END
232
233 function! s:denite_my_settings() abort
234 nnoremap <silent><buffer><expr> i
235 \ denite#do_map('open_filter_buffer')
236 nnoremap <silent><buffer><expr> '
237 \ denite#do_map('toggle_select').'j'
238 nnoremap <silent><buffer><expr> q
239 \ denite#do_map('quit')
240 nnoremap <silent><buffer><expr> <C-t>
241 \ denite#do_map('do_action', 'tabopen')
242 nnoremap <silent><buffer><expr> <C-v>
243 \ denite#do_map('do_action', 'vsplit')
244 nnoremap <silent><buffer><expr> <C-s>
245 \ denite#do_map('do_action', 'split')
246 nnoremap <silent><buffer><expr> <CR>
247 \ denite#do_map('do_action')
248 nnoremap <silent><buffer><expr> p
249 \ denite#do_map('do_action', 'preview')
250 nnoremap <silent><buffer><Tab> j
251 nnoremap <silent><buffer><S-Tab> k
252 endfunction
253
254 " FIND and GREP COMMANDS
255 if executable('rg')
256 " Ripgrep command on grep source
257 call denite#custom#var('grep', 'command', ['rg'])
258 call denite#custom#var('grep', 'default_opts',
259 \ ['--vimgrep', '--no-heading'])
260 call denite#custom#var('grep', 'recursive_opts', [])
261 call denite#custom#var('grep', 'pattern_opt', ['--regexp'])
262 call denite#custom#var('grep', 'separator', ['--'])
263 call denite#custom#var('grep', 'final_opts', [])
264 endif
265
266 let s:insert_mode_mappings = [
267 \ ['jk', '<denite:enter_mode:normal>', 'noremap'],
268 \ ['<Tab>', '<denite:move_to_next_line>', 'noremap'],
269 \ ['<C-j>', '<denite:move_to_next_line>', 'noremap'],
270 \ ['<S-tab>', '<denite:move_to_previous_line>', 'noremap'],
271 \ ['<C-k>', '<denite:move_to_previous_line>', 'noremap'],
272 \ ['<C-t>', '<denite:do_action:tabopen>', 'noremap'],
273 \ ['<C-v>', '<denite:do_action:vsplit>', 'noremap'],
274 \ ['<C-s>', '<denite:do_action:split>', 'noremap'],
275 \ ['<Esc>', '<denite:enter_mode:normal>', 'noremap'],
276 \ ['<C-N>', '<denite:assign_next_matched_text>', 'noremap'],
277 \ ['<C-P>', '<denite:assign_previous_matched_text>', 'noremap'],
278 \ ['<Up>', '<denite:assign_previous_text>', 'noremap'],
279 \ ['<Down>', '<denite:assign_next_text>', 'noremap'],
280 \ ['<C-Y>', '<denite:redraw>', 'noremap'],
281 \ ]
282
283 let s:normal_mode_mappings = [
284 \ ["'", '<denite:toggle_select_down>', 'noremap'],
285 \ ['<C-n>', '<denite:jump_to_next_source>', 'noremap'],
286 \ ['<C-p>', '<denite:jump_to_previous_source>', 'noremap'],
287 \ ['<Tab>', '<denite:move_to_next_line>', 'noremap'],
288 \ ['<C-j>', '<denite:move_to_next_line>', 'noremap'],
289 \ ['<S-tab>', '<denite:move_to_previous_line>', 'noremap'],
290 \ ['<C-k>', '<denite:move_to_previous_line>', 'noremap'],
291 \ ['gg', '<denite:move_to_first_line>', 'noremap'],
292 \ ['<C-t>', '<denite:do_action:tabopen>', 'noremap'],
293 \ ['<C-v>', '<denite:do_action:vsplit>', 'noremap'],
294 \ ['<C-s>', '<denite:do_action:split>', 'noremap'],
295 \ ['q', '<denite:quit>', 'noremap'],
296 \ ['r', '<denite:redraw>', 'noremap'],
297 \ ]
298
299 " termdebug split windows
300 let g:termdebug_wide=1
301
302 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""
303
304 runtime keymaps.vim
305
306 if filereadable($HOME . '/.vim/init-local.vim')
307 source ~/.vim/init-local.vim
308 endif