1 "==============================================================================
3 "==============================================================================
10 set backspace=indent,eol,start
12 "==============================================================================
14 "==============================================================================
15 source ~/.vim/comment.vim
17 call plug#begin('~/.vim/plugged')
18 Plug 'airblade/vim-gitgutter'
19 " Plug 'justinmk/vim-syntax-extra'
20 " Plug 'ap/vim-css-color'
21 " Plug 'mechatroner/rainbow_csv'
22 Plug 'MTDL9/vim-log-highlighting'
23 Plug 'maralla/completor.vim'
24 Plug 'vim-syntastic/syntastic'
27 "==============================================================================
29 "==============================================================================
32 set listchars=tab:>—,nbsp:␣,trail:.
36 set splitbelow splitright
38 set wildmode=list:full,full
39 set ignorecase "search case insensitive
40 set smartcase "if uppercase case sensitive
42 autocmd Filetype python setlocal ts=4 sw=4 expandtab
43 autocmd FileType c setlocal ts=8 sw=8
44 autocmd FilterWritePre * if &diff | set foldcolumn=0 | endif
48 " filetype plugin indent on
50 "==============================================================================
52 "==============================================================================
53 "copy to global clipboard
54 vmap <C-c> y:call system("xclip -i -selection clipboard", getreg("\""))<cr>:call system("xclip -i", getreg("\""))<cr>
56 " replace word with yanked
57 nnoremap <C-p> cw<C-r>0<ESC>
60 nnoremap <C-c> :set invpaste paste?<CR>
64 "Move lines up and down with controle + k or j
65 nnoremap <silent> <C-j> :move +1 <CR>
66 nnoremap <silent> <C-k> :move -2 <CR>
68 "Disable keys in Normal mode
81 "Disable keys in Insert mode
94 " Go (start|end) of line
99 nnoremap <Leader><CR> <Esc>:vsplit
101 nnoremap <silent> <Leader>= :vertical resize +1<CR>
102 nnoremap <silent> <Leader>- :vertical resize -1<CR>
103 nnoremap <silent> <Leader>0 :vertical resize 87<CR>
105 nnoremap <Leader>j <C-w>j
106 nnoremap <Leader>k <C-w>k
107 nnoremap <Leader>l <C-w>l
108 nnoremap <Leader>h <C-w>h
111 nnoremap <Leader>L <C-w>L
112 nnoremap <Leader>H <C-w>H
113 nnoremap <Leader>J <C-w>J
114 nnoremap <Leader>K <C-w>K
117 nnoremap <Leader>f :set hlsearch<CR>/^[a-z].*(.*)$<CR>
118 nnoremap <Leader>o :set hlsearch!<CR>/\%80v.\+/<CR>
119 nnoremap <Leader>s :set hlsearch!<CR>
124 " inoremap ( ()<Left>
125 " inoremap { {}<Left>
126 " inoremap [ []<Left>
127 " inoremap " ""<Left>
128 " inoremap ' ''<Left>
131 nnoremap <Leader>q :qa!<CR>
134 nnoremap za :set foldmethod=syntax<CR>za
135 nnoremap <Leader>z :set foldmethod=syntax<CR>zM
136 nnoremap <Leader>Z :set foldmethod=syntax<CR>zR
139 nnoremap <Leader>a :SyntasticCheck<CR>
140 nnoremap <Leader>n :lnext<CR>
143 nnoremap <Leader>c :call Clean_file()<CR><CR>
145 nnoremap <Leader>r :set rightleft<CR>
146 nnoremap <Leader>R :set norightleft<CR>
149 nnoremap <Leader>' i"<ESC>ea"<ESC><Right>
150 nnoremap <Leader>" i"<ESC>A"<ESC><Right>
151 nnoremap <Leader>[ i{<ESC>ea"<ESC><Right>
156 "==============================================================================
158 "==============================================================================
160 set statusline=\ %F%#StatusLine_g#\ %m%#StatusLine_r#\ %r%*%=
161 set statusline+=%y\ %{&encoding}\ %{&fileformat}
164 set statusline+=%#StatusLine_o#
165 set statusline+=%{StatuslineTabWarning()}
166 set statusline+=%{StatuslineTrailingSpaceWarning()}
169 "recalculate the tab warning flag when idle and after writing
170 autocmd cursorhold,bufwritepost * unlet! b:statusline_tab_warning
171 autocmd cursorhold,bufwritepost * unlet! b:statusline_trailing_space_warning
173 function! StatuslineTrailingSpaceWarning()
174 if !exists("b:statusline_trailing_space_warning")
175 let result = search('\s\+$', 'nw') != 0
177 let b:statusline_trailing_space_warning = ' [TS]'
179 let b:statusline_trailing_space_warning = ''
182 return b:statusline_trailing_space_warning
185 function! StatuslineTabWarning()
186 if !exists("b:statusline_tab_warning")
187 let b:statusline_tab_warning = ''
189 return b:statusline_tab_warning
191 let tabs = search('^\t', 'nw') != 0
192 "find spaces that arent used as alignment in the first indent column
193 let spaces = search('^ \{' . &ts . ',}[^\t]', 'nw') != 0
195 let b:statusline_tab_warning = ' [MI]'
196 elseif (spaces && !&et) || (tabs && &et)
197 let b:statusline_tab_warning = '[&et]'
200 return b:statusline_tab_warning
203 "==============================================================================
205 "==============================================================================
206 let g:syntastic_python_checkers = ['pylint2']
207 let g:syntastic_sh_checkers = ["shellcheck"]
208 let g:syntastic_c_checkers = ["splint"]
209 " Moderately strict checking
210 let g:syntastic_c_splint_args = "-checks -DVERSION=\\\"VERSION\\\""
212 set statusline+=%#statusline_r#
213 set statusline+=\ %{SyntasticStatuslineFlag()}
216 let g:syntastic_check_on_wq = 0
217 let g:syntastic_auto_loc_list = 0
218 let g:syntastic_check_on_open = 1
219 let g:syntastic_enable_highlighting = 0 "underline word
220 let g:syntastic_always_populate_loc_list = 1
221 let g:syntastic_auto_jump = 0
224 let g:syntastic_error_symbol = ''
225 let g:syntastic_warning_symbol = ''
226 let g:syntastic_style_error_symbol = ''
227 let g:syntastic_style_warning_symbol = '!'
229 "==============================================================================
231 "==============================================================================
235 function! MyFoldText() " {{{
236 let line = getline(v:foldstart)
237 let nucolwidth = &fdc + &number * &numberwidth
238 let windowwidth = winwidth(0) - nucolwidth - 3
239 let foldedlinecount = v:foldend - v:foldstart
240 let onetab = strpart(' ', 0, &tabstop)
241 let line = substitute(line, '\t', onetab, 'g')
242 let line = strpart(line, 0, windowwidth - 2 -len(foldedlinecount))
243 let fillcharcount = 81 - len(line) - len(foldedlinecount)
244 let rest = windowwidth - fillcharcount
245 return line . repeat(" ",fillcharcount) . foldedlinecount .' ' . repeat(" ", rest)
248 set foldtext=MyFoldText()
250 "==============================================================================
251 " File type highlight
252 "==============================================================================
254 augroup filetypedetect
255 autocmd BufNewFile,BufRead *.h set filetype=c
256 autocmd BufNewFile,BufRead *.csv set filetype=csv
257 autocmd BufNewFile,BufRead *.gpg set filetype=gpg
258 autocmd BufNewFile,BufRead LICENSE set filetype=text
259 autocmd BufNewFile,BufRead README set filetype=markdown
263 let g:rcsv_colorpairs = [
271 \['darkgreen', 'darkgreen'],
272 \['darkmagenta', 'darkmagenta'],
273 \['darkcyan', 'darkcyan']]
275 "==============================================================================
277 "==============================================================================
278 let g:completor_auto_trigger = 1
279 let g:completor_clang_binary = '/usr/bin/clang'
280 let g:completor_complete_options = 'menuone,noselect,preview'
282 inoremap <expr> <Tab> pumvisible() ? "\<C-n>" : "\<Tab>"
283 inoremap <expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<S-Tab>"
285 "==============================================================================
286 " Remove characters function
287 "==============================================================================
288 function! Clean_file()
290 let save_pos = getpos(".")
291 " Remove spaces from begin & end of line
292 " Remove spaces after tab
294 " Remove file last line if empty
295 " Remove more than 2 empty lines
300 \%s/\($\n\)\+\%$//e |
302 " Return to saved cursor
303 call setpos(".", save_pos)
306 "==============================================================================
308 "==============================================================================
309 let g:filename = expand("%:r")
310 let g:filename_ext = expand("%:e")
311 let g:upperfilename = toupper(filename)
313 autocmd BufNewFile *.sh exe "normal!ggi#!/usr/bin/env bash
\r"
314 autocmd BufNewFile *.py exe "normal!ggi#!/usr/bin/env python3
\r"
315 autocmd BufNewFile *.h :call TempH()
316 autocmd BufNewFile *.c :call TempC()
319 exe "normal!ggi/* See LICENSE file for copyright and license details. */
\r"
320 exe "normal!o#ifndef ".g:upperfilename."_H"
321 exe "normal!o#define ".g:upperfilename."_H"
322 exe "normal!o
\r\r\r#endif /* ".g:upperfilename."_H */"
327 exe "normal!ggi/* See LICENSE file for copyright and license details. */
\r"
328 exe "normal!o/* macros */"
329 exe "normal!o/* typedef */"
330 exe "normal!o/* function declarations */"
331 exe "normal!o/* function implementations */
\r"
332 exe "normal!oint
\rmain(void)
\r{
\r\rreturn 0;
\r}"