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 set tabstop=4 softtabstop=4 shiftwidth=4 textwidth=79 expandtab autoindent foldmethod=indent
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>A :SyntasticToggleMode<CR>
141 nnoremap <Leader>n :lnext<CR>
144 nnoremap <Leader>c :call Clean_file()<CR><CR>
146 nnoremap <Leader>r :set rightleft<CR>
147 nnoremap <Leader>R :set norightleft<CR>
149 nnoremap <Leader>g :GitGutterSignsToggle<CR>
152 nnoremap <Leader>; i"<ESC>lea"<ESC>l
153 nnoremap <Leader>' i"<ESC>A"<ESC>l
154 nnoremap <Leader>[ i[<ESC>lea]<ESC>l
155 nnoremap <Leader>] i{<ESC>lea}<ESC>l
160 "==============================================================================
162 "==============================================================================
164 set statusline=\ %F%#StatusLine_g#\ %m%#StatusLine_r#\ %r%*%=
165 set statusline+=%y\ %{&encoding}\ %{&fileformat}\ %c
168 set statusline+=%#StatusLine_o#
169 set statusline+=%{StatuslineTabWarning()}
170 set statusline+=%{StatuslineTrailingSpaceWarning()}
173 "recalculate the tab warning flag when idle and after writing
174 autocmd cursorhold,bufwritepost * unlet! b:statusline_tab_warning
175 autocmd cursorhold,bufwritepost * unlet! b:statusline_trailing_space_warning
177 function! StatuslineTrailingSpaceWarning()
178 if !exists("b:statusline_trailing_space_warning")
179 let result = search('\s\+$', 'nw') != 0
181 let b:statusline_trailing_space_warning = ' [TS]'
183 let b:statusline_trailing_space_warning = ''
186 return b:statusline_trailing_space_warning
189 function! StatuslineTabWarning()
190 if !exists("b:statusline_tab_warning")
191 let b:statusline_tab_warning = ''
193 return b:statusline_tab_warning
195 let tabs = search('^\t', 'nw') != 0
196 "find spaces that arent used as alignment in the first indent column
197 let spaces = search('^ \{' . &ts . ',}[^\t]', 'nw') != 0
199 let b:statusline_tab_warning = ' [MI]'
200 elseif (spaces && !&et) || (tabs && &et)
201 let b:statusline_tab_warning = '[&et]'
204 return b:statusline_tab_warning
207 "==============================================================================
209 "==============================================================================
210 let g:syntastic_python_checkers = ["pylint"]
211 let g:syntastic_sh_checkers = ["shellcheck"]
212 let g:syntastic_c_checkers = ["splint"]
213 " Moderately strict checking
214 let g:syntastic_c_splint_args = "-checks +posixlib -DVERSION=\\\"VERSION\\\""
216 set statusline+=%#statusline_r#
217 set statusline+=\ %{SyntasticStatuslineFlag()}
220 let g:syntastic_check_on_wq = 0
221 let g:syntastic_auto_loc_list = 0
222 let g:syntastic_check_on_open = 1
223 let g:syntastic_enable_highlighting = 0 "underline word
224 let g:syntastic_always_populate_loc_list = 1
225 let g:syntastic_auto_jump = 0
228 let g:syntastic_error_symbol = ''
229 let g:syntastic_warning_symbol = ''
230 let g:syntastic_style_error_symbol = ''
231 let g:syntastic_style_warning_symbol = '!'
233 "==============================================================================
235 "==============================================================================
239 function! MyFoldText() " {{{
240 let line = getline(v:foldstart)
241 let nucolwidth = &fdc + &number * &numberwidth
242 let windowwidth = winwidth(0) - nucolwidth - 3
243 let foldedlinecount = v:foldend - v:foldstart
244 let onetab = strpart(' ', 0, &tabstop)
245 let line = substitute(line, '\t', onetab, 'g')
246 let line = strpart(line, 0, windowwidth - 2 -len(foldedlinecount))
247 let fillcharcount = 81 - len(line) - len(foldedlinecount)
248 let rest = windowwidth - fillcharcount
249 return line . repeat(" ",fillcharcount) . foldedlinecount .' ' . repeat(" ", rest)
252 set foldtext=MyFoldText()
254 "==============================================================================
255 " File type highlight
256 "==============================================================================
258 augroup filetypedetect
259 autocmd BufNewFile,BufRead *.h set filetype=c
260 autocmd BufNewFile,BufRead *.csv set filetype=csv
261 autocmd BufNewFile,BufRead *.gpg set filetype=gpg
262 autocmd BufNewFile,BufRead LICENSE set filetype=text
263 autocmd BufNewFile,BufRead README set filetype=markdown
267 let g:rcsv_colorpairs = [
275 \['darkgreen', 'darkgreen'],
276 \['darkmagenta', 'darkmagenta'],
277 \['darkcyan', 'darkcyan']]
279 "==============================================================================
281 "==============================================================================
282 let g:completor_auto_trigger = 1
283 let g:completor_clang_binary = '/usr/bin/clang'
284 let g:completor_complete_options = 'menuone,noselect,preview'
286 inoremap <expr> <Tab> pumvisible() ? "\<C-n>" : "\<Tab>"
287 inoremap <expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<S-Tab>"
289 "==============================================================================
290 " Remove characters function
291 "==============================================================================
292 function! Clean_file()
294 let save_pos = getpos(".")
295 " Remove spaces from begin & end of line
296 " Remove spaces after tab
298 " Remove file last line if empty
299 " Remove more than 2 empty lines
304 \%s/\($\n\)\+\%$//e |
306 " Return to saved cursor
307 call setpos(".", save_pos)
310 "==============================================================================
312 "==============================================================================
313 let g:filename = expand("%:r")
314 let g:filename_ext = expand("%:e")
315 let g:upperfilename = toupper(filename)
317 autocmd BufNewFile *.sh exe "normal!ggi#!/usr/bin/env bash
\r"
318 autocmd BufNewFile *.py exe "normal!ggi#!/usr/bin/env python3
\r"
319 autocmd BufNewFile *.h :call TempH()
320 autocmd BufNewFile *.c :call TempC()
323 exe "normal!ggi/* See LICENSE file for copyright and license details. */
\r"
324 exe "normal!o#ifndef ".g:upperfilename."_H"
325 exe "normal!o#define ".g:upperfilename."_H"
326 exe "normal!o
\r\r\r#endif /* ".g:upperfilename."_H */"
331 exe "normal!ggi/* See LICENSE file for copyright and license details. */
\r"
332 exe "normal!o/* macros */"
333 exe "normal!o/* typedef */"
334 exe "normal!o/* function declarations */"
335 exe "normal!o/* function implementations */
\r"
336 exe "normal!oint
\rmain(void)
\r{
\r\rreturn 0;
\r}"