" VIM Configuration File " Description: created for C/C++ development, but useful for Python too " Author: Bhaskar Tallamraju " Original version: https://tbhaskar78.github.io/vimrc/ " Last modified by Jeff Elkner 13 Sept 2024 to remove things we don't use " I like the desert theme the best color desert " turn syntax highlighting on set t_Co=256 syntax on " set the hightlight for search, with background black and red font set hlsearch hi Search ctermbg=black hi Search ctermfg=Red " Set no backup, avoids creating extra files by vim set nobackup "folding settings " zc folds at the current place " zM folds everything " zR unfolds everything " za toggle folding set foldmethod=indent "fold based on indent set foldnestmax=10 "deepest fold is 10 levels set nofoldenable "dont fold by default set foldlevel=2 "this is just what i use " set UTF-8 encoding set enc=utf-8 set fenc=utf-8 set termencoding=utf-8 " disable vi compatibility (emulation of old bugs) set nocompatible "enable filetype filetype plugin on " use indentation of previous line set autoindent " use intelligent indentation for C set smartindent " configure tabwidth and insert spaces instead of tabs set tabstop=4 " tab width is 4 spaces set shiftwidth=4 " indent also with 4 spaces set expandtab " expand tabs to spaces " wrap lines at 79 chars. set textwidth=79 " turn line numbers on " set number " highlight matching braces set showmatch " intelligent comments set comments=sl:/*,mb:\ *,elx:\ */ " c++ indent set cindent set cinoptions=g0 retab "enable python syntax let python_highlight_all = 1 " Enhanced keyboard mappings " switch between header/source with F4 map :e %:p:s,.h$,.X123X,:s,.cpp$,.h,:s,.X123X$,.cpp, " Build gcc, g++ or python code from here autocmd FileType c nnoremap :update!gcc -Werror % && ./a.out autocmd FileType c nnoremap :update!gcc -g -Werror % && gdb ./a.out autocmd FileType cpp nnoremap :update!g++ -Werror -std=c++17 % && ./a.out autocmd FileType cpp nnoremap :update!g++ -g -Werror % && gdb ./a.out autocmd FileType python nnoremap :update!python3 % " Auto build using make with map :make " Auto build using make with map :make clean all " auto cmd to add c header autocmd bufnewfile *.c so ~/.vim/c_header autocmd bufnewfile *.c exe "1," . 10 . "g/File Name :.*/s//File Name : " .expand("%") autocmd bufnewfile *.c exe "1," . 10 . "g/Creation Date :.*/s//Creation Date : " .strftime("%d-%m-%Y") autocmd Bufwritepre,filewritepre *.c execute "normal ma" autocmd Bufwritepre,filewritepre *.c exe "1," . 10 . "g/Last Modified :.*/s/Last Modified :.*/Last Modified : " .strftime("%c") autocmd bufwritepost,filewritepost *.c execute "normal `a" " auto cmd to add cpp header autocmd bufnewfile *.cpp so ~/.vim/cpp_header autocmd bufnewfile *.cpp exe "1," . 10 . "g/File Name :.*/s//File Name : " .expand("%") autocmd bufnewfile *.cpp exe "1," . 10 . "g/Creation Date :.*/s//Creation Date : " .strftime("%d-%m-%Y") autocmd Bufwritepre,filewritepre *.cpp execute "normal ma" autocmd Bufwritepre,filewritepre *.cpp exe "1," . 10 . "g/Last Modified :.*/s/Last Modified :.*/Last Modified : " .strftime("%c") autocmd bufwritepost,filewritepost *.cpp execute "normal `a" "execute retab on write autocmd BufWritePost,filewritepost *.c :retab autocmd BufWritePost,filewritepost *.py :retab autocmd BufWritePost,filewritepost *.cpp :retab autocmd BufWritePost,filewritepost *.js :retab if has("autocmd") " When editing a file, always jump to the last known cursor position. " Don't do it when the position is invalid or when inside an event handler " (happens when dropping a file on gvim). " Also don't do it when the mark is in the first line, that is the default " position when opening a file. autocmd BufReadPost * \ if line("'\"") > 1 && line("'\"") <= line("$") | \ exe "normal! g`\"" | \ endif endif