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 <Leader>/ /
nnoremap <Leader>? ?
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 <S-Up> =\e[1;2A"
exec "set <S-Down> =\e[1;2B"
exec "set <S-Right> =\e[1;2C"
exec "set <S-Left> =\e[1;2D"
exec "set <S-End> =\e[1;2F"
exec "set <S-Home> =\e[1;2H"
"exec "set <C-Up> =\e[1;5A"
"exec "set <C-Down> =\e[1;5B"
" currently unknown options
exec "set <C-Right> =\e[1;5C"
exec "set <C-Left> =\e[1;5D"
exec "set <C-End> =\e[1;5F"
exec "set <C-Home> =\e[1;5H"
endif
"-----------------------------------------------------------------------
" Mappings
"-----------------------------------------------------------------------
" General mappings
"------------------
" Use <C-c> instead of <Esc>, this avoids some timeoutlen delays
if has('gui_running')
map <C-Space> <C-c>
map! <C-Space> <C-c>
else
map <C-@> <C-c>
map! <C-@> <C-c>
endif
" Should be standard
map <F9> :q<CR>
" Magic search
cmap <A-s> s/\v
" Disable highlighting
map <silent> gn :noh<CR>
" Highlight <cword> occurrences
map <silent> gl :let @/ = '\V' . expand('<cword>') <bar> set hls<CR>
" Avoid having to hit Enter after leaving a man page with q
noremap K K<CR>
" Comment current line with a #
map <F12> ^i#<Esc>j
"" Make <Tab> insert spaces in the middle of lines
function Tab_()
if strpart(getline('.'), 0, col('.') - 1) =~ '^\t*$'
return "\<Tab>"
else
return "\<Esc>" . (&ts - (virtcol('.') - 1) % &ts) . "a\<Space>\<Esc>a"
endfunction
inoremap <Tab> <C-r>=Tab_()<CR>
""
"" Block motions
" General blocks
"map <silent> { :call search('{\s*$', 'bW')<CR>
"map <silent> } :call search('{\s*$', 'W')<CR>
"map <silent> ( :call search('(\s*$', 'bW')<CR>
"map <silent> ) :call search('(\s*$', 'W')<CR>
" Main blocks
map <silent> [[ :call search('{\s*$', 'bW') <bar>
\ call searchpair('{', '', '}', 'rbW')<CR>
map <silent> ][ :call search('^\s*\zs}\s*$', 'W') <bar>
\ call searchpair('{', '', '}', 'rW')<CR>
map <silent> ]] :call searchpair('{', '', '}', 'rW') <bar>
\ call search('{\s*$', 'W')<CR>
map <silent> [] :call searchpair('{', '', '}', 'rbW') <bar>
\ call search('^\s*\zs}\s*$', 'bW')<CR>
""
" Show the changes list
map <A-c> :changes<CR>
"" Tags
" Show the tag stack
map <Leader>l :tags<CR>
" Go to the next tag (ctrl-t for previous)
map <Leader>n :ta<CR>
" Select a tag by name
map <Leader>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 <C-\>\ :cstag <C-r>=expand('<cword>')<CR><CR>
nmap <C-\>c :cs find c <C-r>=expand('<cword>')<CR><CR>
nmap <C-\>d :cs find d <C-r>=expand('<cword>')<CR><CR>
nmap <C-\>e :cs find e <C-r>=expand('<cword>')<CR><CR>
nmap <C-\>f :cs find f <C-r>=expand('<cfile>')<CR><CR>
nmap <C-\>g :cs find g <C-r>=expand('<cword>')<CR><CR>
nmap <C-\>i :cs find i ^<C-r>=expand('<cfile>')<CR>$<CR>
nmap <C-\>s :cs find s <C-r>=expand('<cword>')<CR><CR>
nmap <C-\>t :cs find t <C-r>=expand('<cword>')<CR><CR>
""
" Quickfix
map <A-n> :cn<CR>
map <A-p> :cp<CR>
" Switch buffers
map <C-PageDown> :bn<CR>
map <C-PageUp> :bN<CR>
if &term =~ 'xterm' && !($COLORTERM == 'gnome-terminal')
map <Esc>[6;5~ <C-PageDown>
map <Esc>[5;5~ <C-PageUp>
endif
" Moving like in GNU `info'
map <BS> <C-u>
map <Space> <C-d>
" Moving like in `ELinks'
nmap <Insert> <C-y>
nmap <Delete> <C-e>
" Horizontal scrolling
nmap <silent> <A-l> :<C-u>exe 'normal ' . (v:count ? v:count : 15) . 'zl'<CR>
nmap <silent> <A-h> :<C-u>exe 'normal ' . (v:count ? v:count : 15) . 'zh'<CR>
" Counterparts for normal mode's h, l
imap <A-h> <Left>
imap <A-l> <Right>
" Mappings for window manipulation
"----------------------------------
" Give the current window as much height as possible
nmap <A--> <C-w>_
" Faster window switching
nmap <A-9> <C-w>WH0
nmap <A-0> <C-w>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 <A-r> :call Exchange_buffers_()<CR>
""
" 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 <C-o> 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 <C-o>
" 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 <A-f> <C-o>:call Word_( 1)<CR>
imap <A-b> <C-o>:call Word_(-1)<CR>
nmap <silent> <A-f> :call Word_( 1)<CR>
nmap <silent> <A-b> :call Word_(-1)<CR>
" Similar to kill-word, backward-kill-word
inoremap <A-d> x<Left><C-o>d: call Word_( 1)<CR>
inoremap <A-BS> x<Left><C-o>dv:call Word_(-1)<CR>
if &term =~ 'xterm' && !($COLORTERM == 'gnome-terminal')
imap ÿ <A-BS>
endif
" With <C-o>, deletion can leave the cursor on the empty column, as
" $i<C-o>x shows, and that allows this to work.
""
" end-of-line, already default in command mode
imap <C-e> <End>
" Like normal mode's e
imap <A-e> <C-o>e
" Since <C-e> is taken for an emacs binding, <C-b> copies from the line below
inoremap <C-b> <C-e>
" For insert and command line modes
map! <C-a> <Home>
map! <A-w> <S-Right>
" We can't call functions and go back to command mode, so this will do
cmap <A-b> <S-Left>
" history-search-backward, history-search-forward
cmap <C-n> <Up>
cmap <C-p> <Down>
"" 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 <A-.> <C-r>=Yank_last_arg_()<CR>
""
" Visual mode mappings
"----------------------
" Search for the highlighted selection. This mapping uses the z register.
vnoremap <Leader>/ "zy/\V<C-r>z<CR>
" Wrap visual selection in parentheses
vnoremap <A-b> c()<Esc>P
" Mappings for tag highlighting
"-------------------------------
" Generate tags syntax file and enable tag highlighting
command Mktaghl sp tags <bar> %s/^\([^\t:]*:\)\=\([^\t]*\).*/syntax keyword Tag \2/ <bar> wq! tags.vim <bar> noh <bar> so tags.vim
" Enable tag highlighting
map <A-C-h> :so tags.vim<CR>
" Disable tag highlighting
map <A-C-j> :syn enable<CR>
" 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 <A-s> :call Toggle_lines_()<CR>
""
" Toggle &scrollbind, needs to be set in each window
map <F3> :set scrollbind!<CR>:set scrollbind?<CR>
"" Toggle &mouse
function Toggle_mouse_()
if &mouse == 'a'
set mouse =
else
set mouse =a
endif
endfunction
map <F5> :call Toggle_mouse_()<CR>:set mouse?<CR>
""
"" Toggle &virtualedit
function Toggle_virtualedit_()
if &virtualedit == 'all'
set virtualedit =
else
set virtualedit =all
endif
endfunction
map <F7> :call Toggle_virtualedit_()<CR>:set virtualedit?<CR>
""
" Toggle &paste
map <S-F2> :set paste!<CR>:set paste?<CR>
"" 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 <S-F3> :call Toggle_ifold_oc_()<CR>:set foldopen? foldclose?<CR>
""
" Toggle &list
map <A-1> :set list!<CR>:set list?<CR>
" Switch between indentation settings
map <F2> :set tabstop =2 shiftwidth =2<CR>
map <Leader>2 :set tabstop =2 shiftwidth =2<CR>
map <F4> :set tabstop =4 shiftwidth =4<CR>
map <Leader>4 :set tabstop =4 shiftwidth =4<CR>
map <F8> :set tabstop =8 shiftwidth =8<CR>
map <Leader>8 :set tabstop =8 shiftwidth =8<CR>
" Miscellaneous mappings
"-----------------------
" Insert a single character
noremap <Leader>i i<Space><Esc>r
" Split the line
map <A-C-n> \i<CR>
" Just open an (usually) empty line. These mappings use the z mark.
noremap <silent> <A-o> :<C-u>exe 'normal mz' . (v:count ? v:count : 1) . 'o'<CR>`z
inoremap <silent> <A-o> <C-o>:exe 'normal mzo' <bar> exe 'normal `z'<CR>
" Empty the current line
noremap <A-e> S<C-c>
" Column-wise f with ç
map <silent> ç :call search('\%' . virtcol('.') . 'v\zs\V' . nr2char(getchar()), 'W')<CR>
map <silent> Ç :call search('\%' . virtcol('.') . 'v\zs\V' . nr2char(getchar()), 'bW')<CR>
" Highlight the current column
map <silent> <Leader>ç :let @/ = '\%' . virtcol('.') . 'v' <bar> set hls<CR>
" Help shortcut
nmap <A-k> :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 <S-F1> :call Pipe_to_less_('')<Left><Left>
""
" Insert the current date
iab adate <C-r>=strftime('%c')<CR>
"-----------------------------------------------------------------------
" 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 <S-F4> :call Toggle_showmarks_()<CR>:sleep 50m <bar> echo 'showmarks ' . (g:showmarks_enable ? 'on' : 'off')<CR>
" 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 <F11> :Tlist<CR>
" Toggle the taglist window