" Rod's .vimrc/.gvimrc file (Rod Moffitt rod@rod.info) " $Id: vimrc 26708 2023-06-17 15:20:31Z rmoffitt $ " Copyright (C) Rod Moffitt + others " " This program is free software; you can redistribute it and/or " modify it under the terms of the GNU General Public License " as published by the Free Software Foundation; either version 2 " of the License, or (at your option) any later version. " " This program is distributed in the hope that it will be useful, " but WITHOUT ANY WARRANTY; without even the implied warranty of " MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the " GNU General Public License for more details. " " You should have received a copy of the GNU General Public License " along with this program; if not, write to the Free Software " Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. set nocompatible " use Vim defaults (much better!) set ts=3 "number of spaces a tab is converted to set sw=3 "number of spaces to use for each indent set expandtab " expand all tabs set nu " enable line numbering set mouse=hv " only allow mouse interactivity during :help set hidden " allow buffers to remain modified without writing set bs=2 " allow backspacing over everything in insert mode set ai " always set auto indenting on set viminfo='1000,f1,<200,s10 " read/write a .viminfo file: 1000 files worth of marks, max of 200 lines per register, 10kB max items size set tw=100 " wrap text at 100 chars "set backup " uncomment to keep a backup file "set ch=2 " uncomment to make command line two lines high "set noguipty " uncomment to make external commands work through a pipe instead of a pty set vb t_vb= " disable visual/audible bells set history=1000 " 1000 entry history table set undolevels=10000 " 10000 undo levels (WARNING: this can take a lot of memory!) set noundofile " disable the undo file set noswapfile " disable swap files set nobackup " disable backup files set laststatus=2 " always show the status line set noequalalways " don't auto-resize when a window is closed set guioptions-=T " disable the tool bar set guioptions-=r " disable the right hand scrollbar set guioptions-=R " disable the right hand scrollbar for vertically split windows set guioptions-=l " disable the left hand scrollbar set guioptions-=L " disable the left hand scrollbar for vertically split windows set guioptions-=b " disable the bottom/horizontal scrollbar set guioptions-=m " disable the menu " remap SHIFT-insert to middle mouse button for pasting text nnoremap " make the single quote act like the left tick (for jumping to marks) nnoremap ' ` " alias ZZ as z. since ZZ (save and quit) is too easy to accidentally hit when trying to hit zz nnoremap ZZ z. " restore Q as the line formatter (also, make it a single keystroke by adding ) nnoremap Q gq " as of Vim 7.3 edit! no longer kills the undo buffer, this adds a 'Reset' command that emulates it command! Reset :set undoreload=0 | edit! " prevent netrw history files from being saved let g:netrw_dirhistmax=0 " font selection set guifont=Envy\ Code\ R\ 12 " make the :Man command available if filereadable($VIMRUNTIME."/ftplugin/man.vim") source $VIMRUNTIME/ftplugin/man.vim endif " enable C style indenting for C/C++, auto-wrap comments at 100 characters augroup c au! autocmd BufRead *.c,*.cpp,*.h set formatoptions=croq cindent textwidth=100 comments=sr:/*,mb:*,el:*/,:// augroup END " enable C style indenting for Lua, auto-wrap comments at 100 characters augroup lua au! autocmd BufRead *.lua set formatoptions=croq cindent textwidth=100 comments=:-- augroup END " enable C style indenting for PHP, auto-wrap comments at 100 characters augroup php au! au BufRead *.php set formatoptions=croq cindent textwidth=100 comments=sr:/*,mb:*,el:*/,://,:# augroup END " C indentation: " l1: align braces with case labels set cinoptions=l1 if has("cscope") set csto=0 " search with cscope first, then with ctags set cst " search both ctags and cscope set nocsverb " disable db error on load " add the database in the current directory if filereadable("cscope.out") cs add cscope.out " else add the database pointed to by the environment elseif $CSCOPE_DB != "" cs add $CSCOPE_DB endif set csverb " restore db load error display " CTRL-p pops off the stack nnoremap :pop " CTRL-s finds this C symbol nnoremap :cs find s =expand("") " CTRL-rightbracket finds this definition nnoremap :cs find g =expand("") " CTRL-backslash finds functions calling this function nnoremap :cs find c =expand("") " CTRL-underscore then a single character invokes the following features: " s: Find this C symbol " g: Find this definition " d: Find functions called by this function " c: Find functions calling this function " t: Find this text string " e: Find this egrep pattern " f: Find this file " i: Find files #including this file noremap s :cs find s =expand("") noremap g :cs find g =expand("") noremap c :cs find c =expand("") noremap t :cs find t =expand("") noremap e :cs find e =expand("") noremap f :cs find f =expand("") noremap i :cs find i ^=expand("")$ noremap d :cs find d =expand("") endif " configure the Tag List plugin, to install: vim-addons install taglist if exists('loaded_taglist') let Tlist_Highlight_Tag_On_BufEnter=1 let Tlist_GainFocus_On_ToggleOpen=1 let Tlist_File_Fold_Auto_Close=0 let Tlist_Process_File_Always=1 let Tlist_Enable_Fold_Column=0 let Tlist_Compact_Format=1 let Tlist_Show_One_File=0 let Tlist_Auto_Update=1 let Tlist_Auto_Open=0 endif " LsGrep Copyright 2014 Teddy Wing, from https://github.com/teddywing/vim-ls-grep function! LsGrep(search) redir => ls_out silent ls redir END let ls_out = system("echo " . shellescape(ls_out) . " | grep -i " . shellescape(a:search)) echo ls_out endfunction command! -nargs=1 Lsgrep call LsGrep("") if version >= 600 " session saving set sessionoptions=buffers,curdir,resize,tabpages,winpos,winsize function! SessionSave(id) let session_directory=$HOME . "/.vim/sessions" if !isdirectory(session_directory) call mkdir(session_directory,"p","0700") endif let session_filename=session_directory . "/" . strftime("%Y%m%d_%H%M%S_" . a:id . ".vim") exe 'mksession ' . session_filename echomsg "session saved to " . session_filename endfunction command! -nargs=1 Sessionsave call SessionSave("") endif " key code remapping when using PuTTY: function! PuTTYFix() " S-function key codes: execute "set =\e[23~" execute "set =\e[24~" execute "set =\e[25~" execute "set =\e[26~" execute "set =\e[28~" execute "set =\e[29~" execute "set =\e[31~" execute "set =\e[32~" execute "set =\e[33~" execute "set =\e[34~" execute "set =\e[23~" execute "set =\e[24~" if &term =~ "screen-bce" " only need to remap function codes when using GNU Screen execute "set =\e[11~" execute "set =\e[12~" execute "set =\e[13~" execute "set =\e[14~" execute "set =\e[15~" execute "set =\e[17~" execute "set =\e[18~" execute "set =\e[19~" execute "set =\e[20~" execute "set =\e[21~" execute "set =\e[23~" execute "set =\e[24~" endif endfunction command! -nargs=0 Puttyfix call PuTTYFix() " wildmenu if has("wildmenu") set wildignore+=*.a,*.o,*.so set wildignore+=*.bmp,*.gif,*.ico,*.jpg,*.png,*.tif,*.tiff set wildignore+=.git,.hg,.svn set wildignore+=*~,*.swp,*.tmp set wildmode=longest,list,full set wildmenu endif " version 5+ commands if version >= 500 " disable highlighting strings inside C comments let c_comment_strings=0 " reset and enable syntax highlighting hi clear Normal set bg& hi clear syntax reset syntax on " switch off search pattern highlighting and incremental search se nohlsearch se noincsearch " hide the mouse pointer while typing set mousehide " set some nice colors set background=dark hi Normal guifg=white guibg=#00006C hi Normal ctermfg=white hi LineNr guifg=darkgrey hi LineNr ctermfg=darkgrey hi title guifg=darkgrey hi title ctermfg=darkgrey hi VertSplit gui=NONE guifg=cyan guibg=blue hi VertSplit gui=NONE ctermfg=blue ctermbg=cyan hi StatusLineNC gui=NONE guifg=cyan guibg=blue hi StatusLineNC gui=NONE ctermfg=blue ctermbg=cyan hi StatusLine gui=bold guifg=blue guibg=cyan hi StatusLine gui=bold ctermfg=cyan ctermbg=white endif " version 6+ commands if version >= 600 " disable folding set nofoldenable " enable file type detection with plugin and indent loading filetype plugin indent on endif " version 7+ commands if version >= 700 " spelling is configured yet disabled by default setlocal nospell " set a spell file where new words are added with 'zg' set spellfile=~/.vim.spell.add " map CTRL-t to open a new tab using the current buffer nnoremap :tab split endif " version 8+ commands if version >= 800 " vim 8 breaks bracketed paste mode in certain terminals, this disables it: set t_BE= endif " function key bindings: " F1 is unused (the help button for many desktop environments) " F2 is unused " F3 opens the taglist, SHIFT-F3 closes it, CTRL-SHIFT-F3 toggles it if exists('loaded_taglist') nnoremap :TlistOpen nnoremap :TlistClose nnoremap :TlistToggle endif " F4 rebuilds and loads the cscope database from the current directory if has("cscope") nnoremap :echo "rebuilding cscope database...":call system("cscope -qbR"):cs kill -1::cs add . endif " F5 is unused " F6 selects all text and copies it to the clipboard, SHIFT-F6 does a paste, " these also restore the cursor position which is lost during the select all nnoremap :let save_cursor = getpos(".")ggVG"+y:call setpos('.', save_cursor) nnoremap :let save_cursor = getpos(".")ggVG"+gP:call setpos('.', save_cursor) if version >= 700 " F7 enables spell checking while SHIFT-F7 disables it nnoremap :setlocal spell spelllang=en_us nnoremap :setlocal nospell endif " F8 toggles the gvim menu on and off, SHIFT-F8 toggles the toolbar and CTRL-SHIFT-F8 " toggles the vertical scrollbar (all of which are disabled by default in this vimrc) nnoremap :if &go=~#'m'set go-=melseset go+=mendif nnoremap :if &go=~#'T'set go-=Telseset go+=Tendif nnoremap :if &go=~#'r'set go-=relseset go+=rendif " F9 performs an CVS/SVN/Git diff using the vcscommand plugin, SHIFT-F9 " cancels the diff, to install: vim-addons install vcscommand let VCSCommandDeleteOnHide=1 let VCSCommandEdit='split' nnoremap :execute ':VCSVimDiff' nnoremap :execute ':VCSGotoOriginal!' " F10 inserts a doxygen header with CVS fields with the following credentials let doxycred_name='Rod Moffitt' let doxycred_email='rod@rod.info' let doxycred_url='http://rod.info' nnoremap :1i="/*\! \\file " . substitute(bufname("%"), "^.*\/", "", "g") . "\n \\brief \n\\author " . doxycred_name . "\n\\date \$Date\$\n\\version \$Revision\$ */\n\n/\*\ $Id\$\nCopyright (C) " . substitute(system("date +'%G '"), "\n", "", "g") . doxycred_name . " " . doxycred_email . " " . doxycred_url . " */\n\n" " SHIFT-F10 appends my vim preferences to the end of the file nnoremap :$o/* vim: sw=3 ts=3 expandtab/ " F11 is unused (the maximize button for many window managers) if version >= 600 " F12 quickly saves a session in ~/.vim/sessions with the ID 'quicksave' nnoremap :Sessionsave quicksave endif " vim: sw=3 ts=3 expandtab