jhdf /.vimrc

I've been using this for years. I think you can find a lot of interesting things here. A special note goes for those who'd like bash's editing bindings (emacs style) in insert mode.
"-----------------------------------------------------------------------
"
" Last modified Sat 17 Dec 2005 03:52:05 AM
"
" Some things might break due to termcap/terminfo settings' differences
"
"-----------------------------------------------------------------------

"-----------------------------------------------------------------------
" Options
"-----------------------------------------------------------------------

" VIM
set nocompatible

" When changing text, gradually overwrite it
set cpoptions +=$

" Fix backspace
"exe 'set t_kb =' . nr2char(8) | fixdel

" Make it work accross boundaries
set backspace =eol,start,indent

" Wrap on arrows also
set whichwrap +=<,>,[,]

" Stop motions on underscores
"set iskeyword -=_

" Do not redraw while running macros, etc
set lazyredraw

" Keep a minimum of context lines when scrolling
set scrolloff     =2
set sidescrolloff =2

" Enable syntax highlighting and filetype recognition
syntax   enable
filetype plugin indent on

" Indentation
"set tabstop    =4 
"set shiftwidth =4
set copyindent
  " Respect alignments

" Enable modelines
set modeline

" Avoid line-wrapping
set nowrap

" Accuse lines longer than width
set listchars +=tab:\|\ ,precedes:<,extends:>

" Colors for &listchars' eol, precedes and extends
hi NonText term=bold cterm=bold ctermfg=yellow ctermbg=darkcyan gui=bold guifg=blue guibg=lightcyan

if (&term =~ 'xterm' && !($COLORTERM == 'gnome-terminal')) || has('gui_running')
	" Resize width, wouldn't work on a tty console or gnome-terminal
	if v:version < 700
		set columns =88
		  " 80 + 8 for &number
	else
		set numberwidth =5 columns =85
	endif

	set columns +=2
	  " For &foldcolumn
	
	" Display line numbers
	set number

	set foldcolumn =2

	" Reset the terminal to 80 columns when leaving
	autocmd VimLeavePre * set columns =80
endif

" Colors for &number
hi LineNr ctermfg=darkblue ctermbg=lightgrey guifg=darkblue guibg=lightgrey

" Check if we're using a dark background - this should be set then
if $darkxterm != ''
	set bg =dark

	" Fix colors for folded lines
	hi Folded     ctermfg=darkblue ctermbg=grey
	hi FoldColumn ctermfg=darkblue ctermbg=grey
endif

" Essential
set hidden

" Backups
set  backup
let &backupdir = expand('~/vimbackups')

" Use the surrounding clipboard for operations
set clipboard ^=unnamed

" Show us the command we're typing
set showcmd

" Quickly jump to highlight matching braces
set showmatch
set matchtime =2

" Decent sized command line history
set history =1000

" Ask if we really want to leave
set confirm

" Report any changes
set report =0

" Use 'dictionary' files for completion
set complete +=k

" Folding
set foldmethod   =indent
set foldnestmax  =1
set nofoldenable

"" Search options
"set ignorecase
"set smartcase
  " Commented out for influencing gd, [_ctrl-i, etc

nmap / /\c\v
nmap ? ?\c\v
  " \c is the workaround

nnoremap / /
nnoremap ? ?

set hlsearch
set incsearch
""

" Colors for &hlsearch
hi Search ctermfg=white ctermbg=lightblue

" Use the tab completion menu
set wildmenu

" No fillchars
set fillchars =

" Enable the title
set title
set titleold =Terminal

" Always show the statusline
set laststatus =2

" Set ours
let &statusline = '%-2.2n %t %m'                                           .
\                 '%= [%-10.(%{strlen(&filetype)?&filetype:"unknown"}] %)' .
\                 '%{&encoding}  %4.4{winheight(0)}l %3.3b 0x%-4B '        .
\                 '%-10.(%l,%c%V%) %<%P'

" Set the font for the GUI
let &guifont = 'Lucida Console 8'

" Disable GUI menu shortcuts
set winaltkeys =no

" Local key sequences fix
if &term =~ 'xterm' && !($COLORTERM == 'gnome-terminal')
	exec "set     =\e[1;2A"
	exec "set   =\e[1;2B"
	exec "set  =\e[1;2C"
	exec "set   =\e[1;2D"
	exec "set    =\e[1;2F"
	exec "set   =\e[1;2H"
	"exec "set     =\e[1;5A"
	"exec "set   =\e[1;5B"
	  " currently unknown options
	exec "set  =\e[1;5C"
	exec "set   =\e[1;5D"
	exec "set    =\e[1;5F"
	exec "set   =\e[1;5H"
endif


"-----------------------------------------------------------------------
" Mappings
"-----------------------------------------------------------------------

" General mappings
"------------------

" Use  instead of , this avoids some timeoutlen delays
if has('gui_running')
	map   
	map!  
else
	map   
	map!  
endif

" Should be standard
map  :q

" Magic search
cmap  s/\v

" Disable highlighting
map  gn :noh

" Highlight  occurrences
map  gl :let @/ = '\V' . expand('')  set hls

" Avoid having to hit Enter after leaving a man page with q
noremap K K

" Comment current line with a #
map  ^i#j

"" Make  insert spaces in the middle of lines
function Tab_()
	if strpart(getline('.'), 0, col('.') - 1) =~ '^\t*$'
		return "\"
	else
		return "\" . (&ts - (virtcol('.') - 1) % &ts) . "a\\a"
endfunction

inoremap  =Tab_()
""

"" Block motions
" General blocks
"map  {  :call search('{\s*$', 'bW')
"map  }  :call search('{\s*$', 'W')
"map  (  :call search('(\s*$', 'bW')
"map  )  :call search('(\s*$', 'W')

" Main blocks
map  [[ :call search('{\s*$', 'bW') 
\                call searchpair('{', '', '}', 'rbW')
map  ][ :call search('^\s*\zs}\s*$', 'W') 
\                call searchpair('{', '', '}', 'rW')
map  ]] :call searchpair('{', '', '}', 'rW') 
\                call search('{\s*$', 'W')
map  [] :call searchpair('{', '', '}', 'rbW') 
\                call search('^\s*\zs}\s*$', 'bW')
""

" Show the changes list
map  :changes

"" Tags
" Show the tag stack
map l :tags

" Go to the next tag (ctrl-t for previous)
map n :ta

" Select a tag by name
map m :ts 
""

"" Cscope
if has('cscope')
	set nocsverb
	if filereadable('cscope.out')
		cs add cscope.out
	elseif $CSCOPE_DB != ''
		cs add $CSCOPE_DB
	endif
	set csverb
endif

nmap \ :cstag =expand('')

nmap c :cs find c =expand('')	
nmap d :cs find d =expand('')	
nmap e :cs find e =expand('')	
nmap f :cs find f =expand('')	
nmap g :cs find g =expand('')	
nmap i :cs find i ^=expand('')$
nmap s :cs find s =expand('')	
nmap t :cs find t =expand('')	
""

" Quickfix
map  :cn
map  :cp

" Switch buffers
map  :bn
map    :bN

if &term =~ 'xterm' && !($COLORTERM == 'gnome-terminal')
	map [6;5~ 
	map [5;5~ 
endif

" Moving like in GNU `info'
map     
map  

" Moving like in `ELinks'
nmap  
nmap  

" Horizontal scrolling
nmap   :exe 'normal ' . (v:count ? v:count : 15) . 'zl'
nmap   :exe 'normal ' . (v:count ? v:count : 15) . 'zh'

" Counterparts for normal mode's h, l
imap  
imap  


" Mappings for window manipulation
"----------------------------------

" Give the current window as much height as possible
nmap  _

" Faster window switching
nmap  WH0
nmap  wH0

"" Exchange buffers between the current and the next window
function Exchange_buffers_()
	let l:hit_explorer = 0
	let l:current_buffer = winbufnr(0)
	wincmd w
	if bufname(winbufnr(0)) == '-MiniBufExplorer-'
		let l:hit_explorer = 1
		2 wincmd W
	endif
	let l:next_buffer = winbufnr(0)
	exe 'buffer ' . l:current_buffer
	if l:hit_explorer
		wincmd w
	else
		wincmd W
	endif
	exe 'buffer ' . l:next_buffer
endfunction

nmap  :call Exchange_buffers_()
""


" Mappings based on emacs/bash or normal mode, mostly for insert/command modes
"------------------------------------------------------------------------------

"" Alternative word motions, very similar to emacs' in insert mode, and as
"" much as possible in normal mode, given differences in newline treatment.
"" Should be called through  from insert mode.
function Word_(direction)
	let l:iskeyword_save = &iskeyword
	let &l:iskeyword = '@,48-57,$,%'

	if a:direction > 0
		call search('\k', 'W')
		if getline('.')[col('.')] =~ '\k'
			normal e
		endif
		call cursor(line('.'), col('.') + 1)
		  " Important call on which this part is based, this works with 
		  " up to the empty column last on the current line in insert mode.
	else
		call search('\k', 'bW')
		if getline('.')[col('.') - 2] =~ '\k'
			normal b
		endif
	endif

	let &l:iskeyword = l:iskeyword_save
endfunction

" Similar to forward-word, backward-word
imap      :call Word_( 1)
imap      :call Word_(-1)

nmap   :call Word_( 1)
nmap   :call Word_(-1)

" Similar to kill-word, backward-kill-word
inoremap   xd: call Word_( 1)
inoremap  xdv:call Word_(-1)

if &term =~ 'xterm' && !($COLORTERM == 'gnome-terminal')
	imap ÿ 
endif

  " With , deletion can leave the cursor on the empty column, as
  " $ix shows, and that allows this to work.
""

" end-of-line, already default in command mode
imap  

" Like normal mode's e
imap  e

" Since  is taken for an emacs binding,  copies from the line below
inoremap  

" For insert and command line modes
map!  
map!  

" We can't call functions and go back to command mode, so this will do
cmap  

" history-search-backward, history-search-forward
cmap  
cmap  

"" simple yank-last-arg (no arguments or successive calls functionality...)
function Yank_last_arg_()
	let l:last_line = histget('cmd')
	let l:start = match(l:last_line, '\S\+\s*$')
	let l:end   = matchend(l:last_line, '\S\+', l:start)
	return strpart(l:last_line, l:start, l:end)
endfunction

cmap  =Yank_last_arg_()
""


" Visual mode mappings
"----------------------

" Search for the highlighted selection. This mapping uses the z register.
vnoremap / "zy/\Vz

" Wrap visual selection in parentheses
vnoremap  c()P


" Mappings for tag highlighting
"-------------------------------

" Generate tags syntax file and enable tag highlighting
command Mktaghl sp tags  %s/^\([^\t:]*:\)\=\([^\t]*\).*/syntax keyword Tag \2/  wq! tags.vim  noh  so tags.vim

" Enable tag highlighting
map  :so tags.vim

" Disable tag highlighting
map  :syn enable

" Colors for tag highlighting
hi Tag ctermfg=white ctermbg=lightgreen


" Toggling mappings
"-------------------

"" Toggle between 24 and 48 lines
function Toggle_lines_()
	if &lines < 48
		let &lines = 48
	else
		let &lines = 24
	endif
endfunction

nmap  :call Toggle_lines_()
""

" Toggle &scrollbind, needs to be set in each window
map  :set scrollbind!:set scrollbind?

"" Toggle &mouse
function Toggle_mouse_()
	if &mouse == 'a'
		set mouse =
	else
		set mouse =a
	endif
endfunction

map  :call Toggle_mouse_():set mouse?
""

"" Toggle &virtualedit
function Toggle_virtualedit_()
	if &virtualedit == 'all'
		set virtualedit =
	else
		set virtualedit =all
	endif
endfunction

map  :call Toggle_virtualedit_():set virtualedit?
""

" Toggle &paste
map  :set paste!:set paste?

"" Toggle interactive fold opening/closing
function Toggle_ifold_oc_()
	if &foldopen == 'all' && &foldclose == 'all'
		set foldopen&vim foldclose&vim
	else
		set foldopen =all foldclose =all
	endif
endfunction

map  :call Toggle_ifold_oc_():set foldopen? foldclose?
""

" Toggle &list
map  :set list!:set list?

" Switch between indentation settings
map  :set tabstop =2 shiftwidth =2
map 2 :set tabstop =2 shiftwidth =2
map  :set tabstop =4 shiftwidth =4
map 4 :set tabstop =4 shiftwidth =4
map  :set tabstop =8 shiftwidth =8
map 8 :set tabstop =8 shiftwidth =8


" Miscellaneous mappings
"-----------------------

" Insert a single character
noremap i ir

" Split the line
map  \i

" Just open an (usually) empty line. These mappings use the z mark.
noremap   :exe 'normal mz' . (v:count ? v:count : 1) . 'o'`z
inoremap   :exe 'normal mzo'  exe 'normal `z'

" Empty the current line
noremap  S

" Column-wise f with ç
map  ç :call search('\%' . virtcol('.') . 'v\zs\V' . nr2char(getchar()), 'W')
map  Ç :call search('\%' . virtcol('.') . 'v\zs\V' . nr2char(getchar()), 'bW')

" Highlight the current column
map  ç :let @/ = '\%' . virtcol('.') . 'v'  set hls

" Help shortcut
nmap  :h 

"" Use less as a pager for a vim command's output
function Pipe_to_less_(command)
	redir! > ~/vimpipe
	exe 'silent!' . a:command
	redir END
	!less -iS ~/vimpipe
endfunction

map  :call Pipe_to_less_('')
""

" Insert the current date
iab adate =strftime('%c')


"-----------------------------------------------------------------------
" Autocommands
"-----------------------------------------------------------------------

" Start editing in the line we left, if vim remembers it
autocmd BufReadPost *
  \ if line("'\"") > 0 && line("'\"") <= line("$") |
  \   exe "normal g`\"" |
  \ endif


"-----------------------------------------------------------------------
" Plugin settings
"-----------------------------------------------------------------------

" Standard vim manpage reader plugin
"runtime ftplugin/man.vim

" Perl 
let perl_include_pod = 1
let perl_want_scope_in_variables = 1
let perl_extended_vars = 1
let perl_string_as_statement = 1
let perl_sync_dist = 100

" Settings for minibufexpl.vim
let g:miniBufExplTabWrap = 1
let g:miniBufExplModSelTarget = 1

" Settings for showmarks.vim
let g:showmarks_enable = 0
let g:showmarks_textlower = "'\t"
let g:showmarks_textupper = "'\t"
let g:showmarks_textother = "'\t"
hi ShowMarksHLl ctermfg=darkblue ctermbg=lightgrey
hi ShowMarksHLu ctermfg=green    ctermbg=lightgrey
hi ShowMarksHLo ctermfg=yellow   ctermbg=lightgrey
hi ShowMarksHLm ctermfg=red      ctermbg=lightgrey

function Toggle_showmarks_()
	if (&term =~ 'xterm' && !($COLORTERM == 'gnome-terminal'))
	\  || has('gui_running')
		if g:showmarks_enable == 0
			set columns +=2
		else
			set columns -=2
		endif
	endif
	ShowMarksToggle
endfunction

map  :call Toggle_showmarks_():sleep 50m  echo 'showmarks ' . (g:showmarks_enable ? 'on' : 'off')
  " Toggle showmarks
  " (the sleep is so that showmarks' redrawing doesn't erase the message)

" Settings for taglist.vim
let Tlist_Ctags_Cmd = '/usr/bin/ctags'
let Tlist_WinWidth  = 33
let Tlist_File_Fold_Auto_Close = 1

map  :Tlist
  " Toggle the taglist window