vim7 用に少し .vimrc を書き直した

最新の .vimrc 等は、ここで晒してます。

.vimrc

"==<etc>======================================================================
set backupdir=~/.vim/backup

set shortmess+=I
set nu!
set cmdheight=1
set hidden
set history=60
set diffopt=filler,icase,iwhite

if has('kaoriya')
  set iminsert=1 imsearch=0
endif

helptags ~/.vim/doc

syntax on

"==<tab>======================================================================
set cindent
set expandtab

autocmd BufEnter * call SetTab()

function SetTab()
  if &syntax == 'javascript' || &syntax == 'ruby' || &syntax == 'html' || &syntax == 'xhtml' || &syntax == 'css' || &syntax == 'tt2html' || &syntax == 'eruby' || &syntax == 'yaml' || &syntax == 'vim'
    execute 'set softtabstop=2 | set shiftwidth=2 | set tabstop=2'
  else
    execute 'set softtabstop=4 | set shiftwidth=4 | set tabstop=4'
  endif
endf

"==<search>===================================================================
set magic
set ignorecase
set smartcase
set hlsearch
set incsearch

"==<status line>==============================================================
set laststatus=2
set wildmenu
set ruler
set statusline=%<%f? %m%r%h%w%{'['.(&fenc!=''?&fenc:&enc).']['.&ff.']'}%=%l,%c%V%8P

"==<color>====================================================================
colorscheme desert

set listchars=tab:>_
set list
highlight SpecialKey guifg=#555555

highlight Pmenu      ctermbg=DarkGreen
highlight PmenuSel   ctermbg=DarkBlue
highlight PmenuSbar  ctermbg=DarkRed

"==<encode>===================================================================
set encoding=japan
set fileencoding=japan

if has('iconv')
  let s:enc_euc = 'euc-jp'
  let s:enc_jis = 'iso-2022-jp'

  if iconv("?x87?x64?x87?x6a", 'cp932', 'euc-jisx0213') ==# "?xad?xc5?xad?xcb"
    let s:enc_euc = 'euc-jisx0213'
    let s:enc_jis = 'iso-2022-jp-3'
  endif

  let &fileencodings = &fileencodings .','. s:enc_jis
  set fileencodings+=utf-8,ucs-2le,ucs-2
  if &encoding =~# '^euc-?%(jp?|jisx0213?)$'
    set fileencodings+=cp932
    set fileencodings-=euc-jp
    set fileencodings-=euc-jisx0213
    let &encoding = s:enc_euc
  else
    let &fileencodings = &fileencodings .','. s:enc_euc
  endif

  unlet s:enc_euc
  unlet s:enc_jis
endif

autocmd FileType cvs :set fileencoding=euc-jp
autocmd FileType svn :set fileencoding=utf-8

"==<comlete>==================================================================
autocmd BufEnter,Syntax perl set dictionary=~/.vim/dict/perl.dict | set iskeyword+=:
set complete+=k

set omnifunc=syntaxcomplete#Complete
autocmd FileType tt2html set omnifunc=htmlcomplete#CompleteTags

function InsertTabWrapper()
  if pumvisible()
    return "?<c-n>"
  endif

  let col = col('.') - 1
  if !col || getline('.')[col - 1] !~ '?k?|<?|/'
    return "?<TAB>"
  elseif &omnifunc == ''
    return "?<C-P>"
  else
    return "?<C-X>?<C-O>"
  endif
endf

inoremap <TAB> <C-R>=InsertTabWrapper()<CR>

"==<head comment>=============================================================
iab papp <ESC>:r ~/.vim/templates/perl_application.pl<CR>
iab ppkg <ESC>:r ~/.vim/templates/perl_package.pl<CR>
iab pcls <ESC>:r ~/.vim/templates/perl_class.pl<CR>
iab psub <ESC>:r ~/.vim/templates/perl_subroutine.pl<CR>

"==<buffer>===================================================================
map <LEFT> :bp!<CR>
map <RIGHT> :bn!<CR>

"==<syntax check>=============================================================
map ,t :call SyntaxCheck()<CR>

function SyntaxCheck()
  execute ':w'
  if &syntax == 'perl'
    execute ':!perl -cw %'
  elseif &syntax == 'ruby'
    execute ':!ruby -cW %'
  elseif &syntax == 'javascript'
    execute ':!~/bin/js_checker.pl %'
  elseif &syntax == 'yaml'
    execute ':!~/bin/yaml_checker.pl %'
  elseif &syntax == 'html'
    execute '!tidy -quiet -errors --gnu-emacs yes %'
  endif
endf

map ,r :w<CR>:!~/bin/reload_firefox.sh<CR>

"==<move>=====================================================================
nnoremap j gj
nnoremap k gk
nnoremap * g*

"==<pair>=====================================================================
set showmatch
set matchpairs+=<:>

inoremap ( ()<ESC>i
inoremap { {}<ESC>i
inoremap [ <C-R>=AddPair('[')<CR>
inoremap < <C-R>=AddPair('<')<CR>

function AddPair(char)
  if a:char == '['
    if &syntax == 'tt2html'
      return "[%%]?<LEFT>?<LEFT>"
    else
      return "[]?<LEFT>"
    endif
  elseif a:char == '<'
    if &syntax == 'html' || &syntax == 'xhtml' || &syntax == 'tt2html' || &syntax == 'eruby' || &syntax == 'vim'
      return "<>?<LEFT>"
    else
      return '<'
    endif
  endif
endf

inoremap ) <C-R>=ClosePair(')')<CR>
inoremap } <C-R>=ClosePair('}')<CR>
inoremap ] <C-R>=ClosePair(']')<CR>
inoremap > <C-R>=ClosePairHtml('>')<CR>

function ClosePair(char)
  if getline('.')[col('.') - 1] == a:char
    return "?<RIGHT>"
  else
    return a:char
  endif
endf

function ClosePairHtml(char)
  if &syntax == 'html' || &syntax == 'xhtml' || &syntax == 'tt2html' || &syntax == 'eruby' || &syntax == 'vim'
    return ClosePair(a:char)
  else
    return a:char
  endif
endf

nmap ( csw(
nmap { csw{
nmap [ csw[

nmap ' csw'
nmap " csw"

"==<comment out>==============================================================
map ,c :call CommentOut()<CR>

function CommentOut()
  if &syntax == 'perl' || &syntax == 'ruby' || &syntax == 'sh' || &syntax == 'yaml'
    execute ':s/^/#/'
  elseif &syntax == 'javascript'
    execute ':s/^/?/?//'
  elseif &syntax == 'vim'
    execute ':s/^/"/'
  elseif &syntax == 'html' || &syntax == 'xhtml' || &syntax == 'tt2html'
    execute ':s/^?(.*?)$/<!-- ?1 -->/'
  endif

  execute ':nohlsearch'
endf

"==<lookupfile>===============================================================
nmap <silent> <UP> :LUBufs <CR>^.*
let g:LookupFile_AlwaysAcceptFirst=1
let g:LookupFile_PreserveLastPattern=0
let g:LookupFile_AllowNewFiles=0

.gvimrc

set lines=48
set columns=87
set cmdheight=1

if has('mac')
  set guifont=Osaka−等幅:h16
  set nomacatsui
else
  set transparency=200
endif

gui
colorscheme desert
highlight SpecialKey guifg=#555555

highlight Pmenu      guibg=DarkGray
highlight PmenuSel   guibg=DarkBlue
highlight PmenuSbar  guibg=DarkRed