diff options
Diffstat (limited to 'src/.vimrc')
-rwxr-xr-x | src/.vimrc | 138 |
1 files changed, 113 insertions, 25 deletions
@@ -1,20 +1,69 @@ -syntax on -colorscheme ice +" ------------------------------- +" Global options +" ------------------------------- + +"colorscheme ice +colorscheme default + +" Colors +if has('termguicolors') + set termguicolors +endif + +" Cursor can rest beyond the last character +set virtualedit=onemore -" Your usual config below +" Highlight +set hlsearch + +" Options +syntax on set number -set expandtab -set shiftwidth=4 -set tabstop=4 -set softtabstop=4 +set tabstop=8 +set shiftwidth=8 +set softtabstop=8 +set noexpandtab set autoindent set smartindent set scrolloff=999 +set relativenumber set mouse=a -"""""""""""""""""""""""""""""""""""""""""" -" Statubar + +" Line numbers +hi LineNr ctermfg=7 ctermbg=NONE guifg=#505050 guibg=NONE +hi CursorLineNr ctermfg=7 ctermbg=NONE guifg=#505050 guibg=NONE + + +" ------------------------------- +" Toggle between default and kernel-style settings +" ------------------------------- + +let g:vim_kernel_mode = 1 " 0 = personal, 1 = kernel + +function! ToggleListStyle() + if g:vim_kernel_mode + " Kernel style settings + set list " show tabs, trailing spaces, eol + set listchars=tab:>-,trail:~,eol:$ + let g:vim_list_mode = 1 + echo "List mode" + else + " Restore your personal settings + set nolist + set listchars= + let g:vim_list_mode = 0 + echo "No list mode" + endif + " toggle the mode for next call + let g:vim_kernel_mode = !g:vim_kernel_mode +endfunction + + +" ------------------------------- +" Statusbar +" ------------------------------- function! VisualModeLineCount() if mode() =~# 'v' @@ -37,14 +86,19 @@ function! ReadOnlyFlag() return '' " Empty if not modified endfunction + +" Function to display current column / total columns in current line +function! ColAndTotal() + return printf('%d/%d', col('.'), col('$')) +endfunction + " Full-width statusline set laststatus=2 -set statusline= " LEFT Side set statusline= set statusline+=%f " File name -set statusline+=\ [%l:%c] " Line and column +set statusline+=\ [%l:%{ColAndTotal()}] " Line and column / total columns set statusline+=\ [%L/%p%%] " Total lines and percent set statusline+=%{VisualModeLineCount()} " Selected lines in visual mode set statusline+=%{ModifiedFlag()} " Custom modified flag @@ -53,19 +107,11 @@ set statusline+=%{ModifiedFlag()} " Custom modified flag set statusline+=%= " RIGHT side -set statusline+=\ [%y] " Filetype +set statusline+=\ [%y] " Filetype set statusline+=%{ReadOnlyFlag()} -"""""""""""""""""""""""""""""""""""""""""" - " Status bar transparent hi StatusLine ctermbg=0 cterm=NONE - -" Cursor can rest beyond the last character -set virtualedit=onemore - -" Highlight -set hlsearch " Disable expandtab for make files autocmd FileType make setlocal noexpandtab @@ -75,15 +121,61 @@ if has("clipboard") set clipboard=unnamedplus endif +" =============================== +" Kernel-style 80-column guide for C files +" =============================== + +" Use ftplugin for C files only +augroup c_kernel_style + autocmd! + + " Trigger for C files + autocmd FileType c call s:kernel_c_setup() +augroup END + +function! s:kernel_c_setup() + " Highlight the 80th column + setlocal colorcolumn=80 + + " Optional: show cursor position + setlocal ruler + + " Optional: soft wrap for comments + setlocal textwidth=80 + setlocal formatoptions+=t + + " Optional: subtle color for colorcolumn (works in GUI or truecolor terminals) + hi ColorColumn ctermbg=236 guibg=#3a3a3a +endfunction + + +" ------------------------------- +" Keymaps +" ------------------------------- + " F2: absolute numbers only nnoremap <F2> :set number!<CR> " F4: absolute numbers only nnoremap <F4> :set relativenumber!<CR> -" Search highlight +" F5: Search highlight nnoremap <F5> :nohlsearch<CR> +" F6: to toggle kernel style +nnoremap <F6> :call ToggleListStyle()<CR> + +" F7: remove all trailing line +nnoremap <F7> :%s/\s\+$//e<CR> + +" F8 will run checkpatch.pl and populate quickfix list +nnoremap <F8> :w<CR>:cexpr system('checkpatch.pl --no-tree --file ' . expand('%:p'))<CR>:cwindow<CR> + +" Quickfix navigation with Shift + > / Shift + < +" Note: Vim sees these as > and < in normal mode +nnoremap > :cnext<CR> +nnoremap < :cprev<CR> + if &term =~ 'tmux\|xterm\|konsole' " Map HOME key to move to beginning of line in normal mode noremap <Esc>[1~ 0 @@ -91,7 +183,3 @@ if &term =~ 'tmux\|xterm\|konsole' noremap <Esc>OH 0 endif -" Colors -if has('termguicolors') - set termguicolors -endif |