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