"---------------------------------------------------------------------------- " This is my < tipper -at- unix dot lancs dot ac dot uk > main .vimrc file " It was largely built by cannabalising other peoples files, specifically: " 'an example for a vimrc file' by Bram Moolenaar " And others too many to mention. "---------------------------------------------------------------------------- " Use Vim settings, rather then Vi settings (much better!). " This must be first, because it changes other options as a side effect. set nocompatible " Changing the mapleader (normally /) is good for dealing with odd keybaords. " This was for dealing with the keyboards of .jp "let mapleader = "¬" "---------------------------------------------------------------------------- " General behaviour options "---------------------------------------------------------------------------- " allow backspacing over everything in insert mode set backspace=indent,eol,start " Switch syntax highlighting on, when the terminal has colors " Also switch on highlighting the last used search pattern. if &t_Co > 2 || has("gui_running") syntax on " Syntax highlighting on set hlsearch " highligh search endif "--- Tab settings --------------------------------------------------------- set softtabstop=2 " Stops tabs every three, counting whitespaces set shiftwidth=2 " for autoindenting? [CRE] set noexpandtab " to make tabbing work proper like. "set tabstop=2 " for setting actual tab stop (NEVER *EVER* USE THIS) "-------------------------------------------------------------------------- "--- Text Wrapping options ------------------------------------------------ "set autoindent set smartindent set formatoptions=qc " q:allow gq formatting, c:wrap comments automatically set textwidth=78 "-------------------------------------------------------------------------- "--- Folding -------------------------------------------------------------- "set foldlevelstart=99 "set foldmethod=marker "set foldmarker={,} "-------------------------------------------------------------------------- "--- Status Bar ----------------------------------------------------------- "set laststatus=2 " Switch on for permanent statusbar set statusline=(%n)%m%r%y%H%W\ %1*\ %t\ %*%=%3.3b,0x%-3.3B\ \ %6.6l,%-6.6c\ %P hi User1 term=inverse,bold cterm=NONE ctermfg=black ctermbg=yellow guibg=yellow guifg=black "-------------------------------------------------------------------------- set history=50 " keep 50 lines of command line history set ruler " show the cursor position all the time set showcmd " display incomplete commands set is " Incremental searching set ic " Ignore case whilst searching set ttyfast " Expects quick tty, gives smoother scroll set scrolloff=3 " preserve three lines when page-downing set nobackup " Don't create foo~ backup file set showmatch " Turn on matching bracket stuff "set linebreak " Don't break in the middle of words "set showbreak=\| " Add a pipe at the start of lines that _vim_ wraps "---------------------------------------------------------------------------- " Auto-commands, affect behaviour when loading files. "---------------------------------------------------------------------------- " Enable file type detection. " Switches on indentation and sets a lot of tw's filetype plugin indent on " 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). autocmd BufReadPost * \ if line("'\"") > 0 && line("'\"") <= line("$") | \ exe "normal g`\"" | \ endif " This sets the text width for emails from Mutt to 76 characters au BufNewFile,BufRead /tmp/mutt* set tw=76 au BufNewFile,BufRead /tmp/mutt* call FOToggleOpts(1) | redraw " Set wrapping to 76 for all Lubbs posts au BufNewFile,BufRead /tmp/lubbs/* set tw=76 au BufNewFile,BufRead /tmp/lubbs/* call FOToggleOpts(1) | redraw " Set wrapping to 78 on C files au BufNewFile,BufRead *.cpp,*.c,*.h,*.java,*.pl set tw=78 cin si au BufNewFile,BufRead *.cpp,*.c,*.h,*.java,*.pl call FOToggleOpts(0) | redraw " Bash scripts au BufNewFile,BufRead *.sh set tw=78 au BufNewFile,BufRead *.sh call FOToggleOpts(0) | redraw " Text uses nice editing stuff au BufNewFile,BufRead *.txt set noautoindent tw=0 wm=0 nosi au BufNewFile,BufRead *.txt call FOToggleOpts(1) | redraw " Should stop HTML Files auto-indenting au BufNewFile,BufRead *.html,*.htm set noautoindent " For LISP joy au BufNewFile,BufRead *.lsp,*.lisp,*.cl let lisp_rainbow=1 au BufNewFile,BufRead *.lsp,*.lisp,*.cl set filetype=lisp.foolisp au BufNewFile,BufRead *.lsp,*.lisp,*.cl set showmatch au BufNewFile,BufRead *.lsp,*.lisp,*.cl set lispindent=4 "au BufNewFile,BufRead *.lsp,*.lisp,*.cl set lispwords=defun,car au BufNewFile,BufRead *.lsp,*.lisp,*.cl set ai " For all text files set 'textwidth' to 78 characters. "autocmd FileType text setlocal textwidth=78 " Folding, which files to use and what is a marker, also set the foldlevel " high so nothing is folded by default. Use zc to close and zo to open. "au BufNewFile,BufRead *.c,*.h,*.cpp,*.java,*.cs,*.hpp,*.pl " \ setlocal foldlevelstart=99 " \ foldmarker={,} " \ foldmethod=marker set foldlevel=99 " For scratch buffers ":set buftype=nofile ":set bufhidden=hide ":setlocal noswapfile "---------------------------------------------------------------------------- " Keyboard bindings "---------------------------------------------------------------------------- " Maps 'Y' to yank rest of line map Y y$ " Maps End to 'end of line' i.e. $ map End $ " Maps Home to 'start of line' i.e. 0 map Home 0 "map OF $ " Deals with home/end under Debians xterm terminal type. "map OH 0 " Map cursor keys to moving per on-screen-line, *not* line of text line. nmap j gj nmap k gk nmap gk imap gk nmap gj imap gj " maps ;; to 'stop searching' nmap ;; :let @/ = "" "--- Visual Mode ---------------------------------------------------------- " with increment.vim used to increment a selection of numbers in visual mode. vnoremap :Inc " Make p in Visual mode replace the selected text with the "" register. "vnoremap p :let current_reg = @"gvs=current_reg "-------------------------------------------------------------------------- "--- Command Mode --------------------------------------------------------- " Reformats a whole buffer map gg=G'' " Reformatting a paragraph map gwip map ñ gwip " Maps r to rot13 encoding map r ggVGg? " instead of calling the makeprg shell-out and run make. map :!make " Edit another file in the same directory as the current file " uses expression to extract path from current file's path " (thanks Douglas Potts) if has("unix") map ,e :e =expand("%:p:h") . "/" else map ,e :e =expand("%:p:h") . "\" endif " Maps \w to calling the FOToggleOpts function which toggles the text/coding " modes on and off map w :call FOToggleOpts() " Kill a quoted .sig map ks G?^> -- $d} " toggle un printable character showing. map i :set invlist " Toggle numbers down the side " Remember its ':set printoptions=number:y' for printouts with numbers map n :set invnumber " If we're vim7 offer to retab all buffers if v:version >= 700 map t :tab ball endif " Spell checking. if v:version >= 700 map s :set invspell set spellfile=~/.vim/spellfile.latin1.add set spelllang=en_gb else map s :w:!aspell -x -e --lang=en_gb -c %:e! endif " Make d insert a date map d a=strftime("%c") " Replace current line with a quote from the fortune files. map :.!~/bin/sig.sh " PGP leaders, PGP-sign and PGP-verify map ps :1,$!gpg -r $PGPKEYID --clearsign 2> /dev/null map pv :!gpg --verify % "-------------------------------------------------------------------------- "--- Insert Mode ---------------------------------------------------------- " For reformatting a whole buffer imap gg=G'' " Reformatting a paragraph imap magqip`ai imap ñ magqip`ai "make F8 insert text from X-Clipboard if has("xterm_clipboard") nmap :set paste"*p:set nopaste`] imap :set paste"*p:set nopaste`]i endif " Faffing with the VimFootNotes script imap AddVimFootnote imap ReturnFromFootnote "-------------------------------------------------------------------------- ""--- fvl.vim -------------------------------------------------------------- "" Just this line, mnemonic: end of line is ; ""map ; :.LispRange:wincmd p "map ; :.LispRange " "" Used as a shortcut for doing it on visual ops, mnemonic l(isp)-r(ange) ""map l :LispRange:wincmd p "map lr :LispRange " "" l(isp)-e(of) "map le :.,$LispRange " "" The whole file, mnemoic l(isp)-a(ll) ""map al :0,$LispRange:wincmd p "map la :0,$LispRange " ""-------------------------------------------------------------------------- "---------------------------------------------------------------------------- " Colour Scheme and fonts "---------------------------------------------------------------------------- if has("gui_running") " colorscheme koehler set guioptions-=T " Turns off the toolbar set guioptions+=r " Turns on right scrollbar set lines=40 columns=80 if has("gui_win32") set gfn=Courier_new:h10:cANSI " Courier New 10pt for Win32 else " set gfn=Courier\ 10\ Pitch\ 10 " Courier 10pt for X, has crap ! set gfn=Monospace\ 9 " Monospace 9pt for X set mousemodel=popup endif else " Personal Faff set background=light hi StatusLine term=inverse,bold cterm=reverse ctermfg=lightblue ctermbg=gray guibg=black guifg=lightblue hi Comment cterm=NONE ctermfg=darkgreen guifg=#80a0ff hi ModeMsg ctermfg=black ctermbg=white " Make line numbers visible but not glaring hi LineNr guifg=#D3D3D3 "hi IncSearch ctermbg=yellow ctermfg=black hi IncSearch ctermfg=yellow ctermbg=blue hi Search ctermbg=blue ctermfg=yellow " For light coloured bgs yellow fg sucks hi Statement term=bold ctermfg=blue gui=bold guifg=Brown hi CursorIME ctermbg=black ctermfg=lightgray hi Cursor ctermbg=black ctermfg=lightgray highlight Folded guibg=grey guifg=blue ctermbg=black ctermfg=blue highlight FoldColumn guibg=darkgrey guifg=white hi Parens term=bold, cterm=bold, gui=bold match Parens /[{}]/ endif "---------------------------------------------------------------------------- " Adding a toggle button that adds/removes "tan" from formatoptions "---------------------------------------------------------------------------- let g:fo_optstoggle=1 " Calling FOToggleOpts(1) forces text mode, (0) forces code mode. () toggles function! FOToggleOpts(...) " if we get an arg use it to set fo_optstoggle if a:0 != 0 let g:fo_optstoggle=a:1 endif if g:fo_optstoggle == 1 let g:fo_optstoggle=0 set formatoptions+=tan set linebreak set showbreak=\| echomsg "VIM in Text-editing mode (" &formatoptions ") now." else let g:fo_optstoggle=1 set formatoptions-=tan set nolinebreak set showbreak= echomsg "VIM in Coding mode (" &formatoptions ") now." endif endfunction "---------------------------------------------------------------------------- " Making vim silent _and_ nonflashing "---------------------------------------------------------------------------- " From http://www.vim.org/tips/tip.php?tip_id=418 " -------------------------------------------------- function! Errorbells_off(...) " control Vim's audio and visual warnings " * Arguments: " "beep": turn off just beeping " "flash": turn off just flashing " (empty): both off " * Must be initialized after the GUI starts! " off if a:0 == 0 let myeb = "" else let myeb = a:1 endif if myeb ==? "flash" " audibly beep on error messages set errorbells " Screen flash on error (See also 't_vb') set novisualbell set t_vb= elseif myeb ==? "beep" " audibly beep on error messages set noerrorbells " Screen flash on error (See also 't_vb') set visualbell set t_vb& elseif myeb ==? "" " audibly beep on error messages set noerrorbells " Screen flash on error (See also 't_vb') set visualbell set t_vb= endif endfunction "-------------------------------------------------- ":call Errorbells_off("beep") -- turns off beeps ":call Errorbells_off("flash") -- turns off flashes ":call Errorbells_off() -- turns off both call Errorbells_off()