" ------------------------------- " Global options " ------------------------------- "colorscheme ice colorscheme default " Colors if has('termguicolors') set termguicolors endif " Cursor can rest beyond the last character set virtualedit=onemore " Highlight set hlsearch " Options syntax on set nowrap set number set relativenumber set tabstop=8 set shiftwidth=8 set softtabstop=8 set noexpandtab set autoindent set smartindent set scrolloff=999 set mouse=a " 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' return '['.(line("'>") - line("'<") + 1).' lines selected]' endif return '' endfunction function! ModifiedFlag() if &modified return '[Modified]' " Your custom text endif return '' " Empty if not modified endfunction function! ReadOnlyFlag() if &readonly return '[Read-only]' " Your custom text endif 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 " LEFT Side set statusline= set statusline+=%f " File name 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 " CENTER filler (optional) set statusline+=%= " RIGHT side set statusline+=\ [%y] " Filetype set statusline+=%{ReadOnlyFlag()} " Status bar transparent hi StatusLine ctermbg=0 cterm=NONE " Disable expandtab for make files autocmd FileType make setlocal noexpandtab " System clipboard 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: toggle all numbers nnoremap :if &number \| set nonumber norelativenumber \| else \| set number relativenumber \| endif " F4: absolute numbers only "nnoremap :set relativenumber! " F5: Search highlight nnoremap :nohlsearch " F6: to toggle kernel style nnoremap :call ToggleListStyle() " F7: remove all trailing line nnoremap :%s/\s\+$//e " F8 will run checkpatch.pl and populate quickfix list nnoremap :w:cexpr system('checkpatch.pl --no-tree --file ' . expand('%:p')):cwindow " Quickfix navigation with Shift + > / Shift + < " Note: Vim sees these as > and < in normal mode nnoremap > :cnext nnoremap < :cprev if &term =~ 'tmux\|xterm\|konsole' " Map HOME key to move to beginning of line in normal mode noremap [1~ 0 noremap [H 0 noremap OH 0 endif