tanakaBoxの日記

2008-01-122年目の.vimrc

ども。Vim歴2年目に突入したtanakaです。

また.vimrc張っときます。

" basic {{{
set nocompatible
syntax enable
filetype plugin on
filetype indent on

" $VIM
"let $VIM="/usr/share/vim"

" shell
set shell=zsh
if has('gui_running')
   set noshelltemp " GUI + zshのときリダイレクトがおかしい
"  set shellredir=>&
endif

" backup
let $TMP = $HOME . "/tmp/vim"
set backupdir=$TMP
set directory=$TMP

" no intoro
set shortmess+=I

" fold
if !exists($W3M_TTY)
  "set fdm=syntax
  "set fdm=marker
  set fmr={{{,}}}
endif

" scroll
" set scroll=10
set scrolloff=2
" set scrolloff=999

" search
set incsearch
set nowrapscan
set nohlsearch

" history
set history=50000

" warp
set whichwrap=b,s,h,l,<,>,~,[,]

" ~motion
set tildeop

" comment

" indent
set autoindent ts=8 sw=4 sts=4 et

aug All
  au!
  au FileType * setl formatoptions-=ro
  au Filetype * setl cindent ts=8 sw=4 sts=4 et
  au Filetype * setl cinoptions=0:,(0
aug END

aug ShellType
  au!
  au Filetype lisp,scheme setl cindent& ts=8 sw=2 sts=2 et
  au Filetype vim,ruby,zsh,sh setl ts=8 sw=2 sts=2 et
aug END

" let g:is_gauche = 1
aug MakeType
  au!
  au Filetype make setl ts=8 sw=8 sts=8 noet
aug END

" file
set hidden

" status line {{{
set showcmd
set cmdheight=1
set laststatus=2
set wildmenu

set statusline=
set statusline+=[*%n]\  " バッファ番号
set statusline+=%f\     " ファイル名
set statusline+=%{'['.(&fenc!=''?&fenc:'?').'-'.&ff.']'} " 文字コード
" set statusline+=%{'['.GetShortEncodingJP().'-'.&ff.']'} " 文字コード
set statusline+=%y      " ファイルタイプ
set statusline+=%r      " 読み取り専用フラグ
set statusline+=%h      " ヘルプバッファ
set statusline+=%w      " プレビューウィンドウ
set statusline+=%m      " バッファ状態[+]とか

set statusline+=%=      " 区切り

"set statusline+=\ %{strftime('%c')}  " 時間
set statusline+=%4l/%4L%4p%%   " どこにいるか
set statusline+=\ %3c    " 列
set statusline+=\ %4B    " 文字コード
set statusline+=%<       " 折り返しの指定
" }}}
" }}}

" colors & chars {{{
syntax on

colorscheme desert256

if has('gui_running')
  set listchars=tab:>-,eol:<
  set list
  hi clear NonText
  hi NonText guifg=grey40 ctermfg=7
  hi SpecialKey guifg=grey50 ctermfg=7
endif

" zenkaku
" only UTF-8
hi ZenkakuSpace cterm=underline guibg=grey50
match ZenkakuSpace / /

" WhitespaceEOL
" http://d.hatena.ne.jp/tasukuchan/20070816/1187246177
highlight WhitespaceEOL ctermbg=red guibg=red
match WhitespaceEOL /\s\+$/

aug MyColor
  au!
  au WinEnter * match ZenkakuSpace / /
  au WinEnter * if &readonly == "noreadonly" | match WhitespaceEOL /\s\+$/ | endif
aug END
" }}}

" GUI & mouse {{{
if has('gui_running')
  behave mswin " like a mswin mouse
  set clipboard=unnamed
  set guifont=Bitstream\ Vera\ Sans\ Mono\ 9
  set toolbar= " no toolbar
else
  set mouse+=a
  set ttymouse=xterm2
endif

" Right Click Menu {{{
if has('gui_running')
  amenu PopUp.Search\ Forward *
  amenu PopUp.Search\ Backward #
  " vmenu については考え中。
  " vmenu PopUp.Search\ Forward y/<C-R>"<CR>
  " vmenu PopUp.Search\ Backward y?<C-R>"<CR>
endif
" }}}
" }}}

" complete {{{
" set completeopt=menu,preview,longest
set completeopt=menuone,preview
set complete=.,w,b,u,t,i " default

if has("autocmd") && exists("+omnifunc")
  aug Complete
    au!
    au FileType python     setl omnifunc=pythoncomplete#Complete
    au FileType javascript setl omnifunc=javascriptcomplete#CompleteJS
    au FileType html       setl omnifunc=htmlcomplete#CompleteTags
    au FileType css        setl omnifunc=csscomplete#CompleteCSS
    au FileType xml        setl omnifunc=xmlcomplete#CompleteTags
    au FileType php        setl omnifunc=phpcomplete#CompletePHP
    au FileType c          setl omnifunc=ccomplete#Complete

    au FileType ruby,eruby setl omnifunc=rubycomplete#Complete
    au FileType ruby,eruby comp ruby
    au FileType ruby,eruby setl dictionary=$HOME/.vim/dict/ruby.dict
    " au FileType ruby,eruby setl isk+=.
    au Filetype *
          \	if &omnifunc == "" |
          \		setlocal omnifunc=syntaxcomplete#Complete |
          \	endif
  aug END
endif

" ~/.vim/plugin/autocomplpop.vim
" let g:AutoComplPop_PopupCmd = "<TAB>"

" haskell
au FileType haskell comp ghc
let g:haddock_browser="/usr/bin/firefox"

" ruby
let g:rubycomplete_rails = 1
let g:rubycomplete_buffer_loading = 1
let g:rubycomplete_classes_in_global = 1
let g:rubycomplete_include_object = 1
let g:rubycomplete_include_objectspace = 1

" auto complite {{{
let g:AutoComplPop_CompleteOption = '.,w,b'

" from http://lab.lowreal.net/trac/browser/config
function! InsertTabWrapper()
        let col = col('.') - 1
        if !col || getline('.')[col - 1] !~ '\k'
                return "\<TAB>"
        else
                if pumvisible()
                        return "\<C-N>"
                else
                        return "\<C-N>\<C-P>"
                end
        endif
endfunction

function! EnableAutoComplete()
  if mapcheck("a", 'i') == "" && exists('g:loaded_autocomplpop')
    AutoComplPopEnable
  end
  if mapcheck("\<TAB>", 'i') == ""
    inoremap <silent> <TAB> <c-r>=InsertTabWrapper()<cr>
"    inoremap <silent> <expr> <CR> pumvisible() ? "\<C-Y>\<CR>" : "\<CR>"
  endif
endfunction

function! DisableAutoComplete()
  if mapcheck("a", 'i') != ""
    AutoComplPopDisable
  endif
  if mapcheck("\<TAB>", 'i') != ""
    iunmap <TAB>
"    iunmap <CR>
  endif
endfunction

command! EnableAutoComplete call EnableAutoComplete()
command! DisableAutoComplete call DisableAutoComplete()

call EnableAutoComplete() " start


" }}}
" }}}

" plugin {{{
" surround {{{
" file : ~/.vim/plugin/surround.vim
" memo : nmap cs,ds,ys
" }}}

" snippets {{{
let g:snippetsEmu_key = "<S-Space>"
" }}}

" YankRing {{{
if has('viminfo')
  set vi^=!
endif
function! YRRunAfterMaps()
  nnoremap <silent> Y :<C-U>YRYankCount 'y$'<CR>
endfunction

" file : ~/.vim/plugin/yankring.vim
" memo : p<C-y>,p<C-n>
" let g:yankring_persist = 0
" let g:yankring_enabled = 0  " Disables the yankring
" }}}

" BufExplorer {{{
" file : ~/.vim/plugin/bufexplorer.vim
" memo : <leader>be BufferExplorer
" }}}

" TagList {{{
let g:Tlist_Use_Right_Window = 1
let g:Tlist_Show_One_File    = 1
if mapcheck("<F12>")
  unmap <F12>
endif
" }}}

" MRU {{{
let g:MRU_Max_Entries = 1000
let g:MRU_Window_Height = 16
let g:MRU_Exclude_Files="^/tmp/.*\|^/var/tmp/.*"
" let g:MRU_Use_Current_Window = 0
" let g:MRU_Auto_Close = 1
" }}}

" FuzzyFinder {{{
nmap <Leader>fb :FuzzyFinderBuffer<CR>
nmap <Leader>ff :FuzzyFinderFile<CR>
nmap <Leader>fm :FuzzyFinderMruFile<CR>
nmap <Leader>fc :FuzzyFinderMruCmd<CR>
nmap <Leader>fv :FuzzyFinderFavFile<CR>
nmap <Leader>fd :FuzzyFinderDir<CR>
" }}}

" LookupFile {{{
" nmap <silent> <C-S> :LUBufs ^.*<CR>
let g:LookupFile_AlwaysAcceptFirst=1
let g:LookupFile_PreserveLastPattern=0
let g:LookupFile_AllowNewFiles=0
let g:LookupFile_TagExpr = '"./tags"'
if !mapcheck("<A-Ì>")
 imap <silent> <A-S-L> <C-O><Plug>LookupFile
 nmap <silent> <A-S-L> <Plug>LookupFile
endif
" }}}

" project  {{{
" file : ~/.vim/plugin/project.vim
let g:proj_flags = "ist"
" }}}

" NERD_commenter {{{
" usage: <Leader>c<space>
" URL  : http://www.vim.org/scripts/script.php?script_id=1218
" file : ~/.vim/plugin/NERD_commenter.vim
let NERDSpaceDelims = 1
let NERDShutUp = 1

vmap <Leader>co $o^<C-V><Leader>cc<ESC>
" }}}

" autodate {{{
let autodate_format       = ': %Y-%m-%d %H:%M:%S '
let autodate_keyword_pre  = '\$Date'
let autodate_keyword_post = '\$'
" }}}

" chengelog {{{
runtime ftplugin/changelog.vim
" }}}

" cscope {{{
if has("cscope")
  set csprg=/usr/bin/cscope
  set csto=0
  set cst
  set nocsverb
  " add any database in current directory
  if filereadable("cscope.out")
    cs add cscope.out
    " else add database pointed to by environment
  elseif $CSCOPE_DB != ""
    cs add $CSCOPE_DB
  endif
  set csverb
endif
" }}}

" GDB {{{
if has("gdb")
  set previewheight=12
  run macros/gdb_mappings.vim
  set asm=0
  set gdbprg=gdb
endif
" }}}

" Viki {{{
let g:vikiNameSuffix=".viki"
let g:vikiOpenFileWith_html  = "silent !firefox %{FILE}"
autocmd! BufRead,BufNewFile *.viki setl filetype=viki
let g:vikiAutoMarks = 0 " bugアリ
" }}}

" from cmdex.vim {{{
"command! -nargs=0 CdCurrent cd %:p:h
" }}}

" form CD.vim {{{
" URL http://nanasi.jp/articles/vim/cd_vim.html
function! SetCd(set)
  aug CD
    au!
    if (a:set)
      au BufEnter * execute ":lcd " . expand("%:p:h")
    endif
  aug END
endfunction

command! EnableCd call SetCd(1)
command! DisableCd call SetCd(0)

call SetCd(1)
" }}}

"runtime! macros/editexisting.vim

vmap <Leader>aa :Align<Space>
nmap <silent> <Leader>p <plug>ToggleProject
nmap <silent> <Leader>e :Explore<CR>
nmap <silent> <Leader><Leader> :MRU<CR>
nmap <silent> <Leader>h :noh<CR>
nmap <silent> <Leader>sk :w<cr>:!konsole<CR>
" nmap <silent> <Leader>sh :source ~/.vim/vimsh.vim<CR>
nmap <silent> <Leader>] :Tlist<CR>
nmap <Leader>gb :GrepBuffer<Space>
nmap <Leader>gg :Grep<Space>
" }}}


" etc {{{
" Scratch & SetSyn {{{
" memo : -> command! -nargs=0 -bar Scrach ...
" See : h command-bar
command! -nargs=1 SS Scratch | call SetSyn("<args>")
"}}}

" Inc file name {{{
" use my inc command
command! -nargs=1 Inc exe "e " . Readirect("!inc " . "<args>")[0] | exe "normal <c-l>"
function! Readirect(cmd)
  let tmp = expand("$TMP/tmp") . Rand(100000000)
  silent exe a:cmd . " > " . tmp
  let r = readfile(tmp)
  silent exe "!rm " . tmp
  return r
endfunc
" }}}

" rand {{{
function! Rand(n)
  exe 'ruby VIM::command("return #{rand(' . a:n . ')}")'
endfunc
" }}}

" Calc {{{
command! -nargs=+ Calc :ruby print <args>
ruby include Math
" }}}

" save window position and window size {{{
let s:save_size = '~/.vim/savesize.vim'
au GUIEnter * if filereadable(expand(s:save_size)) | execute 'source ' . s:save_size | endif
function! SaveSizes()
  let x0 = getwinposx()
  let y0 = getwinposy()
  let x1 = &columns
  let y1 = &lines
  execute 'redir! > ' . s:save_size
  echo 'if exists(":winpos") == 2'
  echo "\t:winpos" x0 y0
  echo "endif"
  echo "set columns=" . x1
  echo "set lines=" . y1
  redir END
endfunction
au VimLeave * if has("gui_running") | silent call SaveSizes() | endif
" }}}

" #!で始まるファイルを保存時に実行権限を付与する {{{
au BufWritePost * :call AddExecmod()
function! AddExecmod()
  let line = getline(1)
  if strpart(line, 0, 2) == "#!"
    call system("chmod +x ". expand("%"))
  endif
endfunction
" }}}

" auto ctags {{{
au FileWritePost,BufWritePost *.c :call AddCtags()
function! AddCtags()
  call system("ctags -a ". expand("%"))
endfunction
" }}}

" Brouser {{{
" url : http://www.vim.org/tips/tip.php?tip_id=306
" test : javascript:alert()
function! Browser ()
  let line0 = getline (".")
  let line = matchstr (line0, "http[^ ]*")
  if line == ""
    let line = matchstr (line0, "ftp[^ ]*")
  endif
  if line == ""
    let line = matchstr (line0, "file[^ ]*")
  endif
  "let line = escape (line, "#?&;|%")
  ":if line==""
  "  let line = "\"" . (expand("%:p")) . "\""
  ":endif
  call system("firefox "  . "\"" . line . "\"")
endfunction
"  http://hoge.com/
nmap <Leader>w :call Browser ()<CR>
" }}}
" auto QuickFix {{{
" url : http://vimwiki.net/?tips%2F66
" move MakeEasy
" }}}

" ruby {{{
"preview interpreter's output(Tip #1244)
function! Ruby_eval_vsplit() range
    if &filetype == "ruby"
        let src = tempname()
        let dst = "RubyOutput"
        " put current buffer's content in a temp file
        silent execute ": " . a:firstline . "," . a:lastline . "w " . src
        " open the preview window
        silent execute ":pedit! " . dst
        " change to preview window
        wincmd P
        " set options
        setlocal buftype=nofile
        setlocal noswapfile
        setlocal syntax=none
        setlocal bufhidden=delete
        " replace current buffer with ruby's output
        silent execute ":%! ruby " . src
        " change back to the source buffer
        wincmd p
    endif
endfunction
"<F10>でバッファのRubyスクリプトを実行し、結果をプレビュー表示
vmap <silent> <F10> :call Ruby_eval_vsplit()<CR>
nmap <silent> <F10> mzggVG<F10>`z
map  <silent> <S-F10> :pc<CR>
" }}}

au BufWritePost memo.txt helptags .
" }}}

" jp {{{
" 文字コードの自動認識
if &encoding !=# 'utf-8'
  set encoding=japan
  set fileencoding=japan
endif
if has('iconv')
  let s:enc_euc = 'euc-jp'
  let s:enc_jis = 'iso-2022-jp'
  " iconvがeucJP-msに対応しているかをチェック
  if iconv("\x87\x64\x87\x6a", 'cp932', 'eucjp-ms') ==# "\xad\xc5\xad\xcb"
    let s:enc_euc = 'eucjp-ms'
    let s:enc_jis = 'iso-2022-jp-3'
  " iconvがJISX0213に対応しているかをチェック
  elseif 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
  " fileencodingsを構築
  if &encoding ==# 'utf-8'
    let s:fileencodings_default = &fileencodings
    let &fileencodings = s:enc_jis .','. s:enc_euc .',cp932'
    let &fileencodings = &fileencodings .','. s:fileencodings_default
    unlet s:fileencodings_default
  else
    let &fileencodings = &fileencodings .','. s:enc_jis
    set fileencodings+=utf-8,ucs-2le,ucs-2
    if &encoding =~# '^\(euc-jp\|euc-jisx0213\|eucjp-ms\)$'
      set fileencodings+=cp932
      set fileencodings-=euc-jp
      set fileencodings-=euc-jisx0213
      set fileencodings-=eucjp-ms
      let &encoding = s:enc_euc
      let &fileencoding = s:enc_euc
    else
      let &fileencodings = &fileencodings .','. s:enc_euc
    endif
  endif
  " 定数を処分
  unlet s:enc_euc
  unlet s:enc_jis
endif
" 日本語を含まない場合は fileencoding に encoding を使うようにする
if has('autocmd')
  function! AU_ReCheck_FENC()
    if &fileencoding =~# 'iso-2022-jp' && search("[^\x01-\x7e]", 'n') == 0
      let &fileencoding=&encoding
    endif
  endfunction
  autocmd BufReadPost * call AU_ReCheck_FENC()
endif
" 改行コードの自動認識
set fileformats=unix,dos,mac
" □とか○の文字があってもカーソル位置がずれないようにする
if exists('&ambiwidth')
  set ambiwidth=double
endif



" :IminsertOff/On
" command! -nargs=0 IminsertOff inoremap <buffer> <silent> <ESC> <ESC>:set iminsert=0<CR>
" command! -nargs=0 IminsertOn iunmap <buffer> <ESC>

" runtime macros/editexisting.vim
" }}}


" key bindings {{{

noremap ,, ,

" help : key-notation
set backspace=indent,eol,start
set winaltkeys=no
set timeoutlen=100000

" 関数を範囲選択
vmap \f <ESC>][mz[[V'z

" noremap <silent> <leader> :set timeoutlen=3000<CR>
" inoremap <silent> <ESC> <ESC>:set timeoutlen=10<CR>

noremap <Del> "_

noremap <Leader>te :tabe<cr>
noremap <Leader>tc :tabc<cr>
noremap <Leader>tn :tabn<cr>
noremap <Leader>tp :tabp<cr>
noremap <C-Tab>    :bn<cr>
noremap <C-S-Tab>  :bp<cr>
noremap <Leader><tab> :bn<cr>

map <silent> <F4> :w<CR>:call ReloadFirefox()<CR>
map <silent> <F5> :w<CR>:make<CR>
map <silent> <F6> :w<CR>:make debug<CR>

au! User Rails map <buffer> <silent> <F5> :w<CR>:call ReloadFirefox()<CR>

" noremap o o<ESC>
" noremap O O<ESC>
" smart insert改 http://d.hatena.ne.jp/spiritloose/20061113/1163401194
if has('gui_running')
  nmap ( /(<CR>:noh<CR>
  nmap ) /)<CR>:noh<CR>
  nmap <M-9> ysa()a
  nmap <M-0> ds)
  inoremap <M-{> {}<Left>
  inoremap <M-[> []<Left>
  inoremap <M-(> ()<Left>
  inoremap <M-"> ""<Left>
  inoremap <M-'> ''<Left>
  inoremap <M-<> <><Left>
  "vnoremap { "zdi{<C-R>z}<ESC>
  "vnoremap [ "zdi[<C-R>z]<ESC>
  "vnoremap ( "zdi(<C-R>z)<ESC>
  "vnoremap " "zdi"<C-R>z"<ESC>
  "vnoremap ' "zdi'<C-R>z'<ESC>
  nnoremap <M-;> A;<ESC>
  inoremap <M-;> <ESC>A;<ESC>

  inoremap <M-}> <ESC>A<Space>{}<Left><CR><ESC>O
  nnoremap <M-}> A<Space>{}<Left><CR><ESC>O
  aug CloseBlock
    au!
    au FileType ruby,eruby imap <M-}> <ESC>oend<ESC>O
    au FileType ruby,eruby nmap <M-}> oend<ESC>O
    au FileType ruby,eruby imap <M-#> #{}<Left>
  aug END

  noremap <M-s> :%S//g<Left><Left>

  inoremap <M-p> <C-p>
  inoremap <M-n> <C-n>
  inoremap <M-l> <C-X><C-L>
  inoremap <M-o> <C-X><C-O>
  inoremap <M-k> <C-X><C-K>
  inoremap <M-u> <C-X><C-U>
endif

" for screen
function! ScreenSpiritOpen(cmd)
  call system("screen -X eval split  focus 'screen " . a:cmd ."' focus")
endfunction

function! ScreenEval(str)
  let s = substitute(a:str, "[\n]*$", "\n\n", "") " 最後が改行 * 2で終わるようにする。
  call writefile(split(s, "\n"), "/tmp/vim-screen", "b")
  if has('gui_running')
    call system("screen -X eval 'readreg p /tmp/vim-screen' 'paste p'")
  else
    call system("screen -X eval focus 'readreg p /tmp/vim-screen' 'paste p' focus")
  endif
endfunction

nmap ,e :call ScreenEval(getline('.'))<CR>
vmap ,e "zy:call ScreenEval(@z)<CR>
command! -nargs=1 Screen call ScreenSpiritOpen("<args>")

" smooth-smooth scroll
map <C-U> <C-Y>2<C-Y>2<C-Y>2<C-Y>2<C-Y><C-Y>
map <C-D> <C-E>2<C-E>2<C-E>2<C-E>2<C-E><C-E>

" emacs like? kyes

if has('gui_running')
  cnoremap <M-a> <C-A>
  cnoremap <M-b> <C-B>
  cnoremap <M-d> <C-D>
  cnoremap <M-e> <C-E>
  cnoremap <M-f> <C-F>
  cnoremap <M-n> <C-N>
  cnoremap <M-p> <C-P>
  cnoremap <M-b> <S-Left>
  cnoremap <M-f> <S-Right>
endif

cnoremap <C-A>		<Home>
cnoremap <C-B>		<Left>
cnoremap <C-D>		<Del>
cnoremap <C-E>		<End>
cnoremap <C-F>		<Right>
cnoremap <C-N>		<Down>
cnoremap <C-P>		<Up>
" }}}

au VimEnter * Scratch | set ft=vim | exe "normal i\" = Scratch ===========================================\n\n" | b 1

あれ?うまく貼れてなかった。

PeggyPeggy2011/07/11 02:24I’m so glad that the internet allwos free info like this!

ciyqmseciyqmse2011/07/11 17:37pEQ3wP <a href="http://lfttxogwufhn.com/">lfttxogwufhn</a>

klpowkesocxklpowkesocx2011/07/11 22:21EsWWKi , [url=http://gvvjrdilmeoz.com/]gvvjrdilmeoz[/url], [link=http://uebwfkzyjsda.com/]uebwfkzyjsda[/link], http://pwlwenmlhpvg.com/

wxoldrgpqgjwxoldrgpqgj2011/07/13 17:563SKDJk <a href="http://guzkcheiqasl.com/">guzkcheiqasl</a>

pzqhmlpgcpzqhmlpgc2011/07/14 00:00b56gA3 , [url=http://iazlbdcsdfod.com/]iazlbdcsdfod[/url], [link=http://ccybbkaschjc.com/]ccybbkaschjc[/link], http://jvuutyaohjxt.com/

JenaJena2013/03/03 03:15I use VIM, but I'm more familiar with the inofamus; (. )( .) command. It should come as a default upgrade with the ubuntu software package. Check your c:/boobs directory. It allows all the HTML you can throw at it.

qjsipwmvqjsipwmv2013/03/06 09:58gUyku7 <a href=\"http://cdarplvwgrfx.com/\">cdarplvwgrfx</a>

mrvgenmrvgen2013/03/08 05:56TnKMDO , [url=http://ttbnkcrsxtil.com/]ttbnkcrsxtil[/url], [link=http://olkbynsfxovu.com/]olkbynsfxovu[/link], http://bzfpctwrtzbg.com/