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