[feat] bluetooth_connect check status
[dotfiles_afify.git] / .vimrc
blob32addc03782b991d791e6599f118c317e1760820
1 "==============================================================================
2 " Main
3 "==============================================================================
4 set nocompatible
5 let mapleader=" "
6 set shell=bash
7 set encoding=utf-8
8 set fileformat=unix
9 set noswapfile
10 set backspace=indent,eol,start
12 "==============================================================================
13 " Plugins
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'
25 call plug#end()
27 "==============================================================================
28 " Display
29 "==============================================================================
30 colorscheme minimal
31 set list
32 set listchars=tab:>—,nbsp:␣,trail:.
33 set tabstop=4
34 set shiftwidth=4
35 set noexpandtab
36 set splitbelow splitright
37 set wildmenu
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
46 " set noautoindent
47 " set linebreak
48 " filetype plugin indent on
50 "==============================================================================
51 " Keymaping
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>
59 " paste
60 nnoremap <C-c> :set invpaste paste?<CR>
61 set pastetoggle=<C-c>
62 set showmode
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
69 no <Up>        <Nop>
70 no <Down>      <Nop>
71 no <Left>      <Nop>
72 no <Right>     <Nop>
73 no <Space>     <Nop>
74 no <PageUp>    <Nop>
75 no <PageDown>  <Nop>
76 no <BackSpace> <Nop>
77 no <F1>        <Nop>
78 no q           <Nop>
79 no Q           <Nop>
81 "Disable keys in Insert mode
82 ino <Up>       <Nop>
83 ino <Down>     <Nop>
84 ino <PageUp>   <Nop>
85 ino <PageDown> <Nop>
86 ino <End>      <Nop>
87 ino <Home>     <Nop>
88 ino <F1>       <Nop>
90 " Add new line
91 noremap J o<esc>k
92 noremap K O<esc>j
94 " Go (start|end) of line
95 noremap H ^
96 noremap L $
98 " Split
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
110 " Move the split
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
116 " Search
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>
120 nnoremap * *zz
121 nmap n nzz
123 " Auto close
124 " inoremap ( ()<Left>
125 " inoremap { {}<Left>
126 " inoremap [ []<Left>
127 " inoremap " ""<Left>
128 " inoremap ' ''<Left>
130 " Quit
131 nnoremap <Leader>q :qa!<CR>
133 " Fold
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
138 " Syntastic
139 nnoremap <Leader>a :SyntasticCheck<CR>
140 nnoremap <Leader>n :lnext<CR>
142 " Custom functions
143 nnoremap <Leader>c :call Clean_file()<CR><CR>
145 nnoremap <Leader>r :set rightleft<CR>
146 nnoremap <Leader>R :set norightleft<CR>
148 " surround word
149 nnoremap <Leader>' i"<ESC>ea"<ESC><Right>
150 nnoremap <Leader>" i"<ESC>A"<ESC><Right>
151 nnoremap <Leader>[ i{<ESC>ea"<ESC><Right>
153 " Enter command mode
154 noremap ; :
156 "==============================================================================
157 " Status Line
158 "==============================================================================
159 set laststatus=2
160 set statusline=\ %F%#StatusLine_g#\ %m%#StatusLine_r#\ %r%*%=
161 set statusline+=%y\ %{&encoding}\ %{&fileformat}
163 " Warnings
164 set statusline+=%#StatusLine_o#
165 set statusline+=%{StatuslineTabWarning()}
166 set statusline+=%{StatuslineTrailingSpaceWarning()}
167 set statusline+=%*
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
176                 if result
177                         let b:statusline_trailing_space_warning = ' [TS]'
178                 else
179                         let b:statusline_trailing_space_warning = ''
180                 endif
181         endif
182         return b:statusline_trailing_space_warning
183 endfunction
185 function! StatuslineTabWarning()
186         if !exists("b:statusline_tab_warning")
187                 let b:statusline_tab_warning = ''
188                 if !&modifiable
189                         return b:statusline_tab_warning
190                 endif
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
194                 if tabs && spaces
195                         let b:statusline_tab_warning =  ' [MI]'
196                 elseif (spaces && !&et) || (tabs && &et)
197                         let b:statusline_tab_warning = '[&et]'
198                 endif
199         endif
200         return b:statusline_tab_warning
201 endfunction
203 "==============================================================================
204 " Linting
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()}
214 set statusline+=%*
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
223 " Symbols icon
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 "==============================================================================
230 " Folding
231 "==============================================================================
232 " set nofen
233 set foldnestmax=1
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)
246 endfunction " }}}
248 set foldtext=MyFoldText()
250 "==============================================================================
251 " File type highlight
252 "==============================================================================
253 setf dosini
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
260 augroup END
262 " csv colums color
263 let g:rcsv_colorpairs = [
264         \[124, 'red'],
265         \[186, 'green'],
266         \[172, 'yellow'],
267         \[66, 'blue'],
268         \[132, 'purple'],
269         \[72, 'aqua'],
270         \[166, 'orange'],
271         \['darkgreen', 'darkgreen'],
272         \['darkmagenta', 'darkmagenta'],
273         \['darkcyan', 'darkcyan']]
275 "==============================================================================
276 " Auto Completor
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()
289         " Save cursor line
290         let save_pos = getpos(".")
291         " Remove spaces from begin & end of line
292         " Remove spaces after tab
293         " Remove tab\n
294         " Remove file last line if empty
295         " Remove more than 2 empty lines
296         %s/ \+$//e |
297         \%s/^ \+//e |
298         \%s/\t \+/\t/e |
299         \%s/\t\+\n/\r/e |
300         \%s/\($\n\)\+\%$//e |
301         \%s/^\n\{2,\}/\r\r/e
302         " Return to saved cursor
303         call setpos(".", save_pos)
304 endfunction
306 "==============================================================================
307 " File Templates
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()
318 function! TempH()
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 */"
323         exe "normal!kk"
324 endfunction
326 function! TempC()
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}"
333         exe "normal!kk"
334 endfunction