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 'maralla/completor.vim'
20 Plug 'vim-syntastic/syntastic'
23 "==============================================================================
25 "==============================================================================
28 set listchars=tab:>—,nbsp:␣,trail:.
32 set splitbelow splitright
34 set wildmode=list:full,full
38 autocmd FileType python set tabstop=4 softtabstop=4 shiftwidth=4 textwidth=79 expandtab autoindent foldmethod=indent
39 autocmd FileType c setlocal ts=8 sw=8
40 autocmd FilterWritePre * if &diff | set foldcolumn=0 | endif
44 filetype plugin indent on
46 "==============================================================================
48 "==============================================================================
49 "copy to global clipboard
50 vmap <C-c> y:call system("xclip -i -selection clipboard", getreg("\""))<cr>:call system("xclip -i", getreg("\""))<cr>
52 " replace word with yanked
53 nnoremap <C-p> cw<C-r>0<ESC>
56 nnoremap <C-c> :set invpaste paste?<CR>
60 "Move lines up and down with controle + k or j
61 nnoremap <silent> <C-j> :move +1 <CR>
62 nnoremap <silent> <C-k> :move -2 <CR>
64 "Disable keys in Normal mode
77 "Disable keys in Insert mode
90 " Go (start|end) of line
95 nnoremap <Leader><CR> <Esc>:vsplit
97 nnoremap <silent> <Leader>= :vertical resize +1<CR>
98 nnoremap <silent> <Leader>- :vertical resize -1<CR>
99 nnoremap <silent> <Leader>0 :vertical resize 87<CR>
101 nnoremap <Left> <C-w>h
102 nnoremap <Down> <C-w>j
104 nnoremap <Right> <C-w>l
107 nnoremap <Leader><Left> <C-w>H
108 nnoremap <Leader><Down> <C-w>J
109 nnoremap <Leader><Up> <C-w>K
110 nnoremap <Leader><Right> <C-w>L
113 nnoremap <Leader>f :set hlsearch<CR>/^[a-z*].*(.*)$<CR>
114 nnoremap <Leader>o :set hlsearch!<CR>/\%80v.\+/<CR>
115 nnoremap <Leader>s :set hlsearch!<CR>
120 " inoremap ( ()<Left>
121 " inoremap { {}<Left>
122 " inoremap [ []<Left>
123 " inoremap " ""<Left>
124 " inoremap ' ''<Left>
127 nnoremap <Leader>q :qa!<CR>
130 nnoremap <Leader>z zM
131 nnoremap <Leader>Z zR
134 nnoremap <Leader>a :SyntasticCheck<CR>
135 nnoremap <Leader>A :SyntasticToggleMode<CR>
136 nnoremap <Leader>n :lnext<CR>
139 nnoremap <Leader>c :call Clean_file()<CR><CR>
141 nnoremap <Leader>r :set rightleft<CR>
142 nnoremap <Leader>R :set norightleft<CR>
145 nnoremap <Leader>g :GitGutterSignsToggle<CR>
146 nmap <Enter> <Plug>(GitGutterPreviewHunk)
149 nnoremap <Leader>; i"<ESC>lea"<ESC>l
150 nnoremap <Leader>' i"<ESC>A"<ESC>l
151 nnoremap <Leader>[ i[<ESC>lea]<ESC>l
152 nnoremap <Leader>] i{<ESC>lea}<ESC>l
157 "==============================================================================
159 "==============================================================================
161 set statusline=\ %F%#StatusLine_g#\ %m%#StatusLine_r#\ %r%*%=
162 set statusline+=%y\ %{&encoding}\ %{&fileformat}\ %c
165 set statusline+=%#StatusLine_o#
166 set statusline+=%{StatuslineTabWarning()}
167 set statusline+=%{StatuslineTrailingSpaceWarning()}
170 "recalculate the tab warning flag when idle and after writing
171 autocmd cursorhold,bufwritepost * unlet! b:statusline_tab_warning
172 autocmd cursorhold,bufwritepost * unlet! b:statusline_trailing_space_warning
174 function! StatuslineTrailingSpaceWarning()
175 if !exists("b:statusline_trailing_space_warning")
176 let result = search('\s\+$', 'nw') != 0
178 let b:statusline_trailing_space_warning = ' [TS]'
180 let b:statusline_trailing_space_warning = ''
183 return b:statusline_trailing_space_warning
186 function! StatuslineTabWarning()
187 if !exists("b:statusline_tab_warning")
188 let b:statusline_tab_warning = ''
190 return b:statusline_tab_warning
192 let tabs = search('^\t', 'nw') != 0
193 "find spaces that arent used as alignment in the first indent column
194 let spaces = search('^ \{' . &ts . ',}[^\t]', 'nw') != 0
196 let b:statusline_tab_warning = ' [MI]'
197 elseif (spaces && !&et) || (tabs && &et)
198 let b:statusline_tab_warning = '[&et]'
201 return b:statusline_tab_warning
204 "==============================================================================
206 "==============================================================================
207 let g:syntastic_python_checkers = ["pylint"]
208 let g:syntastic_sh_checkers = ["shellcheck"]
209 let g:syntastic_c_checkers = ["splint"]
210 " Moderately strict checking
211 let g:syntastic_c_splint_args = "-checks +posixlib ./util.c -DVERSION=\\\"VERSION\\\""
213 set statusline+=%#statusline_r#
214 set statusline+=\ %{SyntasticStatuslineFlag()}
217 let g:syntastic_check_on_wq = 0
218 let g:syntastic_auto_loc_list = 0
219 let g:syntastic_check_on_open = 1
220 let g:syntastic_enable_highlighting = 0 "underline word
221 let g:syntastic_always_populate_loc_list = 1
222 let g:syntastic_auto_jump = 0
225 let g:syntastic_error_symbol = ''
226 let g:syntastic_warning_symbol = ''
227 let g:syntastic_style_error_symbol = ''
228 let g:syntastic_style_warning_symbol = '!'
230 "==============================================================================
232 "==============================================================================
235 set foldmethod=syntax
237 function! MyFoldText() " {{{
238 let line = getline(v:foldstart)
239 let nucolwidth = &fdc + &number * &numberwidth
240 let windowwidth = winwidth(0) - nucolwidth - 3
241 let foldedlinecount = v:foldend - v:foldstart
242 let onetab = strpart(' ', 0, &tabstop)
243 let line = substitute(line, '\t', onetab, 'g')
244 let line = strpart(line, 0, windowwidth - 2 -len(foldedlinecount))
245 let fillcharcount = 81 - len(line) - len(foldedlinecount)
246 let rest = windowwidth - fillcharcount
247 return line . repeat(" ",fillcharcount) . foldedlinecount .' ' . repeat(" ", rest)
250 set foldtext=MyFoldText()
252 "==============================================================================
253 " File type highlight
254 "==============================================================================
256 augroup filetypedetect
257 autocmd BufNewFile,BufRead *.h set filetype=c
258 autocmd BufNewFile,BufRead *.csv set filetype=csv
259 autocmd BufNewFile,BufRead *.gpg set filetype=gpg
260 autocmd BufNewFile,BufRead LICENSE set filetype=text
261 autocmd BufNewFile,BufRead README set filetype=markdown
264 "==============================================================================
266 "==============================================================================
267 let g:completor_auto_trigger = 1
268 let g:completor_clang_binary = '/usr/bin/clang'
269 let g:completor_complete_options = 'menuone,noselect,preview'
271 inoremap <expr> <Tab> pumvisible() ? "\<C-n>" : "\<Tab>"
272 inoremap <expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<S-Tab>"
274 "==============================================================================
275 " Remove characters function
276 "==============================================================================
277 function! Clean_file()
279 let save_pos = getpos(".")
280 " Remove spaces from begin & end of line
281 " Remove spaces after tab
283 " Remove file last line if empty
284 " Remove more than 2 empty lines
285 " Remove empty comment lines
286 " TODO remove 2 spaces between words
292 \%s/\($\n\)\+\%$//e |
294 " Return to saved cursor
295 call setpos(".", save_pos)
299 "==============================================================================
301 "==============================================================================
302 let g:filename = expand("%:r")
303 let g:filename_ext = expand("%:e")
304 let g:upperfilename = toupper(filename)
306 autocmd BufNewFile *.sh normal!ggi#!/bin/sh
\r
307 autocmd BufNewFile *.py normal!ggi#!/usr/bin/env python3
\r
308 autocmd BufNewFile *.h exe "normal!ggi/* See LICENSE file for copyright and "
309 \"license details. */
\r\r#ifndef ".g:upperfilename."_H
\r#define "
310 \.g:upperfilename."_H
\r\r\r\r\#endif /* ".g:upperfilename."_H */" | normal!kk
311 autocmd BufNewFile *.c exe "normal!ggi/* See LICENSE file for copyright and license"
312 \"details. */
\r\r#include <stdio.h>
\r\r/* macros */
\r/* typedef */
\r/*"
313 \"function declarations */
\r/*"
314 \"global variables */
\r/* function implementations */
\r\rint
\rmain(int argc,"
315 \" char *argv[])
\r{
\r\rreturn 0;
\r}" | normal!kk