1 "==============================================================================
3 "==============================================================================
10 set backspace=indent,eol,start
14 "==============================================================================
16 "==============================================================================
17 source ~/.vim/comment.vim
19 call plug#begin('~/.vim/plugged')
20 Plug 'airblade/vim-gitgutter'
21 Plug 'maralla/completor.vim'
22 Plug 'rhysd/vim-clang-format'
23 " Plug 'neoclide/coc.nvim', {'branch': 'release'}
24 Plug 'vim-syntastic/syntastic'
25 Plug 'ap/vim-css-color'
28 "==============================================================================
30 "==============================================================================
33 set listchars=tab:>—,nbsp:␣,trail:.
36 set noexpandtab " Use tabs, not spaces
37 set splitbelow splitright
39 set wildmode=list:full,full
43 autocmd FileType python set tabstop=4 softtabstop=4 shiftwidth=4 textwidth=79 expandtab autoindent foldmethod=indent
44 autocmd FileType html,css set ts=4 sw=4
45 autocmd FilterWritePre * if &diff | set foldcolumn=0 | endif
49 filetype plugin indent on
51 "==============================================================================
53 "==============================================================================
57 cnoremap w!! w !sudo tee % >/dev/null
59 "copy to global clipboard
60 vmap <C-c> y:call system("xclip -i -selection clipboard", getreg("\""))<cr>:call system("xclip -i", getreg("\""))<cr>
62 " replace word with yanked
63 nnoremap <C-p> cw<C-r>0<ESC>
66 nnoremap <C-c> :set invpaste paste?<CR>
70 "Move lines up and down with controle + k or j
71 nnoremap <silent> <C-j> :move +1 <CR>
72 nnoremap <silent> <C-k> :move -2 <CR>
74 "Disable keys in Normal mode
87 "Disable keys in Insert mode
100 " Go (start|end) of line
105 nnoremap <Leader><CR> <Esc>:vsplit
107 nnoremap <silent> <Leader>= :vertical resize +1<CR>
108 nnoremap <silent> <Leader>- :vertical resize -1<CR>
109 nnoremap <silent> <Leader>0 :vertical resize 87<CR>
111 nnoremap <Left> <C-w>h
112 nnoremap <Down> <C-w>j
114 nnoremap <Right> <C-w>l
117 nnoremap <Leader><Left> <C-w>H
118 nnoremap <Leader><Down> <C-w>J
119 nnoremap <Leader><Up> <C-w>K
120 nnoremap <Leader><Right> <C-w>L
123 nnoremap <Leader>f :set hlsearch<CR>/^[a-z*].*(.*)$<CR>
124 nnoremap <Leader>o :set hlsearch!<CR>/\%80v.\+/<CR>
125 nnoremap <Leader>s :set hlsearch!<CR>
127 vnoremap * y/\V<C-R>=escape(@",'/\')<CR><CR>
132 nnoremap <Leader>q :qa!<CR>
135 nnoremap <Leader>z zM
136 nnoremap <Leader>Z 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>
145 nnoremap <Leader>c :ClangFormat<CR>
147 nnoremap <Leader>r :set rightleft<CR>
148 nnoremap <Leader>R :set norightleft<CR>
151 nnoremap <Leader>g :GitGutterSignsToggle<CR>
152 nmap <Enter> <Plug>(GitGutterPreviewHunk)
153 nmap <Leader>1 <Plug>(GitGutterPrevHunk)
154 nmap <Leader>2 <Plug>(GitGutterNextHunk)
157 nnoremap <Leader>; i"<ESC>lea"<ESC>l
158 nnoremap <Leader>' i"<ESC>A"<ESC>l
159 nnoremap <Leader>[ i[<ESC>lea]<ESC>l
160 nnoremap <Leader>] i{<ESC>lea}<ESC>l
162 "==============================================================================
164 "==============================================================================
166 set statusline=\ %F%#StatusLine_g#\ %m%#StatusLine_r#\ %r%*%=
167 set statusline+=%y\ %{&encoding}\ %{&fileformat}\ %c
170 set statusline+=%#StatusLine_o#
171 set statusline+=%{StatuslineTabWarning()}
172 set statusline+=%{StatuslineTrailingSpaceWarning()}
175 "recalculate the tab warning flag when idle and after writing
176 autocmd cursorhold,bufwritepost * unlet! b:statusline_tab_warning
177 autocmd cursorhold,bufwritepost * unlet! b:statusline_trailing_space_warning
179 function! StatuslineTrailingSpaceWarning()
180 if !exists("b:statusline_trailing_space_warning")
181 let result = search('\s\+$', 'nw') != 0
183 let b:statusline_trailing_space_warning = ' [TS]'
185 let b:statusline_trailing_space_warning = ''
188 return b:statusline_trailing_space_warning
191 function! StatuslineTabWarning()
192 if !exists("b:statusline_tab_warning")
193 let b:statusline_tab_warning = ''
195 return b:statusline_tab_warning
197 let tabs = search('^\t', 'nw') != 0
198 "find spaces that arent used as alignment in the first indent column
199 let spaces = search('^ \{' . &ts . ',}[^\t]', 'nw') != 0
201 let b:statusline_tab_warning = ' [MI]'
202 elseif (spaces && !&et) || (tabs && &et)
203 let b:statusline_tab_warning = '[&et]'
206 return b:statusline_tab_warning
209 "==============================================================================
211 "==============================================================================
212 let g:syntastic_python_checkers = ["pylint"]
213 let g:syntastic_sh_checkers = ["shellcheck"]
214 let g:syntastic_c_checkers = ["splint"]
215 let g:syntastic_c_splint_args = "-checks +posixlib +matchanyintegral +enumint -nullpass -nullret ./util.c -DVERSION=\\\"VERSION\\\""
217 set statusline+=%#statusline_r#
218 set statusline+=\ %{SyntasticStatuslineFlag()}
221 let g:syntastic_check_on_wq = 0
222 let g:syntastic_auto_loc_list = 0
223 let g:syntastic_check_on_open = 1
224 let g:syntastic_enable_highlighting = 0 "underline word
225 let g:syntastic_always_populate_loc_list = 1
226 let g:syntastic_auto_jump = 0
229 let g:syntastic_error_symbol = ''
230 let g:syntastic_warning_symbol = ''
231 let g:syntastic_style_error_symbol = ''
232 let g:syntastic_style_warning_symbol = '!'
234 "==============================================================================
236 "==============================================================================
237 let g:clang_format#detect_style_file = 1
239 "==============================================================================
241 "==============================================================================
242 let g:gitgutter_grep=''
243 let g:gitgutter_enabled = 1
244 let g:gitgutter_map_keys = 0
246 "==============================================================================
248 "==============================================================================
251 set foldmethod=syntax
252 set foldtext=trim(getline(v:foldstart),&commentstring)
255 "==============================================================================
256 " File type highlight
257 "==============================================================================
259 augroup filetypedetect
260 autocmd BufNewFile,BufRead *.h set filetype=c
261 autocmd BufNewFile,BufRead *.csv set filetype=csv
262 autocmd BufNewFile,BufRead *.gpg set filetype=gpg
263 autocmd BufNewFile,BufRead *.log set filetype=log
264 autocmd BufNewFile,BufRead *.s set filetype=nasm
265 autocmd BufNewFile,BufRead LICENSE set filetype=text
266 autocmd BufNewFile,BufRead README set filetype=markdown
269 "==============================================================================
271 "==============================================================================
272 let g:completor_auto_trigger = 1
273 let g:completor_clang_binary = '/usr/bin/clang'
274 let g:completor_nasm_omni_trigger = '/bin/nasm'
275 let g:completor_complete_options = 'menuone,noselect,preview'
277 set dictionary+="~/.vim/dict/text.dict"
278 au FileType * execute 'setlocal dict+=~/.vim/dict/'.&filetype.'.dict'
280 inoremap <expr> <Tab> pumvisible() ? "\<C-n>" : "\<Tab>"
281 inoremap <expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<S-Tab>"
282 inoremap <C-f> <C-X><C-K>
284 "==============================================================================
285 " Remove characters function
286 "==============================================================================
287 function! Clean_file()
289 let save_pos = getpos(".")
290 " Remove spaces from begin & end of line
291 " Remove spaces after tab
293 " Remove file last line if empty
294 " Remove more than 2 empty lines
295 " Remove empty comment lines
296 " TODO remove 2 spaces between words
302 \%s/\($\n\)\+\%$//e |
304 " Return to saved cursor
305 call setpos(".", save_pos)
309 "==============================================================================
311 "==============================================================================
312 let g:filename = expand("%:r")
313 let g:filename_ext = expand("%:e")
314 let g:upperfilename = toupper(filename)
316 autocmd BufNewFile *.sh normal!ggi#!/bin/sh
\r
317 autocmd BufNewFile *.py normal!ggi#!/usr/bin/env python3
\r
318 autocmd BufNewFile *.s exe "normal!ggiBITS 64
\rglobal _start
\rsection"
319 \".text
\r\r_start:
\r\rexit:
\r mov rax, 60 ; "
320 \"exit(
\r mov rdi, 0 ; EXIT_SUCCESS
\r syscall ; );"
321 autocmd BufNewFile *.h exe "normal!ggi/* See LICENSE file for copyright and "
322 \"license details. */
\r\r#ifndef ".g:upperfilename."_H
\r#define "
323 \.g:upperfilename."_H
\r\r\r\r\#endif /* ".g:upperfilename."_H */" | normal!kk
324 autocmd BufNewFile *.c exe "normal!ggi/* See LICENSE file for copyright and license"
325 \"details. */
\r\r#include <stdio.h>
\r\r/* macros */
\r/* typedef */
\r/*"
326 \"function declarations */
\r/*"
327 \"global variables */
\r/* function implementations */
\r\rint
\rmain(int argc,"
328 \" char *argv[])
\r{
\r\rreturn 0;
\r}" | normal!kk