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